What you will be able to do
- Configure a coordinator that can spawn subagents through the Task tool, and recognise the spawn in the message stream
- Write an AgentDefinition whose description, system prompt and tools field each do their own job
- Build spawn prompts that carry complete prior findings, with content kept separate from source metadata
- Fan out parallel subagents from a single coordinator response, and write delegation prompts as goals and quality criteria
- Choose between spawning a fresh subagent and forking a session that keeps the shared analysis
Key concept
Subagent context isolation — A spawned subagent begins in a new, empty conversation. It sees its own system prompt and the prompt the coordinator wrote for it, never the coordinator's history, and only its final message goes back. So anything the subagent needs has to be written into the spawn.
1.Spawning subagents with the Task tool
A coordinator delegates by making a tool call. To spawn a subagent, it emits a Task tool call that names the subagent type and carries a prompt for that run. The subagent then works in its own conversation, and its final message comes back to the coordinator as the tool result. Current SDK versions emit this same tool under the name Agent, which is why the official samples list "Agent" rather than "Task".
The coordinator can only spawn if the tool is available to it. List the Task tool in the coordinator's allowedTools, then define the subagent types under the agents option. A coordinator with a carefully written set of agents but no Task tool in allowedTools cannot call any of them. There is also a built-in general-purpose subagent that Claude can call without any definition from you.
options=ClaudeAgentOptions(
allowed_tools=["Read", "Glob", "Grep", "Agent"],
agents={
"code-reviewer": AgentDefinition(
description="Expert code reviewer.",
prompt="Analyze code quality and suggest improvements.",
tools=["Read", "Glob", "Grep"],
)
},
),When several subagent types are defined, the coordinator picks one by reading their descriptions. This is the same mechanism as Tool descriptions as the selection mechanism: a description that says when to use the agent and what kind of request it covers attracts the right delegations, and a vague one gets ignored. You can skip that matching by naming the agent in the prompt, as in "Use the code-reviewer agent to review this codebase". Even then, Claude still decides whether to make the Task call.
// Check for subagent invocation. Match both names: older SDK versions
// emitted "Task", current versions emit "Agent".
for (const block of msg.message?.content ?? []) {
if (block.type === "tool_use" && (block.name === "Task" || block.name === "Agent")) {
console.log(`Subagent invoked: ${block.input.subagent_type}`);
}
}Checkpoint 1 of 10· Fill the gap
This coordinator defines a code-reviewer subagent. Which tool name must go in the blank so the coordinator can actually spawn it?
options=ClaudeAgentOptions(
allowed_tools=["Read", "Glob", "Grep", " ? "],
agents={
"code-reviewer": AgentDefinition(
description="Expert code reviewer.",
prompt="Analyze code quality and suggest improvements.",
tools=["Read", "Glob", "Grep"],
)
},
),A coordinator spawns a subagent by calling the Task tool, which current SDKs name Agent, so that tool has to be in allowed_tools. Defining agents under agents is not enough without it, and you don't list a subagent's name such as code-reviewer as a tool.
Sources1
2.Configuring each subagent type with AgentDefinition
Each subagent type is one AgentDefinition, and its fields each do a separate job. Two are required: description, which the coordinator reads when deciding whether to delegate, and prompt, which becomes the subagent's system prompt. The optional fields set what the subagent can do and how it runs.
| Field | Required | What it controls |
|---|---|---|
| description | Yes | When the coordinator should delegate to this agent |
| prompt | Yes | The subagent's system prompt: its role, expertise and constraints |
| tools | No | The allowed tool list; if omitted, the subagent inherits every tool available to subagents |
| disallowedTools | No | Tools removed from the agent's tool set |
| model | No | Model override, such as 'sonnet', 'haiku' or 'inherit' |
| maxTurns | No | Maximum agentic turns before the agent stops and returns partial output |
A subagent receives two prompts, and both reach its model. The definition's prompt is the persistent system prompt, and every run of that type gets it. Take a database-migration agent: its definition can hold detailed guidance on SQL practice, rollback strategy and data-integrity checks, guidance that would only clutter the coordinator's own instructions. The prompt the coordinator writes in each Task call is the task for that one run, such as which table to migrate and what has to change. The expertise stays fixed while the task changes from call to call.
Tool restriction goes in the tools field of the subagent's own definition. That field is where Scoped tool access per agent is actually configured. A doc-reviewer defined with tools: ["Read", "Grep"] can read and search, and it has no Edit or Write tool to call, whatever the coordinator holds. The tempting alternatives fail in different ways. A prompt line saying "never edit files" is only an instruction the model may not follow. A description saying the agent is read-only influences which agent gets picked, not what that agent can do. Narrowing the coordinator's own allowedTools doesn't scope the subagent, and it would also take away the Task tool the coordinator needs to spawn anything. Leaving tools unset is the riskiest choice, because the subagent then inherits everything.
Checkpoint 2 of 10· Check yourself
Your team adds a doc-reviewer subagent that must be able to read and search documentation but must never change it. Which configuration actually guarantees that?
The tools field in the subagent's own definition decides which tools it can call, so with only Read and Grep it has no Edit or Write tool. A prompt line is only an instruction the model might not follow. A description only affects which agent the coordinator picks. Narrowing the coordinator's allowedTools doesn't scope the subagent. And if tools is left unset, the subagent inherits every tool available to subagents.
“A doc-reviewer subagent might only have access to Read and Grep tools, ensuring it can analyze but never accidentally modify your documentation files.”Source: code.claude.com
Sources1
3.Subagents start with no parent context
A spawned subagent inherits none of the coordinator's conversation. It starts fresh: it loads its own system prompt and project-level context such as CLAUDE.md, and it does not see the parent's turns. What the coordinator has read, decided or been told by other subagents stays with the coordinator. The prompt string in the Task call is the only way any of that reaches the subagent.
There is no memory across invocations either. A second spawn of the same subagent type is a new conversation and knows nothing about the first run. The earlier transcript can be reached only by resuming that specific agent by its ID within the same session, which is a deliberate step and not a default.
For the synthesis subagent above, the fix is in the prompt text. Paste the researcher's complete notes and source details into it. The other likely fixes miss the cause. More maxTurns gives the subagent more time with nothing to work on. A larger model cannot recover facts that are not in its context. Search tools would make it redo the research and produce its own findings instead of the ones already gathered. The isolation itself is a feature: intermediate tool calls stay inside each subagent, so the coordinator's context grows only by the final summaries. The cost is that the coordinator has to hand over context explicitly.
Checkpoint 3 of 10· Check yourself
After a web-researcher subagent finishes, a coordinator spawns a synthesis subagent. The synthesis subagent's report comes back generic and cites none of the sources the researcher found. What change actually fixes this?
A subagent starts in a fresh conversation and never sees the coordinator's turns, so the research reaches it only if the coordinator writes it into the spawn prompt. More turns or a bigger model can't recover facts that aren't in its context, and search tools would just redo the research instead of using the findings already gathered.
“It does not see the parent’s turns, and only its final response returns to the parent.”Source: code.claude.com
4.Passing complete findings with attribution intact
When one subagent's output feeds another, pass the complete findings, not a pointer to them. In a research pipeline, the web-search results and the document-analysis output both go into the synthesis subagent's prompt, in full. A coordinator that paraphrases them into a sentence or two has already decided what the synthesis can say. Each hop also compresses: a subagent returns a concise summary of what it read, not the material itself, so anything dropped at one handoff is gone for every agent after it.
Source metadata gets lost first when findings are written up as prose. A sentence like "studies show adoption doubled" no longer says which study, which URL or which page. Pass findings as structured records instead, with the claim's content in one field and its metadata in separate fields:
- the source URL
- the document name
- the page number or location
With that structure, the synthesis subagent can quote the content and attach the source to every claim it carries forward, and the Claim-source mappings survive the handoff. Anthropic's research system ends with exactly this kind of step: it passes all findings to a dedicated citation agent so each claim in the report is attributed to its source.
Very large outputs can go by reference instead. A subagent can store its work in an external system and hand the coordinator a lightweight reference, so a long report or dataset doesn't have to be copied through every agent's conversation.
Checkpoint 4 of 10· Check yourself
In a research pipeline, the coordinator hands the synthesis subagent its findings as smooth prose such as "studies show adoption doubled". The final report makes the right claims but can't say which URL, document or page any claim came from. Which handoff format fixes this?
Source metadata is the first thing lost when findings become prose, and a later agent can't cite a URL or page that never reached its context. Structured records keep the content apart from its source fields, so every claim can carry its source through the handoff and on to a final citation step. A "cite your sources" instruction has nothing to cite, and shortening the findings drops even more of them.
“passes all findings to a CitationAgent, which processes the documents and research report to identify specific locations for citations”Source: www.anthropic.com
5.Parallel spawning in a single coordinator response
Subagents run concurrently when the coordinator spawns them together. Independent subtasks then take about as long as the slowest one, not the sum of all of them. A code review that needs a style-checker, a security-scanner and a test-coverage subagent can run all three at the same time.
Getting that concurrency depends on how the coordinator emits the calls. Claude can return several tool_use blocks in one response, so the coordinator puts one Task call per subagent into the same turn. If it spawns one subagent per turn, each result has to come back before the next spawn is requested, and three ten-minute reviews take thirty minutes instead of ten. Spread across separate turns, the calls run one after another.
The three research spawns are independent, so they go out as three Task calls in a single response. The comparison depends on all three results, so it is a later spawn whose prompt carries the full findings from each researcher.
Checkpoint 5 of 10· Check yourself
Style-checker, security-scanner and test-coverage reviews are independent of each other, and each takes about ten minutes. Which coordinator behaviour gets all three results back in roughly ten minutes instead of thirty?
Subagents run at the same time only when the coordinator issues their Task calls together in a single response, so the total time is about that of the slowest review. Spawning one per turn makes each spawn wait for the previous result, so the times add up. maxTurns caps how long a subagent runs and doesn't make spawns concurrent. One subagent doing all three reviews does them one after another.
“multiple subagents can run concurrently, so independent subtasks finish in the time of the slowest one rather than the sum of all of them”Source: code.claude.com
6.Delegation prompts that state goals and quality criteria
Delegation prompts should say what to achieve and how good the result must be, not which steps to take. Research is path-dependent: what the subagent finds on its first search changes what it should look at next, so a fixed path for exploring a complex topic can't be written in advance. A step-by-step script ("search X, open the top three results, extract Y") fails the first time the results look different from what the script expected.
Goal-and-criteria prompts are not vague, though. Anthropic's research system first let its lead agent delegate with short instructions like "research the semiconductor shortage". Subagents misread the task and ran the same searches as each other: one studied the 2021 automotive chip crisis while two others duplicated work on 2025 supply chains. Every delegation needs four parts:
- an objective
- an output format
- guidance on the tools and sources to use
- clear task boundaries
| Procedural script | Goal and quality criteria |
|---|---|
| Search for 'chip shortage 2025', read the first five results, summarise each | Objective: explain current supply constraints for automotive chips |
| Then search for 'chip prices' | Boundaries: 2025 supply chains only; the 2021 crisis is covered by another subagent |
| Return your notes | Output: findings as records with source URL and document name; flag claims backed by only one source |
The output criteria matter most because only the subagent's final message comes back to the coordinator. The coordinator gets nothing from the subagent's intermediate work, so the delegation prompt has to say what that one message must contain. The subagent chooses its own route; the criteria decide whether what it returns can be used.
Checkpoint 6 of 10· Check yourself
A coordinator delegates market research with a script: "Search 'chip shortage 2025', open the top five results, summarise each, then search 'chip prices'." Subagents keep returning unusable notes whenever the search results don't look the way the script expected. How should the delegation prompt be rewritten?
Research is path-dependent: what the first search turns up changes what to look at next, so no fixed script can be written in advance. A goal-and-criteria prompt still has to be specific, though. Without boundaries and an output format, subagents misread the task and repeat each other's searches. And since only the final message comes back, the criteria decide whether the result can be used.
“You can’t hardcode a fixed path for exploring complex topics, as the process is inherently dynamic and path-dependent.”Source: www.anthropic.com
7.Forking instead of spawning
A Task spawn always starts from an empty context, which is wrong for one kind of work: exploring alternatives that all depend on a long shared analysis. A fork_session branches a session into a new session ID and leaves the original intact. The branch keeps everything analysed so far, and you don't have to fit it into a spawn prompt. A subagent can also run as a fork, and then it starts from the parent's conversation instead of from nothing.
Which to choose depends on what the new work needs. Fork when each branch needs the whole baseline: two refactoring strategies tried from the same hour of codebase analysis, for example. Spawn a fresh subagent when the task is self-contained and fits in a prompt, because a clean context keeps the subagent focused and keeps its intermediate work out of the parent's context.
Checkpoint 7 of 10· Check yourself
After an hour of codebase analysis, a coordinator wants to try two competing refactoring strategies. Both strategies depend on everything that analysis found. What is the best way to set this up?
A fork branches the session into a new session ID and keeps everything analysed so far, while the original stays untouched. That fits alternatives that need the whole baseline. A fresh spawn starts from an empty context, so "the analysis so far" means nothing to it, and sending spawns in parallel doesn't change that. Working through both strategies in one session lets strategy A's changes affect B's starting point.
“Try an alternative approach without losing the original | Fork the session.”Source: code.claude.com
Checkpoint 8 of 10· Exam question
A team is building a "doc-reviewer" subagent that should be able to read and comment on documentation but must never be able to modify files, even accidentally. The coordinator itself has Read, Edit, Write, Grep, and Glob available. How should the doc-reviewer's AgentDefinition be configured to guarantee this constraint?
Correct answer: A — Set tools to ["Read", "Grep"] on the doc-reviewer definition so it inherits only the listed read tools regardless of what the coordinator has available
- A. Correct. The tools field on an AgentDefinition is an explicit allowlist; specifying only Read and Grep guarantees the subagent has no access to Edit or Write, independent of what the coordinator or parent session can do.
- B. Incorrect. Leaving tools unset means the subagent inherits all available tools; a prompt instruction is only a suggestion the model could still deviate from, not an enforced restriction.
- C. Incorrect. Restricting the coordinator's own tools would also block the coordinator's other legitimate work and is unrelated to constraining what a specific subagent can do.
- D. Incorrect. The description field only affects when Claude chooses to invoke the subagent; it does not restrict which tools the subagent can actually call once running.
Checkpoint 9 of 10· Exam question
An architect is defining a "database-migration" AgentDefinition with a long prompt field describing SQL best practices, rollback strategy, and data integrity checks. Separately, each time the coordinator invokes this subagent it supplies a different per-call prompt describing the specific table and migration at hand. What is the correct relationship between these two prompt sources?
Correct answer: A — AgentDefinition.prompt sets the subagent's persistent system prompt and expertise, while the per-call prompt passed at invocation supplies the specific task details for that run
- A. Correct. AgentDefinition.prompt defines the subagent's standing role, expertise, and constraints as its system prompt, while the prompt string passed at each invocation carries the specific task and data for that particular run; both reach the subagent together.
- B. Incorrect. AgentDefinition.prompt is not discarded; it continues to shape the subagent's behavior as its system prompt on every invocation, alongside the per-call prompt.
- C. Incorrect. The per-call prompt is delivered to the subagent being invoked, not folded into the coordinator's own system prompt.
- D. Incorrect. There is no truncation-to-the-shorter-prompt behavior; both the definition's system prompt and the invocation prompt are used in full.
Checkpoint 10 of 10· Exam question
A coordinator runs a "web-researcher" subagent that gathers ten sources on a topic, then spawns a "synthesis" subagent to write the final report. The synthesis subagent's output ignores nearly all of the researcher's findings and instead re-derives generic conclusions from scratch. The coordinator's prompt to synthesis only said "Write a report based on the research that was just completed." What change fixes this?
Correct answer: A — Paste the web-researcher's full notes and source details into the synthesis subagent's prompt text, so it can write the report from that material
- A. Correct. A subagent starts with a fresh context window, and the prompt string is the only channel from the coordinator. The researcher's notes and sources reach the synthesis subagent only if they are written into that prompt.
- B. Incorrect. maxTurns only caps how many turns the subagent can take. The synthesis subagent still has no research material, so extra turns give it more room to produce the same generic conclusions.
- C. Incorrect. A larger model gets the same short prompt and an empty context. The researcher's findings are not in either, so no model can recover them from the wording of the instruction.
- D. Incorrect. Fresh searches would produce a different set of results and would not carry over the ten sources and findings the researcher already gathered. The completed research would still be ignored and the work duplicated.
Sources
(6)
Every claim above is drawn from one of these pages, quoted as it was written on the date shown.
- 1.https://code.claude.com/docs/en/agent-sdk/subagentsOfficial docs
“Claude can invoke the built-in general-purpose subagent at any time via the Agent tool without you defining anything”
↩︎ Spawning subagents with the Task tool“description tells Claude when to use this subagent”
↩︎ Spawning subagents with the Task tool“The agent’s system prompt defining its role and behavior”
↩︎ Configuring each subagent type with AgentDefinition“ensuring it can analyze but never accidentally modify your documentation files”
↩︎ Configuring each subagent type with AgentDefinition“If omitted, inherits every tool available to subagents”
↩︎ Configuring each subagent type with AgentDefinition“you must resume the same session to access the subagent’s transcript”
↩︎ Subagents start with no parent context“The parent receives a concise summary, not every file the subagent read.”
↩︎ Passing complete findings with attribution intact“independent subtasks finish in the time of the slowest one rather than the sum of all of them”
↩︎ Parallel spawning in a single coordinator response“only its final message returns to the parent”
↩︎ Delegation prompts that state goals and quality criteria“which starts fresh unless the subagent is a fork”
↩︎ Forking instead of spawning“each subagent runs in its own conversation, which starts fresh unless the subagent is a fork”
↩︎ Key concept“If omitted, inherits every tool available to subagents”
↩︎ Exam trap 1“A doc-reviewer subagent might only have access to Read and Grep tools, ensuring it can analyze but never accidentally modify your documentation files.”
↩︎ Checkpoint“multiple subagents can run concurrently, so independent subtasks finish in the time of the slowest one rather than the sum of all of them”
↩︎ Checkpoint - 2.https://code.claude.com/docs/en/agent-sdk/agent-loopOfficial docs
“It does not see the parent’s turns, and only its final response returns to the parent.”
↩︎ Subagents start with no parent context“It does not see the parent’s turns, and only its final response returns to the parent.”
↩︎ Exam trap 2“Each subagent starts with a fresh conversation (no prior message history”
↩︎ Prediction - 3.
“passes all findings to a CitationAgent, which processes the documents and research report to identify specific locations for citations”
↩︎ Passing complete findings with attribution intact“Subagents call tools to store their work in external systems, then pass lightweight references back to the coordinator.”
↩︎ Passing complete findings with attribution intact“You can’t hardcode a fixed path for exploring complex topics”
↩︎ Delegation prompts that state goals and quality criteria“Each subagent needs an objective, an output format, guidance on the tools and sources to use, and clear task boundaries.”
↩︎ Delegation prompts that state goals and quality criteria“Each subagent needs an objective, an output format, guidance on the tools and sources to use, and clear task boundaries.”
↩︎ Exam trap 4“You can’t hardcode a fixed path for exploring complex topics, as the process is inherently dynamic and path-dependent.”
↩︎ Checkpoint - 4.
“When Claude has multiple independent tool calls to make, it might return several tool_use blocks in a single response.”
↩︎ Parallel spawning in a single coordinator response“When Claude has multiple independent tool calls to make, it might return several tool_use blocks in a single response.”
↩︎ Exam trap 3 - 5.https://code.claude.com/docs/en/agent-sdk/typescriptOfficial docs
“When resuming with resume, fork to a new session ID instead of continuing the original session”
↩︎ Forking instead of spawning - 6.https://code.claude.com/docs/en/agent-sdk/sessionsOfficial docs
“Try an alternative approach without losing the original”
↩︎ Forking instead of spawning“Try an alternative approach without losing the original | Fork the session.”
↩︎ Checkpoint