Subagent Invocation and Context Passing
What a subagent receives
A normal (non-fork) subagent starts with a fresh context. It gets:
- its own system prompt (
AgentDefinition.prompt) plus the Agent tool'spromptstring - project CLAUDE.md (unless
omitClaudeMdis set) - tool definitions (inherited, or the subset in
tools)
It does not get the parent's conversation history, the parent's tool results, the parent's system prompt, or skills unless listed in skills.
> The only content you pass from parent to subagent is the Agent tool's prompt string. Include file paths, error messages and decisions it needs directly in that prompt.
Defining a subagent
AgentDefinition fields: description (required; tells Claude when to use it), prompt (required), tools, disallowedTools, model, skills, memory, mcpServers, maxTurns, background, effort, permissionMode.
- Omit
toolsand it inherits every tool available to subagents. List tools and it gets only those; an omitted tool is simply absent, with no error. - The
Agenttool must be available to the parent (include"Agent"inallowedTools) for delegation to work. - Invocation: automatic (Claude matches the task to
description, so write clear, specific descriptions) or explicit (name the subagent in the prompt). - Programmatic
agentsoverride filesystem agents (.claude/agents/) with the same name.
What comes back
Only the subagent's final message, and the parent may summarise it. To keep it verbatim in the user-facing answer, say so in the instruction you give the main agent.
Practical rules (design guidance built on the above)
- Pass facts, not references to conversation ("as discussed above" means nothing to a subagent).
- Pass structured context with sources attached so the coordinator can keep provenance.
- Give each subagent the narrowest tool set that does its job.
- Cap work with
maxTurns; a subagent that hits it returns output marked partial and can be resumed.
Exam traps
- Assuming the subagent inherits the conversation. It does not (except a fork).
- Forgetting
"Agent"inallowedTools, so delegation never happens. - Vague
description, so Claude never picks the subagent. - Giving every subagent every tool.
- Detecting delegation only by
"Task". Current SDKs emit"Agent"intool_useblocks (the init tools list still saysTask); match both.
References
- Subagents in the SDK — checked Oct 16, 2026
Check your understanding
A subagent must fix "the bug we just found". Why might it fail?Show answerHide answer
Answer
It never saw the conversation; the prompt must contain the file, error and context.How do you make a subagent read-only?Show answerHide answer
Answer
tools: ["Read", "Grep", "Glob"].Claude is answering directly instead of delegating. Two fixes?Show answerHide answer
Answer
Name the subagent in the prompt; write a clearerdescription.