OpenCode — open-model path
Spawn OpenCode from inside agent loops. The open-model harness — point it at Llama, Qwen, DeepSeek, or any model you self-host.
Spawn OpenCode from inside agent loops. OpenCode is the open-model path through the harness — point it at Llama, Qwen, DeepSeek, GPT-OSS, or whatever you can run locally through Ollama, vLLM, or OpenRouter.
Reach for OpenCode when you need to dodge vendor lock-in, control inference cost, keep code off third-party servers, or A/B different open-weight models inside the same loop.
Quickstart
Install the opencode CLI and AgentField. OpenCode picks up your model provider from its own config — OPENROUTER_API_KEY, OLLAMA_HOST, or any of its supported backends.
Call the harness
Pin OpenCode's defaults on the agent — the model field is forwarded directly to OpenCode, so you can target qwen/qwen3-coder, a local ollama/llama3.3:70b, or any backend OpenCode supports without changing the loop.
Composition pattern — tournament with budget cap
Burn a small budget across several open-weight candidates, score the diffs, ship the best one. Same provider: "opencode", different model per branch — no other loop code changes.
Options
| Option | Type | Default | What it does |
|---|---|---|---|
provider | string | required | "opencode" for this provider. |
model | string | "sonnet" (override it) | Any model OpenCode supports — qwen/qwen3-coder, deepseek-ai/deepseek-coder-v3, a local ollama/llama3.3:70b, etc. |
opencode_bin | string | "opencode" | Path to the opencode binary if it is not on $PATH. |
cwd | string | working dir | Working directory the agent treats as the repository root. |
project_dir | string | null | Maps to --dir. When set, cwd is used only for output file placement. |
max_turns | int | 30 | Hard cap on agent iterations. |
max_budget_usd | float | null | Cost ceiling — parsed from the JSON event stream when the backend reports per-step cost. |
env | dict | {} | Extra environment variables forwarded to the subprocess. |
system_prompt | string | null | Custom system prompt prepended to the loop. |
schema | model | null | Pydantic class / Zod schema / Go struct. Forces JSON output validated against the schema. |
Backends OpenCode can drive
OpenCode is model-agnostic. Common backends:
- OpenRouter — pick any open-weight model on the OpenRouter catalog (
qwen/qwen3-coder,deepseek-ai/deepseek-coder-v3,meta-llama/llama-3.3-70b-instruct, etc.). - Ollama — self-hosted local inference. Privacy-preserving; latency depends on your hardware.
- vLLM / TGI / LM Studio — for higher-throughput local serving.
- Anthropic / OpenAI / Google — fall back to a hosted model with the same loop code if needed.
The harness does not care which backend you choose — app.harness just forwards model to OpenCode.
When to choose OpenCode
- Privacy-sensitive workflows — code stays on hardware you control.
- Vendor-independence — switch between Llama, Qwen, DeepSeek, and others without changing your loop.
- Cost optimization — run cheap open-weight models for routine tasks, escalate to hosted models on failure.
- Tournament patterns — burn a budget across several open-weight candidates and pick the best diff.
Pairs well with
- Claude Code — Claude reviews the open-weight implementation; mismatch triggers a retry.
- Codex — adversarial pattern: OpenCode proposes, Codex critiques.
- Gemini CLI — Gemini scopes the work across the whole repo, OpenCode executes each piece cheaply.