Subagents and worktrees: what parallel coding agents share, and where a decision has to live so every worker sees it
A subagent starts with a clean context and hands back a summary. A worktree isolates files and nothing else. What Claude Code, Codex and Cursor document about what a parallel worker starts with, what comes back and which hooks run when one starts, a 20-minute drill with four planted facts, and where to keep the decisions that have to reach every worker.
You split a refactor across four workers. Twenty minutes earlier, in the main session, you had said: leave the legacy billing adapter alone, the mobile app still calls it. Three workers leave it alone. The fourth rewrites it. No error was printed and git did its job: every worker had its own worktree and nothing collided. The rule was in your conversation, the fourth worker was started with a shorter brief, and the sentence was not in it.
Parallel work in a coding harness is built on two kinds of isolation. A worktree isolates files. A subagent isolates context. Both are deliberate, and both are the reason the setup scales. What neither gives you is a way for a decision to cross from one worker to the others. This guide puts side by side what Claude Code, Codex and Cursor document, gives you a drill to see what your own workers start with, and shows where a decision has to be written so that every worker reads it.
What a parallel worker starts with
A subagent does not continue your conversation. The parent model writes it a brief and the worker starts from that:
- Claude Code: "Each subagent starts with a fresh, isolated context window. It doesn't see your conversation history, the skills you've already invoked, or the files Claude has already read. Claude composes a delegation message that summarizes the task, and the subagent works from there."
- Cursor: "Subagents start with a clean context. The parent agent includes relevant information in the prompt since subagents don't have access to prior conversation history."
- Codex: the subagents page lists what a subagent inherits (model, sandbox and approval settings, skills, MCP servers) and recommends telling Codex "what summary or output to return". It does not say whether a subagent sees the parent conversation.
The way back is as narrow as the way in. Claude Code says the subagent "does that work in its own context and returns only the summary". Cursor: "The parent only sees the final summary." Codex recommends it as the pattern: "Return summaries from subagents instead of raw intermediate output."
So a fact reaches a worker when the parent model thought of writing it into the brief, and a finding reaches the parent when the worker thought of writing it into the summary. Everything else stays where it was said.
What each harness documents
| Claude Code | Codex | Cursor | |
|---|---|---|---|
| Starting context | System prompt, the delegation message, the CLAUDE.md files, a git status snapshot. Not the conversation and not the files already read. A fork is the exception: it inherits the whole conversation | The inherited settings below. Whether the parent conversation is visible is not stated | A clean context and the prompt the parent writes |
| Instruction files | Loaded, except by the built-in Explore and Plan agents and by agents with omitClaudeMd: true. A subagent in its own worktree takes them "from your main conversation, not from its worktree" | Not stated for subagents. An ignored AGENTS.override.md is copied into managed worktrees automatically | Not stated on the subagents page |
| MCP servers | Inherited from the main conversation. "A background subagent keeps every MCP tool" | Inherited from the parent. A custom agent file cannot override them: "Configure MCP servers in the parent session so the agent can use them" | Inherited from the parent. Cloud subagents use the servers configured for the team at cursor.com/agents, "not the servers from your local session" |
| What comes back | "only the summary" | A summary, collected by the main thread | "the final summary" |
| The harness's own memory | The main conversation's auto memory is not loaded into a subagent. A custom subagent can keep its own with the memory field. Auto memory is "machine-local", shared by all worktrees of one repository, and "not shared across machines or cloud environments" | Local memories are off by default, live under ~/.codex and are generated in the background from idle chats: "Memories may not update right away when a chat ends" | Not covered in the pages we read |
| Hook when a subagent starts | SubagentStart. It cannot block the subagent. It can return additionalContext, "added to the subagent's context at the start of its conversation, before its first prompt" | SubagentStart. "Plain text on stdout is added as extra developer context for the subagent" | subagentStart. It can allow or deny. Its input carries task: "The task description given to the subagent". No output that adds context is documented |
| Worktree base | The repository's default branch. worktree.baseRef: "head" branches from your current HEAD and carries unpushed commits | The HEAD of the branch you select, in detached HEAD. "If you chose a branch with local changes, Codex applies the uncommitted changes to the worktree as well" | Not stated on the worktrees page. Setup commands go in .cursor/worktrees.json |
| Workers talking to each other | Subagents report to the parent. Named subagents can message each other. Agent teams, experimental and disabled by default, share a task list and message directly, and "The lead's conversation history does not carry over". A cross-session message is "a piece of text one Claude writes to another, never the sender's conversation history or files" | Not documented in the pages we read | Not documented in the pages we read |
Two cells deserve a second read.
The MCP row is the same in all three: the worker keeps the parent's MCP servers. That is the one channel that reaches a subagent without anyone remembering to put it in the brief, and the rest of this guide leans on it. Cursor's cloud subagents are the exception, because they run on a VM and take their servers from the team configuration.
The hook row is not the same. Claude Code and Codex let a hook add text to every subagent at the moment it starts. Cursor's hook at that point decides allow or deny, and what it gives you is visibility: the task field is the brief the worker is about to receive.
Files first: one working tree is one index
Before the context problem there is a plain git one. Cursor says it directly: "Subagents share the parent agent's checkout by default. When several subagents edit files at once, they can overwrite each other's changes." Codex asks you to "be more careful with parallel write-heavy workflows, because agents editing code at once can create conflicts".
There is a quieter version that produces no conflict at all. Agents in the same working tree share one git index. On October 11, 2026, with three of our agents in one checkout, one agent ran git add on its file and committed, and the commit took 31 files another agent had just staged. Nothing failed. The commit message described one fix and the diff contained someone else's unfinished work. The rule we wrote down that day:
# commit only your own paths; whatever else is staged stays out of the commit
git commit -m "fix: parse nested brackets" -- src/parser.ts test/parser.test.tsA new file still needs its own git add <path> right before that commit. With a worktree per worker the index is no longer shared and this goes away. That is what worktrees are for, and it is all they are for: Claude Code's own overview notes that "Agent teams don't isolate teammates in worktrees", and a worktree per worker says nothing about what each worker knows.
Four facts that do not cross by themselves
A rule you only said in the chat. The brief is a summary written by the parent model. "Never touch legacy/" arrives if the model judged it relevant to that subtask. Anthropic's documentation gives the workaround in one line: "If a rule must, such as "ignore the vendor/ directory," restate it in the prompt you give Claude when delegating." Putting it in the instruction file helps in Claude Code, with the exceptions in the table: Explore and Plan "start without your CLAUDE.md files".
A decision made after the spawn. The brief is a snapshot. Background workers keep running while you keep talking to the parent, and what you decide ten minutes later reaches a running worker only if something sends it there.
What a worker tried and dropped. The summary is the worker's own choice of what matters. A dead end that cost it fifteen minutes is rarely in it, so the parent cannot warn the next worker, and the worker next to it never hears about it at all.
Anything that lives in one checkout or on one machine. A worktree created from the default branch does not contain the instruction-file edit you have not committed. Claude Code's auto memory is one directory per repository on one machine. Codex's memories are local files written in the background, some time after a chat goes idle. A cloud agent runs on a VM with a clone. A teammate's laptop has none of it.
A 20-minute drill
- Open a session in a scratch repository with two small independent tasks, such as two functions in different files, each with a test.
- Before delegating, say three facts in ordinary sentences. Do not write them in any file:
- a rule ("never edit anything under
legacy/"); - a rejected approach and why ("no regex for the bracket parsing, the last one let nested brackets through");
- a number ("that API allows 40 requests per minute").
- a rule ("never edit anything under
- Ask for two subagents, one per task, in the background if your harness allows it. Do not repeat the facts.
- While they run, give the parent a fourth fact: a decision ("the config key is
timeout_msfrom now on, nottimeout"). - When they finish, open each worker's own thread and read the first message it received. In Codex,
/subagentsswitches between agent threads. In Cursor, asubagentStarthook that logs its input shows you thetaskfield. Count how many of the three early facts are in each brief. - Check each worker's output for the fourth fact: did either of them use
timeout_ms? - Ask the parent what the first worker tried and gave up on. Compare the answer with that worker's own thread.
Write the three numbers down: early facts in the brief (out of six), late decision followed (out of two), dead ends the parent can report. Then apply the next section and run it again.
We did not run this drill for this page. The table above is what each vendor's documentation says; the drill is how you find out what your version, your model and your instruction files do with it.
Three places a decision can live
The instruction file, for rules that always hold. It is the cheapest place and the one the vendors point to first. Codex's memory page says it about its own memory feature: "Keep required team guidance in AGENTS.md or checked-in documentation. Treat memories as a helpful recall layer, not as the only source for rules that must always apply." Commit the change before you fan out, because a worktree created from the default branch gets the committed file.
The start of every worker, for the state of this task. Where the harness lets a hook add context to a subagent, a few lines hand each worker the decisions so far, whatever the parent wrote in the brief. In Claude Code, in .claude/settings.json:
{
"hooks": {
"SubagentStart": [
{
"hooks": [
{ "type": "command", "command": "${CLAUDE_PROJECT_DIR}/.claude/hooks/brief.sh" }
]
}
]
}
}#!/bin/sh
# .claude/hooks/brief.sh: hand every subagent the decisions file
jq -n --rawfile d "${CLAUDE_PROJECT_DIR}/.agent/decisions.md" \
'{hookSpecificOutput: {hookEventName: "SubagentStart", additionalContext: $d}}'We ran the jq line on a two-line file and it prints the JSON shape the hooks reference documents. We did not run the hook inside Claude Code. In Codex the same event takes plain text on stdout, so the command can be a cat of the file. In Cursor there is no documented way to add context at this point, so the line has to go in the instruction file: "every delegation includes the contents of .agent/decisions.md".
This covers the first fact and part of the second: a worker started after the decision gets it. A worker already running does not, and nothing has been written back.
A record outside every session and every checkout, for what is decided and found during the run. For the third and fourth facts a worker has to be able to write, and other workers have to be able to read, while everything is still running. A file does that on one machine, if it lives at a path every worktree can reach and every worker is told to read it and append to it. Across machines, cloud agents and teammates it has to be a server. All three harnesses hand the parent's MCP servers to the subagent, so a memory server connected over MCP is already there in the worker.
The same record with ValorBrain
ValorBrain keeps task state in task_state, a ledger on the server. With no session argument, a call writes to the default ledger of the credential and agent making it. A subagent calls through the parent's MCP server entry, with the same token and headers, so parent and workers land in the same default ledger, and so do two unrelated tasks you run in two worktrees with the same token in the same harness. Give each fan-out its own ledger by naming it:
{ "action": "ledger_open", "session": "guide-parallel-agents",
"description": "EN+PT guide on parallel agents (subagents, worktrees). Done = PR open with green CI, reviewed, pages return 200.",
"next": "write both .mdx files and open the PR" }
{ "action": "ledger_checkpoint", "session": "guide-parallel-agents",
"what": "Research closed: what the three vendors document about what a subagent starts with, what it returns, worktrees, harness memory and subagent-start hooks.",
"verified_by": "15 vendor documentation pages downloaded on Nov 29, 2026 (all HTTP 200), 31 quotes checked with grep, and that day's public connect manifests",
"coverage": "documentation and published manifest only; no subagent was run in any of the three harnesses" }
{ "action": "ledger_open_question", "session": "guide-parallel-agents",
"question": "Does a Codex or Cursor subagent load the user-level AGENTS.md when it starts? Neither documentation says.",
"settled_by": "run one subagent in each harness with a rule that exists only in AGENTS.md and read the subagent's first message" }Those are the three calls we made while writing this page (our entries are in Portuguese; translated here). task_state with action: "read" and the same session returned that ledger. The same read without session returned a different one: the ledger of an earlier guide, already closed. The two do not mix.
A worker does not need to know the ledger exists to find it. memory_prepare returns open ledgers along with the relevant memory, two at most, the most recently written first, and each one comes back with a line saying who wrote it. A ledger last written by the same agent always qualifies. One written by another agent comes back when the message passed to memory_prepare names its subject: the ledger's name or words from its goal. That is one more reason to name the ledger after the task. This is from the response we got one minute after opening the ledger (translated, shortened):
### session guide-parallel-agents (as of 2026-11-29)
- goal: EN+PT guide on parallel agents (subagents, worktrees). Done = PR open with green CI, reviewed, pages return 200.
- next: write both .mdx files and open the PR
- origin: last write by lucas 1min ago with this same credential (lucas (persona token)) — an earlier session of yours, most likely on this computer; still verify live state before acting.A ledger written by a different agent arrived in the same response with a different last line:
- origin: claude-code's ledger, last write 1d ago with credential … — ANOTHER AGENT's session, not yours; live state (hosts, services) belongs to whoever wrote it.That label is the part a brief never has. A worker that reads "next: write both files" also reads whose next step it is and how old it is.
The line that makes this work goes in the instruction file, once:
## Parallel work
- Before you start a delegated task, call `memory_prepare` with the task as the message.
- Fan-out state goes in `task_state` with `session: "<task-name>"`: a checkpoint for each verified result, an open question for each thing you could not settle.
- A decision that changes what other workers should do goes in `memory_store` with `type: "decision"`, at the moment you make it.
- A dead end goes in `memory_store` with `type: "lesson"`: what you tried and why it failed.memory_store writes to the caller's own collection, visible to the whole tenant by default, so the worker in the next worktree, the cloud agent and the teammate on another harness can find the decision through memory_prepare or memory_retrieve. A ledger checkpoint takes verified_by and its coverage, and an open question takes settled_by: the two things a worker's summary tends to leave out.
What reaches a subagent automatically, and what does not. @valorbrain/connect installs hooks on SessionStart, UserPromptSubmit and Stop in Claude Code and Codex, and on sessionStart and stop in Cursor. That is what the public manifests listed on November 29, 2026. None of them is a subagent-start hook. The context ValorBrain adds at session start and with each prompt goes to the main conversation, and a subagent is reached two other ways:
- the managed rules block connect writes to the user-level instruction file (
~/.claude/CLAUDE.md,~/.codex/AGENTS.md,~/.cursor/AGENTS.md), which tells the agent to callmemory_prepareormemory_retrievebefore answering from its own assumptions. Claude Code documents that a subagent loads the userCLAUDE.md, Explore and Plan excepted. Codex and Cursor do not say whether a subagent loads theirs, which is the open question in the ledger above; - the MCP tools the subagent inherits from the parent.
Telling work fronts apart. connect's hooks can also send a lane, a label for the work front, in the X-Agent-Lane header when VALORBRAIN_AGENT_LANE is set in the harness's environment (up to 120 characters on the client side). The server keeps it as a slug: lowercase, anything other than letters and digits turned into hyphens, 48 characters at most. Two limits matter for parallel work. The MCP server entry connect writes has no X-Agent-Lane header, so the task_state and memory_store calls above carry a lane only if you add that header to the entry yourself; the hosted server never reads the variable. And a lane belongs to an environment, so a parent and its subagents share one. The connection that wrote this page declares none, so we did not exercise lanes here and do not describe their effect.
What the hooks send is listed in What leaves your machine.
What ValorBrain does not do
- It does not put anything into a subagent when it starts. There is no subagent-start hook in the hosted connect. A subagent reads the ledger and the decisions when its instructions tell it to and it makes the call. Claude Code's Explore and Plan agents load no
CLAUDE.md, so they get the instruction only if the brief carries it. - It does not interrupt a running worker. A decision stored at 14:05 is read by a worker that asks after 14:05. A worker that never asks again finishes with what it had.
- It does not isolate files, merge branches or resolve conflicts. That is git and the harness's worktrees. The ledger records that two workers touched the same module only if one of them wrote it down.
- It does not reach a Cursor cloud subagent through your local configuration. Cloud subagents take their MCP servers from the team configuration, so the server has to be added there.
- It does not write the brief. What the parent tells a worker is still the parent model's summary. The record makes it possible to check the brief against something.
- We did not run a subagent for this page. Everything about harness behavior is what each vendor's documentation said on the date below. The ledger calls are real and came from one credential in one session: we did not have a second credential write to the same named ledger, and we did not measure how often a worker follows the instruction to call
memory_prepare. The drill is how you measure that on your setup.
Checklist
- You read one real brief: the first message a subagent received in your harness.
- Workers that write code each have their own worktree, or commit by path.
- Standing rules are in the instruction file and committed before the fan-out.
- You know which of your subagent types skip the instruction file.
- Each fan-out has one named record outside the session that every worker reads first.
- Decisions and dead ends are written to that record when they happen, with what verified them.
- You ran the drill twice and the late decision reached at least the workers started after it.
Sources, read on November 29, 2026: Claude Code, Run agents in parallel, Subagents, Agent teams, Worktrees, Memory, Hooks reference and Cross-session messaging; Codex, Subagents, Git worktrees, Memories and Hooks; Cursor, Subagents, Worktrees, Cloud agents and Hooks.
Next: Handing work from one coding agent to the next for the note that crosses sessions and harnesses, What survives context compaction for what a long session loses on its own, and CLAUDE.md, AGENTS.md and .cursor/rules in one repo for the rules every worker loads from disk.
What survives context compaction in a long agent session: Claude Code, Codex and Cursor, and a checkpoint that outlives the summary
A long session gets compacted into a summary, sometimes while you are away from the keyboard. What Claude Code, Codex and Cursor document about what comes back, the hooks each one gives you around compaction, a 15-minute drill with five planted facts, and where to keep the state a summary is allowed to lose.
Headless and scheduled agent runs: what a cron or CI agent starts with, and where last night's result has to live
A run with nobody watching starts from what is on that machine: no terminal to ask, often no home directory, no memory of the run before. What Claude Code, Codex and Cursor document about instruction files, MCP servers, approvals, harness memory and sessions in non-interactive and scheduled runs, two small tests we ran, a 15-minute drill and where a nightly job has to keep what it found.