Topic 5 of 5 · 5 min read
Subagents that isolate noisy context
Goal: Decide which parts of a task to hand to a subagent so the main context stays small, and judge the summary it returns.
Give noisy work to a subagent so its reading, searching and failed attempts stay in its own context, and only the answer comes back. The main session keeps room for decisions.
Check yourself · 1 of 3
What is the main context benefit of using a subagent?
Why it matters
Exploring a codebase, reading many files, scanning logs or trying several searches fills the window with material that is useful only once. If the main agent does it, all of it stays in the history. A subagent runs in a separate context window with its own tools and instructions, does the digging, and returns a final message. Claude Code's subagent docs describe this isolation, and other tools offer similar delegation. The main context grows by a short report instead of by every file read.
What to hand off
Good candidates have a large input and a small answer:
- "Find where retry logic is implemented and list the files."
- "Read these forty test failures and group them by cause."
- "Check the docs for the rate limit and quote the rule."
Poor candidates need the main session's full history, or are small enough that a delegation costs more than doing it.
How to write the handoff
- State the question and the form of the answer ("return at most ten lines: file, function, one-line reason").
- Give the subagent only the tools it needs. Fewer tools also mean a smaller standing cost.
- Include paths, names and constraints it cannot see. It does not share your history.
- Ask for evidence (file paths, line numbers, quotes) so you can verify.
How to judge what comes back
A subagent's report is a summary, and summaries can drop or invent details. Spot-check two or three claims against the source. Check that it answered the question asked and says what it did not find. If it says "no issues", ask what it examined.
Before and after
Before: main agent reads 40 files looking for the cause; history is full when the fix starts.
After: subagent "find-cause" reads the files and returns:
"Cause: cache key omits tenant id, src/cache/key.ts:22. Checked: src/cache, src/api.
Not checked: background jobs."
Main agent opens one file and fixes it.
What goes wrong
- Vague handoffs that return an essay as long as the material.
- Trusting the summary without any check.
- Delegating tiny tasks where setup costs more than the saving.
- Passing no context, so the subagent answers a different question.
Examples
A tight handoff
Task: find every place that reads the PAYMENT_TIMEOUT env var.
Search only under src/ and config/.
Return: a list of file:line with one phrase each, max 15 lines.
Also list directories you did not search.
The answer is short, checkable and states its limits.
A summary that needs checking
A subagent reports: "No uses of the deprecated client remain." You open the search it ran and see it covered src/ but not scripts/. A second search finds two uses. The report was fluent and incomplete, which is why you ask what was examined.
Key points
- A subagent works in its own context window, so its reading and failed attempts do not fill the main session.
- Delegate tasks with large inputs and small answers, such as searching, log reading and grouping failures.
- The handoff must state the question, the answer format, the paths and constraints, and the tools allowed.
- Ask the subagent for evidence and for what it did not check, then verify a few claims yourself.
- Do not delegate tiny tasks or tasks that need the full conversation history.
Common mistakes
- Handing off with a one-line request and no answer format, then receiving a long report.
- Accepting "all clear" from a subagent without seeing what it covered.
- Giving the subagent every tool, which adds cost and risk it does not need.
- Delegating a five-line task and paying the setup cost for nothing.
Check yourself · 2 of 3
Which task is the best fit for a subagent?
Check yourself · 3 of 3
A subagent reports "no uses of the old API remain." What is the best next step?
Practice items, not counted towards your mastery.
Start here
- Introducing advanced tool use (Anthropic) (opens in a new tab)ArticleFree
Shows tool search, programmatic tool calling and tool-use examples, with Anthropic's own measurements of context saved.
- Code execution with MCP (Anthropic) (opens in a new tab)ArticleFree
Explains why many MCP tool definitions and large intermediate results waste context, and the code-execution fix.
- Tool search tool (Claude docs) (opens in a new tab)DocsFree
The API reference for deferring tool definitions and loading them on demand.
More for this topic
- Create custom subagents (Claude Code docs) (opens in a new tab)DocsFree
How a subagent runs in its own context window and returns only a result to the main session.