← ~/pillars / multi-agent-orchestration / context-isolation-and-handoff
Context isolation and handoff
What to pass and withhold in a dispatch prompt, and the three-tier hierarchy for work that outlives one context window: compaction, handoff documents, budgets.
updated 2026-09-07 ~5 min read pattern 03/06 Architecture & Orchestration
on this page
Context. Every orchestration pattern in this pillar rests on the same mechanics: workers get fresh context windows and do not inherit the dispatcher’s conversation history, and long-running work outlives any single window. State has to move deliberately: in dispatch prompts going out, and in handoff documents coming back.
Forces. Context is the binding constraint: the window fills fast and performance degrades as it fills (best practices). The context engineering post names the failure “context rot”, attention stretching thin as tokens accumulate (context engineering). Pass too much in a dispatch and you pay tokens and import anchoring bias; pass too little and the worker guesses. Compaction preserves continuity but is lossy. And the filesystem, the one thing all agents share, is both the communication channel and the conflict surface.
Resolution. Treat the dispatch prompt as the only channel for parent intent and curate it; treat the filesystem as the durable state store; and manage long work with a three-tier hierarchy: compaction within a session, handoff documents across sessions, budgets around the whole loop.
What is isolated, what is shared
Isolated by default, and no longer unconditionally: the context window.
A named subagent runs in its own window and the main session’s history does
not carry over. The exception is the built-in fork type, which “inherits
the entire conversation so far instead of starting fresh”: the same system
prompt, tools, model, and message history as the parent, with only its final
result coming back. Fork mode is on by default in interactive sessions,
so an unqualified “do this in a subagent” can now produce a worker that has
read everything you have
(subagents). Definitions in
.claude/agents/ are not run as forks, which makes naming the agent the way
you keep isolation rather than assume it. Mind the asymmetry while you are
at it: fork mode is off in non-interactive -p runs and in the Agent SDK
unless you turn it on, so the same instruction can isolate in CI and not at
your terminal. Agent teammates
load project context (CLAUDE.md, MCP servers, skills) like any session, but
“the lead’s conversation history does not carry over”
(agent teams). Two built-in
exceptions to project-context loading: the Explore and Plan subagents
skip CLAUDE.md and the parent’s git status to stay fast and cheap.
Shared: the filesystem (one working directory: the communication channel, and the place where two writers collide) and permissions (teammates start with the lead’s settings; subagents inherit the parent conversation’s permissions, with extra tool restrictions).
Dispatch prompt anatomy
Pass four things (agent teams):
- The task spec, inline, with specific file paths.
- Scope boundaries: what not to touch.
- Constraints from the parent conversation that are not in CLAUDE.md.
- The expected output format, so reports are comparable across workers.
Withhold three things: the full conversation history (token cost plus anchoring bias), other workers’ intermediate reasoning, and your own deliberation about the decomposition. Prefer just-in-time retrieval over pre-loading: hand the worker lightweight identifiers (file paths, class names) and let it read what it needs (context engineering). The return path mirrors this: workers send back condensed summaries, not full exploration traces.
The three-tier hierarchy for long work
Tier 1: compaction, within a session. Approaching the limit, Claude Code
clears older tool outputs first, then summarises the conversation; your
requests and key code snippets are preserved, but detailed early instructions
may be lost (how Claude Code works).
Steer it rather than accept the default: /compact Focus on the API changes
for a directed manual pass, or a “Compact Instructions” section in CLAUDE.md
(“when compacting, always preserve the full list of modified files and any
test commands”). If one huge file or output refills the window immediately
after each summary, Claude Code stops auto-compacting after a few attempts
and errors instead of looping.
Tier 2: handoff documents, across sessions. Compaction preserves context
within a session; a filesystem handoff document preserves state across
sessions and into dispatches. The documented pattern is structured
note-taking: external memory files like NOTES.md that persist outside the
context window, “enabling coherence across context resets”
(context engineering).
Before compaction bites or before dispatching, write down: architectural
decisions made, unresolved issues, what was done and what remains, and the
file paths touched. The next context reads the document, not a degraded
summary.
Tier 3: budgets, around the loop. Bound what a dispatched loop may spend by setting a model-visible task budget: a countdown the model sees and self-moderates against, unlike a per-response token ceiling it is unaware of. Lower effort levels suit simple subagent tasks. Availability and exact syntax are version-sensitive: verify against current platform docs before relying on them.
Failure modes
Context pollution. A session accumulates residue from previous tasks and
performance degrades: earlier instructions get ignored under the noise. The
documented tripwire: corrected Claude more than twice on the same issue in
one session? The context is cluttered with failed approaches. /clear and
start fresh (best practices).
Prevention is the subagent pattern itself: noisy exploration happens in a
disposable window, and only the summary enters yours.
Review theatre. Handoff back into the same context that implemented the work produces review in name only: the model is biased toward code it just wrote. Review must land in a fresh context that sees only the diff and the criteria, and a fork is not one: dispatch reviewers by name, not by asking for “a subagent”. The mechanism and calibration are in verification topologies.
Conflicting writes to shared state. Handoff files are subject to the same
last-write-wins hazard as code: give each worker its own report path
(HANDOFF-T07.md, not a shared HANDOFF.md), exactly as file ownership
partitions the code in
orchestrator-worker.
Worked example
Hour three of a long refactor, the window near full. Before compacting, the
session writes NOTES.md: the decision to keep the legacy serialiser behind
a feature flag, two unresolved test failures with their suspected cause, the
nine files touched so far, and the ./gradlew :svc:test command that gates
each step. CLAUDE.md’s Compact Instructions preserve the modified-file list
through the summary. Next morning, a fresh session reads NOTES.md and
resumes with full fidelity instead of a degraded recollection. The two test
failures become a scoped dispatch to the
implementer subagent: spec inline,
only the two test files and one production class authorised, report to
HANDOFF-fix-tests.md. The worker’s report, not its exploration, comes
back, and NOTES.md is updated. Nothing important ever lives only in a
context window.