Topic 1 of 5 · 4 min read
When a subagent beats one long session
Goal: Decide for a given coding task whether to use one session, one subagent or several, and name the context or speed gain that justifies it.
Use a subagent when a piece of work would flood your main session with text you will never need again, or when several independent pieces can run at the same time. Otherwise stay in one session.
Check yourself · 1 of 3
What is the main context benefit of delegating a broad code search to a subagent?
Why it matters
A coding agent works inside one context window. Every file it reads, every grep result and every failed attempt stays in that window and competes for attention with your actual task. After a long search the useful facts are a few lines, but the context holds thousands. A subagent is a separate agent run, started by the parent, with its own empty context. It does the noisy work and returns a short report. The parent keeps only the report.
Three real gains
- Isolation of noise. "Find every place we parse the session cookie" may read 40 files. A subagent reads them; your session receives a list of 6 paths with one line each.
- Parallel breadth. Reviewing four independent packages is four jobs that do not need each other. Four subagents finish in about the time of one.
- Fresh eyes. A reviewer that did not write the code has not absorbed the author's assumptions. It judges the diff, not the intent it remembers.
The price
Anthropic reports that multi-agent systems used about 15 times more tokens than chats, and that this only pays off when the task is valuable enough. Each subagent also starts knowing nothing: it does not see your conversation, your decisions or your half-formed plan. Anything it needs must be written into its brief, and the parent only gets back what the report says.
A quick decision rule
- The task needs the whole conversation to make sense (a design discussion, a tricky refactor): one session.
- The task is a lookup or a read-heavy check with a short answer: one subagent.
- The task splits into parts that touch different files and can be judged separately: several subagents, with the parent merging.
Before and after
Weak: "Check how auth works, fix the login bug, update the docs and review it, all in this session." By the end, context is full of unrelated files and the review is done by the same session that wrote the fix.
Better: one explore subagent maps the auth flow and returns a half-page summary. The parent fixes the bug in its own session. A separate review subagent reads only the diff and the ticket.
What goes wrong
- Delegating small work. If the answer is one file read, a subagent costs more than it saves.
- Delegating the thinking. A subagent cannot make a decision that depends on context it was never given.
- Parallelising things that depend on each other. Two workers editing the same module will collide.
Examples
Three options for one ticket
Ticket: "Rename userId to accountId across the API."
- One session: fine for a single package with 10 call sites.
- One explore subagent: right when you first need a map of all 200 call sites and only want the list back.
- Several workers: right once the map shows 5 packages with no shared files. Each worker owns one package.
Noise stays out
The parent asks an explore subagent where rate limits are configured. The subagent reads 30 files and returns: "Two places: config/limits.ts:12 sets defaults, middleware/throttle.ts:44 applies them. Per-route overrides are in routes/billing.ts." The parent's context grew by 40 words, not 30 files.
Key points
- A subagent has its own empty context, so noisy searches and file reads stay out of the parent session.
- Independent areas can run in parallel; dependent steps cannot.
- Multi-agent runs cost far more tokens, so they must be justified by value or speed.
- A subagent knows only what its brief says, never the parent conversation.
- A reviewer that did not write the code gives a fresher judgment than the author's own session.
Common mistakes
- Spawning a subagent for a one-file lookup that costs more to brief than to do.
- Expecting a subagent to remember decisions made earlier in the parent conversation.
- Running subagents in parallel on work that edits the same files.
- Using the author's own session to review its own change and calling that a second opinion.
Check yourself · 2 of 3
You must check how three unrelated packages each handle retries, then summarise. The packages share no files. What is the best approach?
Check yourself · 3 of 3
A design decision depends on a long discussion you had with the agent earlier. Should you hand it to a subagent?
Practice items, not counted towards your mastery.
Start here
- Create custom subagents (Claude Code docs) (opens in a new tab)DocsFree
How a subagent file sets its description, tools and model, and how the parent delegates to it.
- How we built our multi-agent research system (Anthropic) (opens in a new tab)ArticleFree
Reports the gain from parallel subagents and the roughly 15x token cost, plus lessons on briefs and effort.
- Custom agents in VS Code (opens in a new tab)DocsFree
The same idea in another tool: a custom agent with its own instructions and tool list.