opencode subagents: @ mention, agent files, a model per agent and the depth limit
- opencode
- coding-agents
- agent-ops
Yes. opencode has subagents. Two ship built in, general and explore. The primary agent launches one through a tool, task in opencode 1.x and subagent in opencode 2. Or you type @ and its name. A custom subagent is a markdown file in .opencode/agents/ with mode: subagent in the frontmatter. This post reads the docs and the source. I do not run opencode.
# .opencode/agents/reviewer.md (1.x syntax; in 2 the field is a permissions list)
---
description: Reviews changes for correctness and regressions
mode: subagent
model: anthropic/claude-sonnet-5-5
permission:
edit: deny
---
Review the current changes. List findings with file and line.
- Two kinds of agent. Primary agents take your prompt. Subagents run in a child session with fresh context.
modedecides. - Two ways in. The primary agent picks a subagent by its
description. Or you type@generalin the prompt. - Own model.
modelin the agent file wins. Without it, a subagent inherits the model of the agent that called it. - The limit is depth, not count.
subagent_depth(1.x) orexperimental.subagent_depth(2) defaults to 1. I found no key for a concurrent count. - How I know. Docs for 1.x and 2, source at tags v1.19.5 and v2.2.5, read on 31 October 2026. No run of my own.
The Anthropic side, with my two agent files, is in Claude Code subagents. The Codex side is in Codex subagents.
Does opencode have subagents?
Yes. The agents page of the 1.x docs splits agents into two types. Primary agents take your prompt. Subagents are "specialized assistants that primary agents can invoke for specific tasks". The built-in subagents are general, with every tool except todowrite, and explore, read-only.
The launch goes through a tool, task in the v1.19.5 source and subagent in v2.2.5. The v2 agents page says subagents "run with fresh context in foreground or background child sessions". Delegation is automatic, "based on their descriptions" per the 1.x docs, as in Claude Code.
How do I configure opencode subagents?
A markdown file, or an entry in opencode.json. The JSON map is called agent in 1.x and agents in 2, per the migration guide. The 1.x docs name two folders, ~/.config/opencode/agents/ for every project and .opencode/agents/ for one. The file name becomes the agent name. The body is the system prompt.
description is required. The model reads it to choose. mode takes primary, subagent or all. In 1.x a missing mode means all. In 2 a new custom agent defaults to primary, so a file without mode: subagent will not run as one.
Permissions are per agent. In 1.x the keys are edit, bash, webfetch and the like, each ask, allow or deny. opencode 2 renames the field to permissions, an ordered list of action, resource and effect. Per the migration guide, bash becomes shell, task becomes subagent, prompt becomes system. Old agent markdown files still load. What deny rules still stop under --auto is in opencode --dangerously-skip-permissions.
In 1.x, permission.task on the parent agent says which subagents it may launch. Glob patterns, last match wins. A deny removes the subagent from the tool description. You can still call it with @. In 2 the same rule is an entry in permissions with "action": "subagent", the agent id as resource and "effect": "deny". The v2.2.5 source drops a denied agent from the tool's "Available subagents" list too.
Can an opencode subagent use a different model?
Yes. Set model in the agent file or in the agent's JSON entry. The format is provider/model-id. opencode 2 adds a variant after #, as in anthropic/claude-sonnet-5-5#high.
Without a model, the 1.x docs say subagents "use the model of the primary agent that invoked the subagent". The v2.2.5 source resolves it in one line. A model passed on the tool call wins, then the agent's model, then the parent session's model. That tool parameter is new in 2. Its description says "NEVER set this unless the user explicitly asks for a particular model". I have not tried it.
What is the opencode subagents limit?
Depth. The 1.x config page documents subagent_depth with a default of 1. Primary agents can launch subagents, which cannot launch more. Set 2 for one nested level, 0 to block every launch. In 2 the key moves to experimental.subagent_depth. The v2.2.5 source counts parents up the session chain and fails the call with "Subagent depth limit reached".
I found no setting for how many subagents can run at once, not in the docs and not in the two tool files. Claude Code documents 20 concurrent. opencode is silent.
How do I view running subagents in opencode?
Child sessions. The 1.x agents page lists the keybinds. session_child_first, by default Leader and Down, enters the first child. Right and Left cycle through children. Up returns to the parent. The opencode 2 footer count and the sidebar plugin that lists child sessions are in my opencode statusline post. How to get back to a parent or child session after a restart is in opencode resume.
Background runs are newer. In v1.19.5 background: true on the tool needs OPENCODE_EXPERIMENTAL_BACKGROUND_SUBAGENTS=true. In v2.2.5 it works without a flag.
Why does an opencode subagent get stuck?
Per issue #59566, opened on 27 October 2026 about opencode 2.1.0, a background child can end in a "completed"-looking state after a provider stream cut, and the parent has no tool to check or cancel it. The sessionID follow-up hung and cancelling worked only through the close button in the UI. I have not reproduced it. The v2.2.5 tool tells the parent not to "sleep, poll for progress, ask the subagent for status". I think that is why a dead child looks like a slow one from the parent's side.
opencode subagents vs Claude Code subagents
| opencode 1.x / 2 | Claude Code | |
|---|---|---|
| Agent file | Markdown, .opencode/agents/ | Markdown, .claude/agents/ |
| Marks a subagent | mode: subagent | Any agent file |
| Built-in subagents | general, explore | Explore, Plan, general-purpose and three more |
| Manual call | @name in the prompt | @agent-name in the prompt |
| Model fallback | 1.x: the calling agent's model. 2: the parent session's model | Env variable, then the main model |
| Depth | 1.x: subagent_depth. 2: experimental.subagent_depth. Default 1 | Default 3 layers |
| Concurrent limit | Not documented | 20 by default |
Frequently asked questions
Does opencode have a Task tool?
In 1.x, yes. The v1.19.5 source has task.ts with the parameter subagent_type. In opencode 2 the tool is named subagent.
Can opencode subagents run in the background?
In 2, yes, with background: true on the tool call. In 1.x the same parameter sits behind OPENCODE_EXPERIMENTAL_BACKGROUND_SUBAGENTS, listed as experimental on the CLI page.
Did you test this?
No. opencode is not installed on my machine. This post reads the 1.x and v2 docs and the source at two tags on 31 October 2026.
The verdict
From Claude Code, the file shape is the same plus one line, mode: subagent. Put the model in the file. Leave the depth limit at 1 until you need nesting. Check the version first: field names, the tool name and the permission block changed between 1.x and 2.
Sources, read on 31 October 2026: the opencode agents, config and CLI pages for 1.x, the v2 agents, config and migration pages, and anomalyco/opencode at tags v1.19.5 (tool/task.ts) and v2.2.5 (tool/plugin/subagent.ts). Claude Code numbers are from Create custom subagents.