CertSafari
    Anthropic Claude Certified Architect – Foundations (CCAR-F)· Lessons

    Domain 1 · Lesson 3/30

    Spawning subagents: Task tool, AgentDefinition, and context passing

    Configure subagent invocation, context passing, and spawning

    18 min read
    3.86% of exam
    6 sources
    Published 20 Oct 2026
    Docs as of 14 Oct 2026

    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.

    A coordinator that can spawn: the spawning tool appears in allowed_tools, and one subagent type is defined under agentspython
            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.

    Spotting a spawn in the stream: a tool_use block named Task (older SDKs) or Agent (current), with the chosen subagent_type in its inputtypescript
      // 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"],
                    )
                },
            ),

    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.

    The AgentDefinition fields that shape delegation, behaviour and capability
    FieldRequiredWhat it controls
    descriptionYesWhen the coordinator should delegate to this agent
    promptYesThe subagent's system prompt: its role, expertise and constraints
    toolsNoThe allowed tool list; if omitted, the subagent inherits every tool available to subagents
    disallowedToolsNoTools removed from the agent's tool set
    modelNoModel override, such as 'sonnet', 'haiku' or 'inherit'
    maxTurnsNoMaximum 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?

    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?

    Sources21

    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?

    Sources13

    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.

    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?

    Sources14

    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
    The same delegation written as a script and as a goal with criteria
    Procedural scriptGoal and quality criteria
    Search for 'chip shortage 2025', read the first five results, summarise eachObjective: 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 notesOutput: 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?

    Sources31

    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?

    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?

    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?

    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?

    Sources516

    Sources

    (6)

    Every claim above is drawn from one of these pages, quoted as it was written on the date shown.

    1. 1.
      “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. 2.
      “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. 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. 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. 5.
      “When resuming with resume, fork to a new session ID instead of continuing the original session”
      ↩︎ Forking instead of spawning
    6. 6.
      “Try an alternative approach without losing the original”
      ↩︎ Forking instead of spawning
      “Try an alternative approach without losing the original | Fork the session.”
      ↩︎ Checkpoint

    Ready to test yourself?

    Practise the 16 questions on this subdomain.

    Spotted a mistake, or was something unclear? Tell us.