---
title: "OpenCode: the open-model path"
description: "Drive OpenCode from inside agent loops, the optional override for AgentField's default CodeAF harness. The open-model path: Llama, Qwen, DeepSeek, or any model you self-host."
url: "https://agentfield.ai/docs/agentfield/integrations/opencode"
canonical: "https://agentfield.ai/docs/agentfield/integrations/opencode"
markdown_url: "https://agentfield.ai/llm/docs/agentfield/integrations/opencode"
contract_version: "2026-03-24-v1"
docs_revision: "a2a2b0669dab"
product: "AgentField"
category: "integrations"
difficulty: "intermediate"
keywords: ["harness", "opencode", "open weights", "llama", "qwen", "deepseek", "self-hosted", "autonomous loop", "provider override"]
last_modified: "2026-11-02T17:24:14.000Z"
ai_summary: "Drive OpenCode from inside agent loops, the optional override for AgentField's default CodeAF harness. The open-model path: Llama, Qwen, DeepSeek, or any model you self-host."
---

OpenCode is an **optional override**. AgentField's harness runs [CodeAF](/docs/agentfield/integrations/codeaf), its own native worker, by default -- set `provider="opencode"` when you specifically want OpenCode driving the loop.

Spawn [OpenCode](https://opencode.ai) from inside [agent loops](/docs/agentfield/quick-guides/harness-orchestration). 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

Only needed for this provider -- the default CodeAF path provisions its binary automatically. Install the `opencode` CLI alongside AgentField. OpenCode picks up its 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 with [`HarnessConfig`](/docs/agentfield/build/building-blocks/harness) — 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 [harness provider](/docs/agentfield/quick-guides/harness-orchestration), different `model` per branch — no other loop code changes.

    
    
    

## Options

| Option | Type | Default | What it does |
| --- | --- | --- | --- |
| `provider` | string | `"codeaf"` | Set to `"opencode"` to select this provider. Unset means the [CodeAF default](/docs/agentfield/integrations/codeaf). |
| `model` | string | empty | Empty means the provider's own default. Set 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](/docs/agentfield/quick-guides/harness-orchestration) 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](/docs/agentfield/integrations/anthropic) — Claude reviews the open-weight implementation; mismatch triggers a retry.
- [Codex](/docs/agentfield/integrations/openai) — adversarial pattern: OpenCode proposes, Codex critiques.
- [Gemini CLI](/docs/agentfield/integrations/gemini) — Gemini scopes the work across the whole repo, OpenCode executes each piece cheaply.

## See also

- [CodeAF -- the default harness](/docs/agentfield/integrations/codeaf)
- [Harness orchestration](/docs/agentfield/quick-guides/harness-orchestration)
- [`HarnessConfig` reference](/docs/agentfield/build/building-blocks/harness)
- [OpenCode docs](https://opencode.ai/docs)
