04 | Subagents and Shared Work
Sunil Tiwari · Oct 29, 2026 · 10 min read
Expanded from Part 4 of OpenCode Architecture by Vinoth Govindarajan, The Agent Stack.
Vinoth's post, "OpenCode Architecture, Part 4: Subagents and Shared Work" (13 October 2026), asks a narrow question with a large answer: when a coordinator agent hands a job to a worker agent, what actually crosses that boundary? His answer, backed by six controlled runs against OpenCode v1.18.30, is that delegation gives you a new conversation. It does not clone the coordinator's policy, its memory or its working copy. This note walks through each of his sections, ties every claim to the OpenCode source he pinned (commit 3104c14), and adds diagrams, worked examples and the places where today's code has moved on.
Architecture map (canvas): the canvas in this project (Canvas or Split view)
The whole handoff at a glance

A restriction needs an owner
Vinoth starts by separating two things that are easy to blur. A role (OpenCode calls it an agent: build, plan, general, explore, or one you define) says what an agent may do. A session is one conversation, with its own messages and its own list of permission rules. A coordinator is a role running in a session; when it delegates, a worker role runs in a new session.
His lab is deliberately small. Two custom roles: coordinator may dispatch to worker (task: { worker: allow }) but is denied direct edits to one file (edit: { labels.mjs: deny }). worker is allowed to edit that file. The task is the same every time: fix a label function so it trims outer whitespace and keeps the spaces inside. Each restriction is moved to a different place, one at a time, while the starting files and request stay fixed. The point of the design is that only the location of the deny changes, so any change in the outcome is caused by where the rule lives.
His six cases, reproduced:
| Case | Where the restriction sits | Child session created? | Outcome |
| Allowed baseline | Nowhere on the edit path | Yes | Worker edited labels.mjs; all four tests passed |
| Direct coordinator edit | Coordinator role denies labels.mjs; coordinator edits itself | No | Edit blocked; file unchanged; original failures remained |
| Delegated coordinator edit | Same coordinator-role deny; coordinator delegates | Yes | Worker edit not blocked; file changed; all four tests passed |
| Parent-session deny | Edit deny on the parent session | Yes | Worker edit denied; file unchanged; failures remained |
| Worker-role deny | Edit deny on the worker role | Yes | Worker edit denied; file unchanged; failures remained |
| Dispatch deny | Coordinator's task rule blocks worker | No | Handoff denied; no edit attempted; file unchanged |
The surprising row is the third. The rule meant "this file must not be edited by this team" was written as "this role may not edit it", and a role's rules apply only to that role. The owner of a restriction decides how far it reaches. A common misconception is that a coordinator is a manager whose limits bind its reports. In OpenCode, a coordinator is closer to a colleague who can ask someone else to do the job.

What authority reaches the worker?
This is where the code tells the story. The task tool (packages/opencode/src/tool/task.ts) does, in order:
- Walks up
parentIDlinks to count depth and fails if it reachessubagent_depth(default 1, so by default a worker cannot spawn its own workers). - Calls
ctx.ask({ permission: "task", patterns: [subagent_type] }). This is the dispatch check. A deny here stops everything before any session exists, which is the sixth row of the table. - Builds the child's rules with
deriveSubagentSessionPermission(agent/subagent-permissions.ts), then callsSession.create({ parentID, agent, permission }).
The derivation is 15 lines and worth reading in full. Its doc comment says it plainly: "Parent agent restrictions only govern that agent; the subagent's own permissions determine its capabilities."
return [
...parentSessionPermission.filter(
(rule) => rule.permission === "external_directory" || rule.action === "deny",
),
...(canTodo ? [] : [{ permission: "todowrite", pattern: "*", action: "deny" }]),
...(canTask ? [] : [{ permission: "task", pattern: "*", action: "deny" }]),
]So the child gets every deny from the parent session, every external_directory rule (which keeps the worker inside the same directory fence), and denies for todowrite and task unless the worker role mentions them. Nothing from the coordinator role is copied.
When the worker then tries an edit, session/tools.ts builds the check as Permission.merge(agent.permission, session.permission), which is a plain concatenation: worker role rules first, child session rules after. permission/index.ts evaluates with findLast, so the last matching rule wins. A copied session deny sits after the worker's role allow, so it wins. That is the fourth row.
Vinoth adds two caveats that the code confirms. First, Permission.ask evaluates ruleset and then the in-memory approved list, again with findLast, so an earlier "always allow" from the user can sit after a copied deny and override it. A copied deny is ordered, not absolute; his runs used fresh approval state for that reason. Second, his coordinator was custom. The built-in plan role (agent/agent.ts) denies edit: "*" and also task: { general: deny }, so the OpenCode authors already close the obvious "plan delegates to general to edit" hole at the dispatch layer.

Code has moved on (current dev, v2.x): OpenCode's packages/opencode was removed in July 2026 and the runtime now lives in packages/core. There the tool is called subagent (core/src/tool/plugin/subagent.ts), the child is created without a copied permission list, primary roles cannot be dispatched as subagents, the depth key is experimental.subagent_depth, and a configured deny is checked before saved approvals so an old "always" cannot override it. Vinoth's findings describe the v1 line (still released, e.g. v1.19.5); on v2, re-run the parent-session-deny case before relying on it.
What does the worker actually know?
Permission answers "may I edit?", never "what is a correct edit?". The requirement to trim outer whitespace but keep inner spaces is intent, and intent travels only in words.
The task tool turns the coordinator's prompt string into message parts (resolvePromptParts) and sends them to the child session. The child's model input is then assembled in session/prompt.ts from four sources: environment info (sys.environment), project instructions (instruction.system(), e.g. AGENTS.md), MCP instructions and skills for that role, and the child session's own message history. The parent's history is not on that list.
Vinoth proved this with markers. A marker that lived only in the parent conversation never reached the worker. A marker written into the delegated prompt did. A third marker, placed in a file, appeared only after the worker read that file. He is careful to add that this is about default context flow, not a confidentiality boundary: the worker shares the filesystem and can read whatever the parent can.
A worked example. Weak delegation: "Fix the label bug in labels.mjs." Strong delegation: "In labels.mjs, formatLabel must trim leading and trailing whitespace only. ' a b ' must become 'a b'. Do not change exports. Run node --test and paste the result." The second carries the edge case, the boundary and the evidence you want back.

What comes back?
In the foreground path the coordinator's task call blocks until the child finishes. The child's tool calls, errors and diffs stay in the child session's records. What the coordinator receives is built by renderOutput in task.ts:
<task id="ses_..." state="completed">
<task_result>
...the worker's last text part...
</task_result>
</task>Only result.parts.findLast(type === "text") is returned. The code does fail the task if the last message contains a tool error, but an error in an earlier step of the worker's run, followed by a polite final message, still yields state="completed". That is exactly what Vinoth saw in the parent-session-deny case: the worker's text honestly said the edit was denied, the wrapper said completed, and the denied operation lived only in the child's history. Neither agent compared bytes or ran tests; his outside harness did.
The lesson is that completed describes the conversation, not the work. Keep the task id (it is the child session id) linked to the operations and files it touched, and accept work on evidence.

Shared files are not shared state
Session.create (session/session.ts) stamps the child with directory: ctx.directory, the same instance directory as the parent. A new session is a new conversation row, not a new checkout or sandbox. Two sessions can therefore edit the same file, and nothing in the session model knows the other is doing it.
task_id adds a second subtlety. If it resolves, task.ts reuses that stored child session, with its old messages and rules, instead of creating a new one. It does not restore any earlier working directory or file state. On interruption the tool calls ops.cancel(childID) (and the abort listener does the same), which asks the loop to stop; there is no promised rollback of edits already made. Vinoth flags that resume, cancel and concurrent writes were outside his tested cases, so treat them as design facts from the code, not measured behaviour. Background subagents (behind OPENCODE_EXPERIMENTAL_BACKGROUND_SUBAGENTS) make the overlap risk sharper, which is why their started message tells the model to "avoid working with the same files or topics".
His recommendation: one writer per file set, or isolated git worktrees per worker with a separate merge step.

Design the whole handoff
Vinoth closes by mapping each part of the label task to the layer that can actually carry it: the prompt carries the whitespace requirement, the runtime checks each operation against role plus session rules, the dispatch rule decides whether the worker can be called at all, and an external checker verifies the file. He then scales it to a refactor with three constraints (protect database migrations, keep API behaviour, verify the patch) and notes that a prompt can state all three but can enforce and verify none of them. Protecting migrations is a deny on the session (or on every worker role) for migrations/*; keeping API behaviour is a contract test; verification is a step outside both agents.

What to steal
His six-question checklist, phrased as things to tick before you delegate:
- Intent: the exact requirement is written down, including what must not change.
- Authority: the restriction sits on the path the worker will really use (session or worker role, not only the coordinator role).
- Context: the worker can reach the decisions, files and instructions it needs, because they are in the prompt or pointed to.
- Shared resources: someone owns writes to every file the worker can touch, or the worker has its own worktree.
- Evidence: the returned task id leads back to the operations and changed files.
- Acceptance: someone checks the current files and behaviour instead of trusting the report.
And the line to remember: delegation creates a new conversation, not a cloned policy or a private checkout.
Quick self-check
- A coordinator role denies edits to
a.tsand delegates to a worker whose role allows edits. Isa.tssafe? - Which two kinds of parent-session rules does v1 copy into the child?
- Why does a copied deny beat the worker's role allow?
- The task result says
state="completed". What has that proved? - Does a resumed
task_idrestore the files the worker saw last time? - Where should "keep inner spaces" live: in a rule, or in the prompt?
Answers:
- No. Role rules govern only that role; the worker's edit succeeds (his third case).
- Every
denyrule and everyexternal_directoryrule (plus defaulttaskandtodowritedenies unless the worker role mentions them). - Rules are merged worker-role first, session second, and evaluated with
findLast, so the later session deny wins. Saved approvals can still come after it in v1. - Only that the child conversation ended without a tool error in its last message. Check bytes and tests.
- No. It reuses messages and rules; the directory is shared and there is no rollback.
- In the prompt (or a test). Permissions say what may be touched, not what correct looks like.
Source and credit
- Vinoth Govindarajan, "OpenCode Architecture, Part 4: Subagents and Shared Work", 13 October 2026, in The Agent Stack. All experiments, numbers and the checklist are his.
- His companion lab: delegation-boundary.md (GitHub: vingov).
- Vinoth on LinkedIn: https://www.linkedin.com/in/vinothgovindarajan
- OpenCode source at the commit he pinned (
3104c14, v1.18.30), anomalyco/opencode:- tool/task.ts: dispatch, depth limit, child creation,
renderOutput - agent/subagent-permissions.ts:
deriveSubagentSessionPermission - session/tools.ts:
Permission.merge(agent, session) - permission/index.ts:
evaluatewithfindLast,ask, approvals - agent/agent.ts: built-in
planpolicy - session/prompt.ts: child input assembly
- session/session.ts:
Session.createand the shared directory
- tool/task.ts: dispatch, depth limit, child creation,
- Current
devfor the v2 notes: packages/core/src/tool/plugin/subagent.ts and packages/core/src/permission.ts.