Deep Dive: Multi-Agent Dispatch - Spawn, Fork, Direct
Summary
Source-level analysis of the three ways Claude Code dispatches work: Spawn (a named sub-agent with a fresh context, its own tool pool, permission mode, and model), Fork (a synthetic agent that inherits the parent conversation byte-for-byte so parallel workers share the prompt cache), and Direct (the main agent just does the task itself). Covers sync-to-background promotion via a promise race, recursion guards on forking, git-worktree isolation, and a decision matrix for picking a strategy per task.
Key Takeaways
- Spawned agents start from zero context - the dispatch prompt must carry all necessary background
- Fork exists to share the prompt cache: byte-identical request prefixes make parallel workers dramatically cheaper
- Fork workers run under strict rules: no further spawning, no chatting, commit before reporting, bounded report size
- Sub-agents get independent tool pools and permission modes, not a copy of the parent's
- Rule of thumb: specialist skills need spawn; splittable research suits fork; simple steps are best done directly
Reliability Note
English summary of a contributed deep-dive article (original text in Chinese) analyzing a reverse-engineered Claude Code snapshot. Unofficial - verify against official Anthropic docs and behavior.
Flows informed by this source
5Choose the Right Dispatch: Spawn, Fork, or Direct
Three ways to hand work to a sub-agent - fresh-context spawn, cache-sharing fork, or just doing it yourself - and the decision matrix for picking per task.
+1 more steps to Done
Best forproduction-grade builds with strict verification
Make Parallel Sub-Agents Share the Prompt Cache
Byte-identical request prefixes are why forked workers cost a fraction of spawned ones - engineer your dispatch so every parallel child hits the same cache entry.
+1 more steps to Done
Best forproduction-grade builds with strict verification
Sub-Agent Delegation with Context Isolation
Delegate bounded work to sub-agents that run in fresh context and return only distilled results - the pattern behind scalable long tasks.
+1 more steps to Done
Best forproduction-grade builds with strict verification
Single-Agent vs Multi-Agent: Decide and Design
A decision flow for the most expensive architecture choice in agent systems - grounded in what actually ships versus what demos well.
+1 more steps to Done
Best forbuilders who have shipped a basic app before
Prompt-Cache-Aware Conversation Design
Structure your agent's context for prefix caching: stable prefixes, append-only history, and cache-friendly dynamic content.
Best forbuilders who have shipped a basic app before