`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.
OpenCode is the open-source (MIT) terminal coding agent. At about 210,000 GitHub stars on 25 Sep 2026, it's the most-starred of the three I cover in this cluster. It supports local models natively, and Ollama now ships a first-party integration for it. Of the three agents, it's the one I'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.
OpenCode on your laptop, the model on a box across the room. · Illustration generated with Higgsfield
Step 1: install OpenCode
# 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 lists the defaults: 4k under 24 GiB of VRAM, 32k at 24–48 GiB, 256k at 48 GiB+. The Ollama 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.
OpenCode's own provider docs describe the symptom: "If tool calls aren't working, try increasing num_ctx in Ollama. Start around 16k - 32k." Their 16–32k starting point is lower than Ollama's 64k requirement. I'd go with Ollama's number, since coding agents pull file contents into the context as they work.
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
ollama launch opencode # pick a model, start OpenCode
ollama launch opencode --config # configure without starting a session
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:
Then just run opencode. When a global and a project config disagree, OpenCode's config precedence rules 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. 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)
Qwen3-Coder 30B-A3B
fp16 KV (default)
24 GiB
q8_0 KV
21 GiB
Realistic card
24GB (tight) · 32GB (comfortable)
gpt-oss 20B
fp16 KV (default)
15.6 GiB
q8_0 KV
14.1 GiB
Realistic card
16GB (tight) · 24GB (comfortable)
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, best GPU for gpt-oss 20B. The hardware deep-dive is best GPU for Qwen3-Coder.
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
− Two docs disagree on the starting context (OpenCode: 16–32k; Ollama: 64k+)
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, accessed 25 Sep 2026).
Why aren't OpenCode tool calls working with Ollama?
Almost always context length. OpenCode's docs say to increase num_ctx if tool calls fail, and 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.
Will ollama launch opencode overwrite my config?
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.
What's the best local model for OpenCode?
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.
Is OpenCode free?
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.