Skip to content
Integrations
Integrations

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

OptionTypeDefaultWhat it does
providerstringrequired"opencode" for this provider.
modelstring"sonnet" (override it)Any model OpenCode supports — qwen/qwen3-coder, deepseek-ai/deepseek-coder-v3, a local ollama/llama3.3:70b, etc.
opencode_binstring"opencode"Path to the opencode binary if it is not on $PATH.
cwdstringworking dirWorking directory the agent treats as the repository root.
project_dirstringnullMaps to --dir. When set, cwd is used only for output file placement.
max_turnsint30Hard cap on agent iterations.
max_budget_usdfloatnullCost ceiling — parsed from the JSON event stream when the backend reports per-step cost.
envdict{}Extra environment variables forwarded to the subprocess.
system_promptstringnullCustom system prompt prepended to the loop.
schemamodelnullPydantic 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.

See also