Back to Vault
Claude Code Internals
Tier 1

Deep Dive: Multi-Agent Dispatch - Spawn, Fork, Direct

Read the Article Fetched 2026-07-08 5 related flows

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

5
Flows category icon
Agent Architecture

Choose 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.

01Implement spawn: fresh context specialists
02Implement fork: inherited context, shared cache
03Add guards and async lifecycle

+1 more steps to Done

Best forproduction-grade builds with strict verification

4 steps90-150 minutesAdvanced
Flows category icon
Agent Architecture

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.

01Map what must be byte-identical
02Stabilize the shared prefix
03Measure cache performance

+1 more steps to Done

Best forproduction-grade builds with strict verification

4 steps60-120 minutesAdvanced
Flows category icon
Agent Architecture

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.

01Specify the delegation contract
02Implement the isolated sub-loop
03Wire dispatch into the parent and distill

+1 more steps to Done

Best forproduction-grade builds with strict verification

4 steps90-150 minutesAdvanced
Flows category icon
Agent Architecture

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.

01Analyze the workload for separability
02Score the three architectures
03Sketch the chosen architecture

+1 more steps to Done

Best forbuilders who have shipped a basic app before

4 steps45-75 minutesIntermediate
Flows category icon
Memory & Context

Prompt-Cache-Aware Conversation Design

Structure your agent's context for prefix caching: stable prefixes, append-only history, and cache-friendly dynamic content.

01Audit context stability
02Restructure for stable-first layout
03Verify cache hits and measure savings

Best forbuilders who have shipped a basic app before

3 steps45-75 minutesIntermediate

Made with Emergent