OpenCode with a local model: setup for Ollama, LM Studio or llama.cpp
OpenCode is an open-source (MIT) coding agent that runs in the terminal, with a desktop app and IDE extension also available. It talks to Ollama, LM Studio and llama-server through an OpenAI-compatible provider entry in opencode.json, which suits people who want a full-featured terminal agent on local models.
At a glance
- Type
- cli
- Licence
- MIT
- Latest release
- 1.19.3 (2026-10-16)
- Status
- Maintained
- Local backends
- ollama, lmstudio, llamacpp, vllm, openai-compatible
- Needs native tool calling
- Yes
- MCP support
- Yes
- Recommended minimum context
- 16,000 tokens
- Start-up prompt
- ~7,000 tokens (single third-party measurement)
- GitHub stars
- 214.6k (2026-10-19)
How to set it up with a local model
Pick your backend. Each command has its own Copy button. Where a step uses an example model, swap in the one you run; the table below lists the ones that fit your machine.
Install it (macOS / Linux):
curl -fsSL https://opencode.ai/install | bashStart Ollama with a 64k context window (or set the context slider in the Ollama app's settings).
OLLAMA_CONTEXT_LENGTH=64000 ollama serveIn a second terminal, pull a tool-capable coding model (replace qwen3-coder:30b with any model you prefer).
ollama pull qwen3-coder:30bQuickest path: let Ollama configure and launch OpenCode for you.
ollama launch opencodeOr add Ollama as a provider in your global OpenCode config (replace qwen3-coder:30b with the model you pulled).
~/.config/opencode/opencode.json{ "$schema": "https://opencode.ai/config.json", "provider": { "ollama": { "npm": "@ai-sdk/openai-compatible", "name": "Ollama (local)", "options": { "baseURL": "http://localhost:11434/v1" }, "models": { "qwen3-coder:30b": { "name": "Qwen3-Coder 30B", "limit": { "context": 64000, "output": 8192 } } } } } }Run OpenCode in your project and pick the model with /models.
opencode
Other ways to install
npm
npm install -g opencode-aiHomebrew
brew install anomalyco/tap/opencodeCheck that it works
List the models OpenCode can see from your local provider; your model should appear as provider/model. With Ollama, run `ollama ps` during a session and check the CONTEXT column.
opencode models ollamaWhich local models fit, by machine
Checked by this site's engine at the context OpenCode needs, with 32 GB of system RAM for MoE offload. A Mac counts three quarters of unified memory as usable.
| Machine | Model | Quant | Context | Fit | Ollama |
|---|---|---|---|---|---|
| 12 GB GPU | Qwen 3.5 9B | Q4_K_M | 32,768 | Comfortable (7.4 GB of 12 GB) | qwen3.5:9b |
| Qwen 3.6 35B-A3B | Q4_K_M | 32,768 | With CPU offload (MoE) (22.7 GB of 12 GB) | qwen3.6:35b-a3b | |
| 16 GB GPU | Qwen 3.5 9B | Q4_K_M | 32,768 | Comfortable (7.4 GB of 16 GB) | qwen3.5:9b |
| Qwen 3.6 35B-A3B | Q4_K_M | 32,768 | With CPU offload (MoE) (22.7 GB of 16 GB) | qwen3.6:35b-a3b | |
| 24 GB GPU | Qwen3.8 27B | Q4_K_M | 32,768 | Comfortable (19.9 GB of 24 GB) | qwen3.8:27b |
| Qwen 3.6 27B | Q4_K_M | 32,768 | Comfortable (19.9 GB of 24 GB) | qwen3.6:27b | |
| Devstral Small 2 24B | Q4_K_M | 32,768 | Comfortable (20.7 GB of 24 GB) | devstral-small-2:24b | |
| Qwen 3.6 35B-A3B | Q4_K_M | 65,536 | Tight (23.3 GB of 24 GB) | qwen3.6:35b-a3b | |
| 32 GB GPU | Qwen3.8 27B | Q4_K_M | 32,768 | Comfortable (19.9 GB of 32 GB) | qwen3.8:27b |
| Qwen 3.6 27B | Q4_K_M | 32,768 | Comfortable (19.9 GB of 32 GB) | qwen3.6:27b | |
| Devstral Small 2 24B | Q4_K_M | 32,768 | Comfortable (20.7 GB of 32 GB) | devstral-small-2:24b | |
| Qwen 3.6 35B-A3B | Q4_K_M | 65,536 | Comfortable (23.3 GB of 32 GB) | qwen3.6:35b-a3b | |
| Qwen3-Coder 30B-A3B (MoE) | Q4_K_M | 65,536 | Comfortable (25.7 GB of 32 GB) | qwen3-coder:30b | |
| Mac, 64 GB | Qwen 3.6 35B-A3B | Q8_0 | 131,072 | Comfortable (40.7 GB of 48 GB) | — |
Your exact machine: filter the matrix or check any model in the analyzer.
Common problems with local models
- Ollama's OpenCode guide says OpenCode needs a 64k+ context window; OpenCode's own docs say to raise num_ctx (start around 16k-32k) if tool calls aren't working.
- limit.context in opencode.json only tells OpenCode the window size. The OpenAI-compatible API cannot change Ollama's context, so set it on the server (OLLAMA_CONTEXT_LENGTH or the app slider).
- `ollama launch opencode` uses an inline config and does not overwrite ~/.config/opencode/opencode.json; models defined only in opencode.json do not appear in its model picker.
- OpenCode 2 is out and uses the same `opencode` command; these steps follow the OpenCode 1 docs, and the two cannot be installed side by side under the default command.
Other coding agents
How they rank for local models: the best agent harness for local LLMs.
- Qwen Code
- Codex CLI
- Cline
- Kilo Code
- Aider
- Pi coding agent
- Claude Code
- Crush
- Goose
- OpenHands
- Zed agent
- GitHub Copilot BYOK
- Continue (discontinued)
- Roo Code (discontinued)
- Void (discontinued)