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.

  1. Install it (macOS / Linux):

    curl -fsSL https://opencode.ai/install | bash
  2. Start Ollama with a 64k context window (or set the context slider in the Ollama app's settings).

    OLLAMA_CONTEXT_LENGTH=64000 ollama serve
  3. In a second terminal, pull a tool-capable coding model (replace qwen3-coder:30b with any model you prefer).

    ollama pull qwen3-coder:30b
  4. Quickest path: let Ollama configure and launch OpenCode for you.

    ollama launch opencode
  5. Or 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
              }
            }
          }
        }
      }
    }
  6. Run OpenCode in your project and pick the model with /models.

    opencode
Other ways to install

npm

npm install -g opencode-ai

Homebrew

brew install anomalyco/tap/opencode

Check 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 ollama

Which 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.

MachineModelQuantContextFitOllama
12 GB GPUQwen 3.5 9BQ4_K_M32,768Comfortable (7.4 GB of 12 GB)qwen3.5:9b
Qwen 3.6 35B-A3BQ4_K_M32,768With CPU offload (MoE) (22.7 GB of 12 GB)qwen3.6:35b-a3b
16 GB GPUQwen 3.5 9BQ4_K_M32,768Comfortable (7.4 GB of 16 GB)qwen3.5:9b
Qwen 3.6 35B-A3BQ4_K_M32,768With CPU offload (MoE) (22.7 GB of 16 GB)qwen3.6:35b-a3b
24 GB GPUQwen3.8 27BQ4_K_M32,768Comfortable (19.9 GB of 24 GB)qwen3.8:27b
Qwen 3.6 27BQ4_K_M32,768Comfortable (19.9 GB of 24 GB)qwen3.6:27b
Devstral Small 2 24BQ4_K_M32,768Comfortable (20.7 GB of 24 GB)devstral-small-2:24b
Qwen 3.6 35B-A3BQ4_K_M65,536Tight (23.3 GB of 24 GB)qwen3.6:35b-a3b
32 GB GPUQwen3.8 27BQ4_K_M32,768Comfortable (19.9 GB of 32 GB)qwen3.8:27b
Qwen 3.6 27BQ4_K_M32,768Comfortable (19.9 GB of 32 GB)qwen3.6:27b
Devstral Small 2 24BQ4_K_M32,768Comfortable (20.7 GB of 32 GB)devstral-small-2:24b
Qwen 3.6 35B-A3BQ4_K_M65,536Comfortable (23.3 GB of 32 GB)qwen3.6:35b-a3b
Qwen3-Coder 30B-A3B (MoE)Q4_K_M65,536Comfortable (25.7 GB of 32 GB)qwen3-coder:30b
Mac, 64 GBQwen 3.6 35B-A3BQ8_0131,072Comfortable (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.

Sources (9), checked 2026-10-20