OpenCode is a terminal coding agent that connects to 75+ LLM providers. That flexibility is great until you have to pick one. The model you run decides whether OpenCode produces code that compiles on the first try or sends you in circles — so here’s how to choose, ranked by what they’re actually good for.

The quick answer

ModelInput / Output (per 1M)ContextBest for
Claude Sonnet 4.6$3 / $151MThe reliable default — daily coding, multi-file edits
Claude Opus 4.6~$5 / $25200KLarge refactors where mistakes are expensive
GPT-5.4 Codexpremium tier400KBig diffs, heavy multi-file work
Gemini 3.1 Pro~$2 / $121MLong-context: whole-repo Q&A, large logs
DeepSeek V3.2~$0.27 / M128KLow-cost coding fallback
MiniMax M2.5~$0.12 / $1200K+Budget — routine edits, high-volume work
GLM-4.7 / GLM-5sub-dollar128K+Cheap general-purpose coding
Qwen3 Codercheap256KCode-specialized, strong price/performance
Gemma 4 8B (Ollama)$0 (local)128KPrivate, offline, no API bill

If you don’t have a reason to pick something else, start with Claude Sonnet 4.6 — best tool-calling reliability for the cost, and the 1M window keeps long sessions coherent.

What matters for an OpenCode model

Skip the leaderboard. For OpenCode specifically:

  • Tool-call precision — OpenCode executes file ops and shell commands through the model’s tool calls. A model that mangles arguments edits the wrong file. Claude and GPT-5-class models are the most disciplined.
  • Multi-file coherence — real changes touch several files. You want a model that holds the architecture in its head and doesn’t break an interface in file C while fixing file A.
  • Code that runs — does the diff compile and pass tests, or does it look plausible and fail? This is where flagships earn their price on hard tasks.
  • Cost per session — coding sessions are token-heavy. A model 20–50x cheaper per token is 20–50x cheaper per afternoon of work; that’s why the budget tier exists in this list.

Best overall — Claude Sonnet 4.6

At $3/$15 per million tokens with a 1M-token window, Sonnet 4.6 is the model most OpenCode users should run by default. Tool calls land, multi-file edits stay consistent, and it tracks the constraints you set across a long session instead of forgetting them three edits in. Configure this one first.

If you want to spend a bit less while keeping Claude’s reliability, Claude 3.7 Sonnet (also $3/$15) is still excellent for autonomous coding loops — prefer it over Sonnet 4 if you don’t need the 1M context.

Best for big refactors — GPT-5.4 Codex or Claude Opus 4.6

When OpenCode is doing a large refactor or wading through a gnarly bug across many files, step up. GPT-5.4 Codex is tuned for exactly this and handles large diffs well. Claude Opus 4.6 (~$5/$25) is the choice when a single wrong edit is costly — the model to put behind OpenCode when it’s touching production code or infra.

Both are expensive. Don’t make them your default; route to them for the tasks that need the horsepower and keep something cheaper for everything else.

Best for long context — Gemini 3.1 Pro

Gemini 3.1 Pro’s 1M-token window lets you point OpenCode at an entire repository and ask it to find the bug or explain the architecture. For whole-codebase Q&A, large log analysis, or working across a sprawling monorepo, it’s the context leader, and at ~$2/$12 it’s cheaper than the Claude or GPT flagships.

Best budget — MiniMax M2.5, DeepSeek V3.2, GLM, Qwen3 Coder

This is where the bill shrinks. MiniMax M2.5 at roughly $0.12/$1 per million tokens is the cheapest model that still produces working code in OpenCode — fine for routine edits, boilerplate, and most day-to-day work. DeepSeek V3.2 (~$0.27/M) is the low-cost coding fallback. GLM-4.7 / GLM-5 sit in the same sub-dollar tier, and Qwen3 Coder is the code-specialized option with strong price/performance.

The pattern that works: run a budget model as your OpenCode default and override to Sonnet or a Codex model only for the hard stuff. Most people see the majority of their bill disappear from that one change.

Best local models for OpenCode

For zero API cost or data that can’t leave your machine, run a local model. OpenCode treats Ollama and LM Studio as ordinary OpenAI-compatible custom providers.

  • Gemma 4 8B — runs on a 16GB Mac. Good for reading code, simple edits, boilerplate.
  • Qwen3.5 27B — needs ~32GB but is meaningfully stronger on code; the best local pick if you have the RAM.
  • Llama 3.3 70B — strongest open model here, but you’ll want a serious GPU to run it well locally.

Wire Ollama in:

ollama pull gemma4
opencode auth login   # choose "Other", provider id: ollama, any key value
{
  "provider": {
    "ollama": {
      "npm": "@ai-sdk/openai-compatible",
      "options": { "baseURL": "http://localhost:11434/v1" },
      "models": { "gemma4": { "name": "Gemma 4 8B" } }
    }
  }
}

Restart OpenCode, run /models, pick Gemma 4. Local models won’t match a frontier flagship on hard multi-step work — keep a cloud model configured as a fallback. For the deeper local rundown, see Best Ollama Models for Coding Agents.

Set up haimaker.ai with OpenCode

The simplest way to use every model above without a separate account and key per provider is to wire haimaker.ai into OpenCode once as an OpenAI-compatible provider, then switch models from /models.

  1. Create an account and copy an API key at app.haimaker.ai. New accounts get free credits.

  2. Store the credential:

    opencode auth login
    

    Choose Other, enter provider id haimaker, and paste your API key.

  3. Add the provider to opencode.json (or ~/.config/opencode/opencode.jsonc):

    {
      "provider": {
        "haimaker": {
          "npm": "@ai-sdk/openai-compatible",
          "options": { "baseURL": "https://api.haimaker.ai/v1" },
          "models": {
            "anthropic/claude-sonnet-4-6": { "name": "Claude Sonnet 4.6" },
            "openai/gpt-5-4-codex": { "name": "GPT-5.4 Codex" },
            "minimax/minimax-m2-5": { "name": "MiniMax M2.5" },
            "deepseek/deepseek-v3-2": { "name": "DeepSeek V3.2" }
          }
        }
      }
    }
    
  4. Restart OpenCode, run /models, and pick a model. To add more later, drop the model ID into the same haimaker block — the credential and base URL stay the same.

Want pricing and benchmarks side by side before you choose? Every model is in one place at haimaker.ai.

GET $10 FREE CREDITS ON HAIMAKER


Related: OpenCode Custom Provider Setup · Use Ollama with OpenCode · Best Ollama Models for Coding Agents