# How to use Ollama with OpenCode, with ollama launch opencode and local models (Dec 2026)

ollama launch opencode or one opencode.json block, plus the 64k context OpenCode requires, why tool calls fail without it, and what fits on your GPU at that length.

Updated Dec 1, 2026 · By Ari Vale

This page has referral links. As an Amazon Associate we earn from qualifying purchases.

Our Vast referral code: 623346 (link: https://cloud.vast.ai/?ref_id=623346). New users get no bonus from it; we earn 3% of what referred users spend (Vast's referral program docs: https://docs.vast.ai/guides/reference/referral-program?ref_id=623346).

## The short answer

As of December 1, 2026, to use Ollama with OpenCode, run `ollama launch opencode` and give the model at least 64k of context. Ollama starts OpenCode with an inline config for the model you pick and leaves your own opencode.json alone. To set it up by hand, add an `ollama` provider to opencode.json using `@ai-sdk/openai-compatible` with baseURL http://localhost:11434/v1, then run `opencode`. Ollama's docs say OpenCode requires 64k context or more, but Ollama defaults to 4k on GPUs under 24 GiB, so start the server with `OLLAMA_CONTEXT_LENGTH=64000`. If tool calls fail, context is the first thing to check. OpenCode 2 also finds a running local Ollama server and adds its models by itself. (Written on Ollama v0.34.4 / OpenCode v1.18.32; re-checked Dec 1, 2026 against Ollama v0.40.19 and OpenCode v2.4.3.)

- **Fastest:** `ollama launch opencode`
- **Manual:** an `ollama` provider block in opencode.json
- **Required:** 64k+ context. Ollama's default is 4k on sub-24 GiB GPUs.
- **Tool calls failing?** Raise the context before you blame the model

## The fast way: `ollama launch opencode`

```shell
ollama launch opencode                    # pick a local or cloud model, start OpenCode
ollama launch opencode --model qwen3.5    # skip the picker
ollama launch opencode --config           # write the setup without starting a session
```

That one command is the whole setup if OpenCode is installed and your model runs with 64k context (step 2 below). Per Ollama's docs, re-read December 1, 2026, it starts OpenCode with an inline config for the model you choose, lists both local models and Ollama's cloud models, and leaves your own `opencode.json` untouched. `ollama launch` with no app name opens a picker; the CLI reference lists OpenCode, Claude Code, Codex, VS Code and Droid as supported integrations. The `--model` flag is from the same CLI reference.

OpenCode is the open-source (MIT) terminal coding agent. At about 230,000 GitHub stars on Dec 1, 2026 (210,000 on Sep 25), it's the most-starred of the three we cover in this cluster (Claude Code had about 158,000 and Codex about 137,000 that day). It supports local models natively, and Ollama now ships a first-party integration for it. Of the three agents, it's the one we'd point a newcomer to local models at first. Here's why, and how to set it up without the usual "tool calls don't work" dead end. The full comparison with Claude Code and Codex is in [our three-way guide](https://aliteq.com/run-coding-agents-on-local-models-ollama).

> **Pinned to**
>
> Ollama v0.34.4 (Sep 23, 2026) and OpenCode v1.18.32 (Sep 21, 2026). Commands from Ollama's OpenCode page and OpenCode's provider docs, accessed Sep 25, 2026. Re-checked Nov 12, 2026 against Ollama v0.40.16 (Nov 9) and OpenCode v1.19.5 (Oct 28): Ollama's OpenCode page, the 64k requirement and the opencode.json provider block are unchanged. Updated Nov 14, 2026: Ollama's CLI reference now lists five launch integrations (OpenCode, Claude Code, Codex, VS Code, Droid) and a --model flag that skips the picker; the fast-path section at the top uses both. Re-checked Dec 1, 2026 against Ollama v0.40.19 (Nov 26) and OpenCode v2.4.3 (Nov 29): Ollama's OpenCode page, the 64k requirement, the five launch integrations, the context defaults and the opencode.json provider block are unchanged. New since Nov 14: OpenCode is now on version 2, which still reads the V1 provider block below, and its own docs move config precedence under Locations. We quote the docs; we haven't benchmarked OpenCode on local models ourselves.

![Flat illustration of a developer at a standing desk with a laptop, cabled to a small box on a shelf next to a sleeping cat](https://media.aliteq.com/media/software/how-to-use-ollama-with-opencode-2026.jpg)
OpenCode on your laptop, the model on a box across the room. · Illustration generated with Higgsfield

## Step 1: install OpenCode

```shell
# macOS / Linux (Ollama's docs)
curl -fsSL https://opencode.ai/install | bash

# Windows (Ollama's docs)
npm install -g opencode-ai
```

## Step 2: fix the context before you start

This step is the one that decides whether OpenCode works. Ollama's page is unambiguous: "OpenCode requires a context length of 64k or higher." Ollama's [context-length page](https://docs.ollama.com/context-length) lists the defaults: **4k under 24 GiB of [VRAM](https://aliteq.com/tools/vram-calculator), 32k at 24–48 GiB, 256k at 48 GiB+.** The Ollama [FAQ](https://docs.ollama.com/faq) still says a flat 4,096. On a typical 8–16GB gaming card you start at 4k, which is 1/16th of what OpenCode needs.

On Sep 25, 2026, OpenCode's own [provider docs](https://opencode.ai/docs/providers/) described the symptom: "If tool calls aren't working, try increasing num_ctx in Ollama. Start around 16k - 32k." That advice was gone when we re-checked on Nov 12, and on Dec 1 the page still says OpenCode probes the local Ollama server at http://127.0.0.1:11434 and adds its models by itself. Go with [Ollama](https://aliteq.com/ollama)'s 64k, since coding agents pull file contents into the context as they work.

```shell
OLLAMA_CONTEXT_LENGTH=64000 ollama serve

# check it took: CONTEXT should be 64000, PROCESSOR 100% GPU
ollama ps
```

## Step 3 (fast path): ollama launch opencode, in detail

```shell
ollama launch opencode            # pick a model, start OpenCode
ollama launch opencode --config   # configure without starting a session
```

[Ollama](https://aliteq.com/how-to-manage-local-ai-models-ollama)'s docs are specific about what this touches. `ollama launch opencode` starts OpenCode with an inline config for the selected model and "does not overwrite `~/.config/opencode/opencode.json`". Your existing OpenCode settings still apply. The flip side is that models you've defined only in opencode.json won't show up in the launch model picker.

## Step 3 (manual path): opencode.json

If you want the setup committed with your project, add an Ollama provider to opencode.json. This is Ollama's documented block, with the model changed to a coding model:

```json
{
  "$schema": "https://opencode.ai/config.json",
  "provider": {
    "ollama": {
      "npm": "@ai-sdk/openai-compatible",
      "name": "Ollama",
      "options": {
        "baseURL": "http://localhost:11434/v1"
      },
      "models": {
        "qwen3-coder:30b": {
          "name": "qwen3-coder:30b"
        }
      }
    }
  }
}
```

Then just run `opencode`. That block is OpenCode's version 1 format, which Ollama's docs still show (re-read Dec 1, 2026). OpenCode 2 reads it as it is: its [migration guide](https://opencode.ai/docs/migrate-v1/) says "Existing supported V1 configuration is intended to keep working". In V2's own format the map is called `providers`, `npm` becomes `package` with an `aisdk:` prefix, and `baseURL` moves under `settings`. With Ollama running on the same machine, OpenCode 2 finds it without any provider block at all.

When a global and a project config disagree, OpenCode's [config locations and precedence rules](https://opencode.ai/docs/config/#locations) decide which one wins. It's worth a read if a setting seems to be ignored.

## Which model fits at 64k

OpenCode needs a model with tool calling. Ollama links its [tools-capable list](https://ollama.com/search?c=tools). For coding on a home GPU, the Ollama library has Qwen3-Coder 30B (19 GB download, 256K max context) and gpt-oss 20B (14 GB, 128K). At the 64k OpenCode requires, our VRAM engine gives:

### VRAM at 64k context (our engine, Q4_K_M)

|   | fp16 KV (default) | q8_0 KV | Realistic card |
| --- | --- | --- | --- |
| Qwen3-Coder 30B-A3B | 24 GiB | 21 GiB | 24GB (tight) · 32GB (comfortable) |
| gpt-oss 20B | 15.6 GiB | 14.1 GiB | 16GB (tight) · 24GB (comfortable) |

The q8_0 column is Ollama's documented `OLLAMA_KV_CACHE_TYPE=q8_0` setting, which the FAQ says uses "approximately 1/2 the memory of f16" with a very small precision loss. It's a global setting, so it applies to every model you run. Per-GPU tables: [best GPU for Qwen3-Coder](https://aliteq.com/cost-to-run/qwen3-coder-30b-a3b#best-gpu), [best GPU for gpt-oss 20B](https://aliteq.com/cost-to-run/gpt-oss-20b#best-gpu). The hardware deep-dive is [best GPU for Qwen3-Coder](https://aliteq.com/can-you-run-qwen3-coder-locally).

In practice that means a 24GB card such as a used [RTX 3090](https://aliteq.com/gpus/rtx-3090) for Qwen3-Coder, and a 32GB [RTX 5090](https://aliteq.com/gpus/rtx-5090) if you want the comfortable setup. On a 16GB card, gpt-oss 20B is the realistic pick, and our [best local LLM for 16GB VRAM](https://aliteq.com/best-local-llm-16gb-vram) guide lists what else fits. If replies feel slow once the context fills up, our guide on [how to speed up local LLM inference](https://aliteq.com/how-to-speed-up-local-llm-inference) covers the settings that matter.

**Own the card that's comfortable at 64k: GeForce RTX 5090 32GB cards** 32 GB: the comfortable size for Qwen3-Coder 30B at 64k context in the table above. Amazon lists several makers' RTX 5090 cards. Best for: running OpenCode with Qwen3-Coder 30B at 64k on your own machine.. [Check price on Amazon](https://www.amazon.com/s?k=RTX%205090%2032GB%20graphics%20card&tag=aliteqofficia-20) (Referral link: we earn a commission if you buy.)

**Your card can't hold Qwen3-Coder at 64k?** Rent a 24GB RTX 3090 by the hour and point OpenCode at it over an SSH tunnel. This link opens Vast.ai with our Ollama + Open WebUI template, so Ollama is ready to pull Qwen3-Coder as soon as the machine starts. It's a cheap way to see if a local coding agent suits you before you buy a bigger GPU. [Yes, rent a 24GB card for an hour](https://cloud.vast.ai/?template_id=26e7446a7d6906ee366b620c84e1e422&ref_id=623346) (Referral link: we earn a commission if you buy.) Live RTX 3090 prices on Vast.ai, from and typical: https://aliteq.com/vast-ai-pricing

### Pros

- MIT-licensed and open source
- `ollama launch opencode` doesn't overwrite your own opencode.json
- One JSON provider block you can commit with the project
- Ollama lists no API gaps for it beyond the context requirement

### Cons

- Needs 64k+ context. Ollama's sub-24 GiB default is 4k.
- Models defined only in opencode.json don't appear in the launch picker
- OpenCode's docs no longer give a context figure (they said 16–32k on Sep 25, 2026); use Ollama's 64k+

Weighing it against the others? The same one-command setup exists for Claude Code ([ollama launch claude](https://aliteq.com/how-to-use-ollama-with-claude-code)) and Codex ([ollama launch codex](https://aliteq.com/how-to-use-ollama-with-codex-cli)). Running out of disk after trying models? See [how to delete Ollama models](https://aliteq.com/how-to-manage-local-ai-models-ollama). If you'd rather work inside VS Code, see [running Qwen3-Coder in VS Code](https://aliteq.com/local-ai-coding-assistant-vs-code).

Not sure which model to load? Our [best local model for OpenCode](https://aliteq.com/best-local-coding-model-for-opencode) guide compares seven tool-calling models by the VRAM each needs at 64K context, from 16 GB to 48 GB cards.

**Want the comfortable setup, not the tight one?** A 32GB RTX 5090 gives Qwen3-Coder 30B its 64k context with room to spare. Runpod runs it in Secure Cloud datacenters with one-click templates, so you can start a pod for a coding session and stop it when you're done. [Rent a 32GB RTX 5090 on Runpod](https://console.runpod.io/signup?ref=nuninlts) (Referral link: we earn a commission if you buy.) Live RTX 5090 prices on Runpod, from and typical: https://aliteq.com/runpod-pricing

Live hourly rates for every card above are on our [cloud GPU price tracker](https://aliteq.com/cloud-gpu). If you'd rather serve the model to more than one tool, see [how to run local AI as an API server](https://aliteq.com/how-to-run-local-ai-as-an-api-server). Weighing a local agent against a paid one? Read [Qwen3-Coder vs GitHub Copilot](https://aliteq.com/qwen3-coder-vs-github-copilot), and for a whole-workflow view of models that fit one card, our [best local LLM for coding on a single GPU](https://aliteq.com/best-local-llm-for-coding-single-gpu) guide ranks them.

This guide is part of our [how to run a local AI model on your own PC in 2026 — a genuinely simple beginner's guide](https://aliteq.com/how-to-run-a-local-llm-on-your-pc-beginners-guide) guide. Related guides: [OpenClaw vs Hermes Agent: which to run on a local model](https://aliteq.com/run-openclaw-hermes-local-model-ollama), [Should you use Ollama or LM Studio to run AI on your own PC?](https://aliteq.com/ollama-vs-lm-studio-which-should-you-use), [Open WebUI or LM Studio: which should you use to run local AI?](https://aliteq.com/open-webui-vs-lm-studio).

## "Error: context deadline exceeded" with ollama launch opencode

This error means a request to Ollama ran out of time before it finished. Ollama's docs have no page for it. In Ollama's GitHub issues (for example [#17484](https://github.com/ollama/ollama/issues/17484)) it comes up in two moments: while a model is still downloading, and while a big model is loading into memory. Try these in order:

- **Download the model on its own first.** Run `ollama pull <model>` and let it finish before `ollama launch opencode`. If the pull stalls, run the same command again.
- **On a work or school network with a proxy,** set `HTTPS_PROXY` for the Ollama server, not `HTTP_PROXY`, and install the proxy's certificate as a system certificate. Ollama's FAQ says both.
- **For a big model on a slow first load,** run `ollama run <model> "hi"` once, check `ollama ps` shows it loaded, then launch.
- **If it still fails,** set `OLLAMA_DEBUG=1`, restart Ollama and read `server.log`. On Windows it's in `%LOCALAPPDATA%\Ollama`, per Ollama's troubleshooting page.

## Quick answers

**Q: How do I fix "context deadline exceeded" in Ollama?**

A: It means a request timed out, usually while a model is downloading or loading. Run ollama pull <model> on its own first, set HTTPS_PROXY (not HTTP_PROXY) if you are behind a proxy, load a big model once with ollama run before ollama launch opencode, and check server.log with OLLAMA_DEBUG=1 if it keeps failing.

**Q: How do I use Ollama with OpenCode?**

A: Run `ollama launch opencode`. Or add an `ollama` provider to opencode.json with npm "@ai-sdk/openai-compatible" and baseURL http://localhost:11434/v1, list your model under "models", then run `opencode` (Ollama docs, re-read Dec 1, 2026). OpenCode 2 still accepts that block.

**Q: What does ollama launch opencode do?**

A: It starts OpenCode wired to an Ollama model you pick, local or cloud, using an inline config. It does not overwrite ~/.config/opencode/opencode.json. Add --model <name> to skip the picker, or --config to set it up without opening a session (Ollama docs, re-read Dec 1, 2026).

**Q: Can OpenCode run fully local with Ollama?**

A: Yes. Pick a downloaded model with tool calling, such as qwen3-coder:30b or gpt-oss:20b, and give it at least 64k context. Nothing leaves your machine. Cloud models in the same picker are optional and run on Ollama's servers.

**Q: Why aren't OpenCode tool calls working with Ollama?**

A: Almost always context length. Ollama's docs say OpenCode requires 64k or more. Ollama defaults to 4k on GPUs under 24 GiB, so start it with OLLAMA_CONTEXT_LENGTH=64000 and confirm with `ollama ps`.

**Q: Will ollama launch opencode overwrite my config?**

A: No. Per Ollama's docs it starts OpenCode with an inline config and doesn't overwrite ~/.config/opencode/opencode.json, so your existing settings still apply. Models defined only in opencode.json don't appear in the launch picker.

**Q: What's the best local model for OpenCode?**

A: One with tool calling and enough context. Qwen3-Coder 30B needs about 24.0 GiB at 64k on our engine (21.0 GiB with the 8-bit KV cache), so a 24GB card is tight. gpt-oss 20B needs about 15.6 GiB (14.1 GiB with q8_0), which suits 16GB cards.

**Q: Is OpenCode free?**

A: OpenCode itself is open source under the MIT licence. Running it against a local Ollama model costs nothing beyond your hardware and electricity. Ollama's cloud models, if you choose them, run on Ollama's servers instead.

## Sources

- [Ollama docs — OpenCode integration (accessed Sep 25, Nov 14 and Dec 1, 2026)](https://docs.ollama.com/integrations/opencode)
- [Ollama docs — CLI Reference: Launch integrations, supported list and --model flag (read Nov 14 and Dec 1, 2026)](https://docs.ollama.com/cli)
- [OpenCode docs — Providers (accessed Sep 25, Nov 12 and Dec 1, 2026)](https://opencode.ai/docs/providers/)
- [OpenCode docs — Migrate from V1 (existing V1 configuration keeps working in V2; read Dec 1, 2026)](https://opencode.ai/docs/migrate-v1/)
- [Ollama releases on GitHub (v0.40.19, Nov 26, 2026; read Dec 1, 2026)](https://github.com/ollama/ollama/releases)
- [OpenCode on GitHub (v2.4.3, Nov 29, 2026, with V1 at v1.19.6; 230,252 stars on Dec 1, 2026)](https://github.com/anomalyco/opencode)
- [OpenCode docs — Config locations and precedence (read Dec 1, 2026)](https://opencode.ai/docs/config/#locations)
- [OpenCode on GitHub (MIT)](https://github.com/anomalyco/opencode)
- [Ollama docs — Context length (accessed Sep 25 and Dec 1, 2026)](https://docs.ollama.com/context-length)
- [Ollama docs — FAQ (accessed Sep 25 and Dec 1, 2026)](https://docs.ollama.com/faq)
- [Ollama library — qwen3-coder / gpt-oss tags (read Dec 1, 2026)](https://ollama.com/library/qwen3-coder/tags)
- [Higgsfield plans and pricing (official page, checked Dec 2, 2026)](https://higgsfield.ai/pricing?fpr=lax-8e2251&fp_sid=how-to-use-ollama-with-opencode--md)
- [Illustration generated with Higgsfield](https://higgsfield.ai?fpr=lax-8e2251&fp_sid=how-to-use-ollama-with-opencode--md)
- [Ollama docs, Troubleshooting: logs and OLLAMA_DEBUG (official docs, read Nov 19 and Dec 1, 2026)](https://docs.ollama.com/troubleshooting)
- [Ollama GitHub issue #17484, Error: context deadline exceeded (read Nov 19 and Dec 1, 2026; still open)](https://github.com/ollama/ollama/issues/17484)

---

Canonical: https://aliteq.com/how-to-use-ollama-with-opencode

This page has referral links. As an Amazon Associate we earn from qualifying purchases.
