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
| Question | OpenCodechecked at 2.0.29 |
|---|---|
| Is there one, and how does it start | Yes. The primary agent launches one with the |
| Built-in subagents |
|
| Define your own | Add a Markdown file to New custom agents default to |
| What a definition can set |
V1 fields |
While it runs
| Question | OpenCodechecked 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 |
| 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 ( |
| Its permissions | Launching a subagent is gated by the parent's |
| Subagents of subagents | Only one level by default: The V1 top-level |
Watching and handing off
| Question | OpenCodechecked at 2.0.29 |
|---|---|
| Watch, steer or stop one | In the terminal client, |
| 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
Several at once, 7
Keep working while it runs, 11
Your checkout or its own copy, 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.
| Moment | OpenCode 2.xPlugin hooks and events |
|---|---|
| Hook types | Plugin 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.idlesession 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.
- OpenCode v2 plugin development, Documentation, checked 2026-10-15
- OpenCode 2.0.29 session hooks, Source code, checked 2026-10-15
- OpenCode 2.0.29 event union, Source code, checked 2026-10-15
- OpenCode 2.1.0 official release notes; snapshot retained in October 21 review, Documentation, checked 2026-10-21
- OpenCode v2.1.1: packages/schema/src/session-legacy.ts, Source code, checked 2026-10-21
- OpenCode 2.2.0: entry-host, Source code, checked 2026-10-28
- OpenCode 2.2.0: entry-runner, Source code, checked 2026-10-28
- OpenCode 2.2.0: gui-desktop, Source code, checked 2026-10-28
- OpenCode 2.2.0: gui-root, Source code, checked 2026-10-28
- OpenCode 2.2.2: packages/plugin/src/effect/session.ts, Source code, checked 2026-10-30
- OpenCode 2.2.2: packages/core/src/plugin/goal.ts, Source code, checked 2026-10-30
- opencode v2.2.7: packages/server/src/process.ts, Source code, checked 2026-11-12
- opencode v2.2.7: packages/core/src/schedule.ts, Source code, checked 2026-11-12
- opencode v2.2.7: packages/core/src/schedule.ts, Source code, checked 2026-11-12
- opencode v2.3.2: packages/server/src/process.ts, Source code, checked 2026-11-20
- opencode v2.3.2: packages/core/src/automation.ts, Source code, checked 2026-11-20
- opencode v2.3.2: packages/schema/src/automation.ts, Source code, checked 2026-11-20
- opencode v2.3.2: packages/core/src/database/migration/20261116043204_automation.ts, Source code, checked 2026-11-20
- opencode v2.3.2: packages/schema/src/config/flag.ts, Source code, checked 2026-11-20
- OpenCode 2.4.0 release notes, Documentation, checked 2026-11-24
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.
| Question | OpenCodesource-observed; checked at 2.3.0 |
|---|---|
| Child transcripts and parent links | Subagent runs become child sessions in the same |
| 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 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 Since 2.1, replay data is in |
| Session record structure | OpenCode |
|---|---|
| Envelope fields | id, session_id, type, seq, time_created, time_updated, data |
| Record discriminator | session_message.type (user|assistant|synthetic|system|skill|shell|compaction|idle|agent-switched|model-switched|location-switched) |
| Identifiers and lineage | session_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 |
| Ordering | per-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.