Skip to Content

OpenCode agents and model routing

OpenCode routes work through primary agents (Plan, Build) and subagents (@explore, @scout, @general). Each agent can use a different model, step cap, and permission set — the main cost-control surface after opencode stats.

This page answers opencode plan build, opencode agent, opencode max steps, and subagent overhead.

Hub: Tokenminning in OpenCode.

Plan vs Build

Press Tab to cycle primary agents. Plan is read-only by default (edits and bash set to ask); Build has full tool access.

AgentModeTypical modelWhen to use
PlanprimaryHaiku / mid-tierAnalysis, architecture, review plans
BuildprimarySonnet-classEdits, refactors, implementation

Start in Plan; switch to Build only when you approve the approach. See Intro: Plan mode .

{ "$schema": "https://opencode.ai/config.json", "default_agent": "plan", "model": "anthropic/claude-sonnet-4-5", "small_model": "anthropic/claude-haiku-4-5", "agent": { "plan": { "model": "anthropic/claude-haiku-4-20250514" }, "build": { "model": "anthropic/claude-sonnet-4-5", "steps": 25 } } }
SettingToken effect
default_agentEvery new session starts in Plan — avoids accidental Build loops
small_modelCheaper model for hidden title, summary, compaction agents
agent.build.stepsHard cap on agentic iterations before forced text reply

Built-in subagents

Invoke with @ mention or let the Task tool delegate. Each subagent spawns a child session with fresh context and its own model calls.

SubagentAccessCost profilePrefer when
@exploreRead-onlyLow — no edit loopFile patterns, codebase search
@scoutRead-onlyMedium — may clone dependency reposUpstream library research
@generalFull toolsHigh — parallel child sessionsMulti-step work only

Do not @general for simple grep. Use built-in grep / @explore instead.

Limit subagent depth and spawning

{ "subagent_depth": 1, "agent": { "build": { "permission": { "task": { "*": "deny", "explore": "allow", "scout": "allow" } } } } }
SettingEffect
subagent_depth1 (default) — subagents cannot spawn nested subagents
permission.taskDeny @general by default; allow read-only subagents only

Hidden system agents (compaction, title, summary) also call the model when triggered. Route them to small_model via global config — see Providers.

Cap agentic loops with steps

From Agents: max steps :

{ "agent": { "build": { "steps": 25 }, "quick-thinker": { "steps": 5 } } }

When the limit is hit, OpenCode forces a text summary instead of more tool calls. Pair with permission.bash: "ask" if shell loops dominate spend.

Custom agents

Define agents in opencode.json or markdown under .opencode/agents/:

{ "agent": { "code-reviewer": { "description": "Reviews code without edits", "mode": "subagent", "model": "anthropic/claude-haiku-4-20250514", "permission": { "edit": "deny", "bash": "deny" }, "steps": 10 } } }

Keep custom agent prompts short. Set steps on any looping agent. Use mode: "subagent" for specialized work you invoke with @review.

Interactive scaffold: opencode agent create.

Troubleshooting

Frontier model on every question — Set default_agent: "plan" and cheaper agent.plan.model.

Parallel subagent spike — Restrict permission.task; prefer @explore over @general.

Hidden agent cost — Assign small_model; disable unnecessary auto-compaction if sessions are short (Context).

Last updated on