26.5 Isolation with subagents
- Approved by
- Panaversity ·
In everyday life. A lawyer preparing a case sends a clerk to the records room to check one old contract. The clerk reads forty pages there and comes back with one line: the contract ended in March. The lawyer's desk stays clear. But the clerk was not in the morning meeting. If the lawyer wanted the page number too, and said so only in that meeting, the clerk comes back without it. In this section, the lawyer is the worker, the clerk is a subagent, and the note the clerk carries is the only thing that passes between them.
What you will learn. You practice this in Lab 26, Task 5.
- What does a subagent keep out of the worker's window?
- What does a subagent receive, and what does it never receive?
- Where must a rule live so that a subagent follows it?
- What does a subagent cost, and when is one window enough?
Why it matters. Isolation works in both directions. It keeps the lookups out of the worker's window, and it keeps the worker's rules out of the subagent's.
At work. On Monday, May 3, 2027, the rule and the state of the work already have a home, and the run passes its check. Now you move the vendor lookups out. For each invoice the worker hands one vendor id to a subagent. The subagent calls find_vendor, reads the whole result, and answers with the terms alone. The worker's window gains one short line for each vendor. Then you run the same check by code, and read the cost of the run beside the last one.
What does a subagent keep out of the worker's window?
The lookups and everything they returned. The worker starts a second agent for one part of a job (22.7). That second agent is a subagent, and the agent that starts it is the parent. On the Claude Agent SDK, each subagent runs in its own conversation, and "only its final message returns to the parent."1 The exam guide calls this technique subagent isolation: side work is done in a window of its own.
Of the chapter's three kinds, a subagent moves evidence. The tool results arrive in the subagent's window and never in the parent's. Nothing is lost when the subagent ends, because the connector can return every result again. 12.6 used the same idea for coding. Here the worker does it, and nobody directs it.
What does a subagent receive, and what does it never receive?
It receives four things: its own system prompt, the prompt string the parent passes for this one job, the project's instruction file where one is loaded, and its tools. It never receives the parent's system prompt or the parent's conversation. The Claude Agent SDK's documentation gives both lists:1
| The subagent receives | The subagent does not receive |
|---|---|
| "Its own system prompt", and the prompt string the parent passes | "The parent's conversation history or tool results" |
The "Project CLAUDE.md", where the harness is set to load it. An agent that sets omitClaudeMd starts without it | "The parent's system prompt" |
| "Tool definitions", all of the parent's or a smaller set you choose |
"The only content you pass from parent to subagent is the Agent tool's prompt string".1 The Agent tool is the tool the parent calls to start a subagent. So Dave's request, the corrections typed earlier and every decision so far stay behind, unless the parent writes them into that string.
One kind of subagent breaks this table on purpose. A fork is "a subagent that copies the conversation so far instead of starting fresh."1 A fork begins with everything that already fills the parent's window, so it isolates nothing on the way in. When the reason for a subagent was a clean window, a subagent that shares the parent's context is a fault in the design.
Where must a rule live so that a subagent follows it?
In the project's instruction file, or in the subagent's own system prompt. A rule that lives only in the parent's system prompt does not reach it. For the parent, a rule had to leave the conversation and go into the instructions. A subagent cannot see even the parent's instructions.
In this book's lab the worker loads no settings files (settingSources: [], from Lab 22), so no instruction file reaches the subagent. Its own prompt must carry every rule it needs. For the vendor lookup, this is that prompt:
You look up one vendor for Brightline's AP review. Call
find_vendoronce for the vendor id you are given. Answer with the vendor id and its payment terms, word for word as the tool returned them. Give no bank digits and no note. Never pay, approve or change anything.
The last sentence is already in the worker's instructions. It is written again here because the subagent cannot see it there. You also give this subagent one tool, find_vendor, and no other.
Not every rule goes to the subagent. "With the policy line for each" is a rule about the review, which the parent writes, so it stays in the parent's instructions.
The same care applies to what comes back. Suppose a subagent did the policy search, and its prompt did not ask for the line written as (file.md:N). It could answer in its own words, and the worker would have no line to cite. The check by code after the run would fail that invoice, and the trace would show a subagent's answer with no line in it.
What does a subagent cost, and when is one window enough?
It costs tokens and time, and one window is enough when the results are already small. Claude Code's documentation says of subagents: "What they cost you is mostly tokens, since every subagent sends its own requests".2 A fresh subagent also "first has to gather context your conversation already had, so it can end up slower".2 All of it spends from the same $1.00 budget as the review (23.17).
The saving can also be lost again. "Running many subagents that each return detailed results can consume significant context".3 The advice is to "Ask for short summaries back, so twenty results don't fill your context anyway."2 That is why the vendor subagent answers in one line.
So the other choice is fair. When a tool already returns only what the task needs (26.3), a subagent for that tool removes little from the window and still pays for its own requests. One window is also right when the worker needs the details themselves to decide. In Lab 26 you read tokens by part and the run's cost before and after the subagent, so the numbers decide.
The operating rule: give side work its own window, write every rule the subagent needs into its own prompt, and ask for a short answer back.
Do this now. Ask your coding agent to plan one subagent, without building it. Copy this line:
Name one lookup in this project that a subagent could do in its own window. Write the system prompt you would give that subagent, and list every rule from this project's instructions that it would need and could not see. Say what one line it should send back. Change no file.
Check yourself
Question 1 / 8
0 answered
A subagent finishes its vendor lookup. What comes back to the parent?
Sources
- Owner
- Panaversity