Harness Notes

Subagents

Updated 2026-11-24,

On this page

How each harness starts and configures subagents, what they can see and change, which lifecycle hooks run, and how their transcripts are saved and read.

Worktrees: creation, setup, integration and cleanup

Starting one

QuestionOpenCodechecked at 2.0.29
Is there one, and how does it start

Yes. The primary agent launches one with the subagent tool, choosing from a list of available subagents that is added to the tool description. You can also @-mention a subagent in the composer, or run a command with subagent: true (or with an agent whose mode is subagent), which starts it in a background child session.

Built-in subagents

general handles research and multi-step work and cannot launch further subagents. explore searches and reads code and web sources without editing. build and plan are primary agents, and compaction, title and summary are hidden maintenance agents. You can override a built-in by reusing its ID.

Define your own

Add a Markdown file to ~/.config/opencode/agents/<name>.md (global) or .opencode/agents/<name>.md (project). The frontmatter takes the same fields as a config entry and the body becomes system; nested paths set the ID, so .opencode/agents/team/reviewer.md is team/reviewer. You can also define agents under agents in any OpenCode config file. Definitions merge in configuration order: later scalar values replace earlier ones, and permissions rules are appended.

New custom agents default to mode: primary, so set mode: subagent (or all) to make one callable as a subagent. Legacy agent/ and mode(s)/ folders are still read, and edits reload without a restart.

What a definition can set

description (shown to the model when it picks a subagent), mode, model (provider/model#variant), system, permissions (ordered action/resource/effect rules), steps, hidden, color (hex), disabled and request (header and body overlays, which the V2 runner does not send yet). There are no per-agent MCP, skills or memory fields; MCP tools are gated through permissions actions named <server>_<tool>.

V1 fields prompt, temperature, top_p, permission, tools, disable and maxSteps are legacy. Use system, request.body, permissions, disabled and steps instead.

While it runs

QuestionOpenCodechecked at 2.0.29
What it sees, and what comes back

A new child session starts with fresh context, containing only the prompt the main agent writes plus a line saying it is a subagent. When it finishes, the text of its last reply returns to the main agent inside <subagent sessionID="..." state="completed">. Passing that sessionID back continues the same child conversation. The main agent can also pick the child's model per call with model; otherwise it uses the agent's model or the parent's.

Several at once

Yes. Since 2.3.0 all subagent calls run in the background and return immediately, so the main agent can keep launching work. The earlier background: true input is historical; this selected source review does not establish a new concurrency limit.

Since 2.3.0 all subagent launches run in the background; the earlier background: true input is historical.

Keep working while it runs

Since 2.3.0, subagents always run in the background. The call immediately returns sessionID and status running; background is no longer an input field. The parent receives a <subagent> message each time the child goes idle, including after later rounds. If descendants or other background work remain, the report identifies outstanding work and can retain state running. No polling is needed.

2.2.1 /goal waits instead of reviewing while the session's own subagent or image job is running, since that job's completion notice wakes the session. A step taken by any descendant subagent restarts the goal's 30-minute wait timer.

Confirmed at v2.3.2 through tool schema, job startup and parent-inbox report delivery. This replaces the older selectable foreground/background behavior; no execution/restart probe.

Your checkout or its own copy

Subagents run in the parent session's directory and edit your checkout directly; there is no automatic per-subagent worktree or sandbox, so there is nothing to merge. Worktrees exist as separate session tools (worktree_create, session_move), which an agent can use to move a whole session into a new worktree.

Its permissions

Launching a subagent is gated by the parent's subagent permission, with the agent ID as the resource. The child then runs with its own agent's permissions, appended after the global permissions and not limited to the parent's. ask rules still prompt you, and saved "allow always" approvals for subagents are stored by agent ID.

Subagents of subagents

Only one level by default: experimental.subagent_depth defaults to 1. Raise it in config to allow subagents to launch their own. The built-in general and explore agents also deny the subagent action, so nested calls need a custom subagent.

The V1 top-level subagent_depth key is replaced by experimental.subagent_depth.

Watching and handing off

QuestionOpenCodechecked at 2.0.29
Watch, steer or stop one

In the terminal client, Down opens the subagent picker in the composer. From there Up/Down select, Enter opens the child session and ctrl+d interrupts it. Right/Left cycle between child sessions and Up returns to the parent. You can steer a child by typing in its session, and Esc interrupts the session you are in.

Hand work to a cloud agent

Not supported

No. Subagents run as local child sessions on the same OpenCode server; there is no built-in cloud or remote handoff for delegated work.

Notes and sources

OpenCode, 21 sources
Is there one, and how does it start, 5
Built-in subagents, 2
Define your own, 2
What a definition can set, 3
What it sees, and what comes back, 2
Several at once, 7
Keep working while it runs, 11
Your checkout or its own copy, 3
Its permissions, 3
Subagents of subagents, 4
Watch, steer or stop one, 2
Hand work to a cloud agent, 1

Subagent lifecycle hooks

Recorded start and stop events, with their control semantics and availability caveats. A dash means no event is recorded here. General session or tool events do not establish a dedicated subagent hook.

Which moments a hook can attach to, and what it can do there. Event names link to each harness’s documentation. “Block”, “deny” and “modify” change what the agent does; “observe only” can watch but not intervene. Where hook files live is on the Locations page.

MomentOpenCode 2.xPlugin hooks and events
Hook typesPlugin hooks and events

Notes and sources

OpenCode 2.x
  • @opencode/cli 2.x, checked at 2.0.28. 1.x plugins do not run in 2.x.
  • Plugins register hooks per domain with ctx.<domain>.hook(name, callback); each callback receives one mutable event. Hooks run in plugin order.
  • Transforms are synchronous edits to registered definitions, replayed in registration order.
  • Events are read with ctx.event.subscribe() and can only be observed.
  • 2.1 renames provider replay data to native across text/reasoning lifecycle, tool and step/compaction events. Tool result native shallow-merges into call native; execution state is unchanged. SessionCompactionResult.providerState becomes native. session.compacted is removed; subscribe to current compaction lifecycle events.
  • 2.1 adds paginated ctx.session.list to both Effect and Promise plugin APIs.
  • 2.2.0 source: event.subscribe({types}) filters events by registered type; unknown types warn and are ignored. Plugin reload activation is awaited before model-step context preparation. Session instruction entry mutations use ctx.session.instructions.entry.*, independently of hook callbacks. Experimental desktop GUI plugins use a separate Electron/main and app renderer loader; this is not a CLI/TUI rendering guarantee.
  • 2.2.1 adds the experimental experimental.idle session hook (ctx.session.hook). Input added from it, such as a synthetic message, continues the same execution instead of letting the session go idle. The built-in /goal plugin is its first user.
  • 2.2.4+ schedule lifecycle, traced at 2.2.7: ServerProcess.start forks Schedule.run outside the optional managed lifecycle branch, including opencode serve/standalone servers. A SQLite lease elects one scheduler per database; experimental.schedules remains checked at fire time. This is a core background scheduler, not a new plugin hook event; no firing probe.
  • Since 2.3.1, schedules become experimental automations: use experimental.automations (schedules remains an alias), /automation and automation_* tools. Triggers support time/interval/cron or MCP push events, with prompt or Code Mode actions. Event triggers also require mcp_events. Every server starts the automation loop. Migration keeps only active/paused plain-prompt schedules without conditions/run limits and with a next due time; it drops the old table. Prior schedule findings describe 2.2.x. No scheduler or migration runtime probe.
  • In 2.4.0, automations use the top-level automations setting. Set it to false to disable timer, cron and MCP-event automations.

Subagent transcripts

Child storage and parent links are described separately from the harness’s general session format. Internal and source-observed formats can change between versions; these records do not promise a stable external schema.

QuestionOpenCodesource-observed; checked at 2.3.0
Child transcripts and parent links

Subagent runs become child sessions in the same session_v2 table, with parent_id set to the calling session, and they report their results back to the parent. Forks are new sessions whose fork_session_id and fork_boundary point to the source session. opencode session list shows only top-level sessions.

Session file format

Partly

SQLite with session_v2 and session_message, plus optional split assistant session_part rows and deduplicated blob/blob_ref media. The internal reader joins parts before hydrating media and decoding legacy/current shapes. experimental.part_rows and experimental.media_blob default off, but reads support mixed representations. Use the matching server API or session export rather than assuming data.content alone is the transcript.

On first start, 2.x migrates 1.x sessions in place within the same database from the old session/message/part tables into session_v2/session_message, and also imports any opencode-next.db.

2.1 changes public SDK/HTTP/plugin field names. Stored/imported legacy rows are normalized by compatibility decoders without a new database migration; do not keep sending legacy fields in public writes.

What is recorded

Entries include user/system/synthetic/skill/shell messages, assistant text/reasoning/tools, compaction, idle markers and settings changes. With part_rows, assistant content is ordered session_part data followed by any remaining inline content. With media_blob, attachments can carry media:<sha256> references into blob; missing bytes yield unavailable placeholders. Session totals include auxiliary model usage that need not have a visible message row.

2.1 names provider replay data native on text/reasoning parts, tools, assistant/compaction messages and lifecycle events. Tool call/result blobs shallow-merge into tool.native (result keys win); tool.state remains execution status/output. Native checkpoint windows are native.messages.

Read transcripts from code

Every client talks to a local background server whose V2 HTTP API includes session.list, session.get, session.message.list (GET /api/session/{sessionID}/message), session.log and experimental.session.export. Use it through the @opencode/client package or opencode api. opencode run --format json emits JSON events. The V1 server API and SDK are not compatible with 2.x.

Since 2.1, replay data is in native, summary tails in metadata.keepID and provider windows in native.messages; the session.compacted event is gone.

Session record structureOpenCode
Envelope fieldsid, session_id, type, seq, time_created, time_updated, data
Record discriminatorsession_message.type (user|assistant|synthetic|system|skill|shell|compaction|idle|agent-switched|model-switched|location-switched)
Identifiers and lineagesession_v2.id, session_v2.parent_id, session_v2.fork_session_id, session_v2.project_id, session_v2.workspace_id, session_message.id (msg_...), tool call id
Orderingper-session monotonically increasing seq (unique index on session_id, seq)

Notes and sources

OpenCode, 16 sources
  • Partial refresh at v2.1.1: replay-data fields, compaction references and archive API verified; existing database-path and command evidence remains scoped to 2.0.29. No runtime/import probe.
  • 2.2.0 source adds opt-in experimental.media_blob storage for inline user/tool media, off without the setting. Normal history reads hydrate references; clients opt into media: references with x-opencode-capabilities: experimental-media-uri. Missing blob bytes become an unavailable-media text placeholder. Instruction entry state is separate from chronological instruction updates; previous transcript schema pins are not upgraded wholesale.
  • 2026-11-15 source refresh: v2.3.0 at a6b15d33daf6ab7d35569f6d711fdb630b9f04e7. Source inspection, not a harness runtime probe. Historical supplements keep their independent evidence and dates.
  • The historical 1.x and dev-json variants are separate formats; neither defines 2.3.0 rows. Older CLI/export instructions retain their independently dated evidence.
Child transcripts and parent links, 5
Session file format, 6
What is recorded, 6
Read transcripts from code, 6