Agent Execution Models: Five Ways to Run
Claude Code supports five distinct agent execution models, each with different isolation levels, use cases, and cost profiles. All five share the forked agent pattern as their primitive, but they differ in where they run and how they're isolated.
The Five Models
| Model | Isolation | Where it runs | Cache sharing | Use case |
|---|---|---|---|---|
| InProcessTeammate | AsyncLocalStorage (same process) | Same terminal | Full cache reuse | Lightweight parallel work |
| LocalAgentTask | Separate async process | Background | Cache prefix shared | Non-blocking sub-agents |
| RemoteAgentTask | Cloud container (CCR) | Anthropic cloud | No cache sharing | Full sandboxed execution |
| DreamTask | Background-only, memory writes only | Background | Cache prefix shared | Memory consolidation |
| Worktree Agent | Git worktree (own branch + directory) | Background or interactive | Cache prefix shared | Parallel code editing |
The Shared Primitive: Forked Agents
All five models use the forked agent pattern from src/utils/forkedAgent.ts. The fork constructs a child agent using CacheSafeParams — byte-identical to the parent's API request prefix, enabling 92% prompt cache reuse. The child gets cloned mutable state (separate readFileState LRU cache, child AbortController, fresh denialTracking) but shares the cache prefix.
Anti-recursion: Fork children see the AgentTool in their pool but reject recursive fork attempts, checked via <fork_boilerplate_tag> marker.
Cost Model
The cache-sharing economics are dramatic:
- Five parallel agents cost nearly the same as one (92% prefix reuse)
- Measured savings: $4.85 (81% reduction) per representative task
- Breaking cache alignment is catastrophic: PR #18143 tried effort: 'low' on a fork, cache dropped from 92.7% to 61%, writes spiked 45x
Only four parameters are safely overridable without breaking cache: abortController, skipTranscript, skipCacheWrite, canUseTool.
Worktree Isolation: Git as Virtualization
Instead of complex filesystem virtualization, Anthropic leveraged Git's built-in mechanism. Each worktree agent gets:
- Isolated: own working directory, staging area, HEAD
- Shared: .git/objects/ (history stored once), .git/refs/ (branches visible)
Five simultaneous worktree agents produce five independent branches merged through standard PR process. Cleanup is automatic on agent exit.
The COORDINATOR_MODE Vision
COORDINATOR_MODE (compiled out of standard builds) represents the most aggressive parallelism: one worker per logical CPU core. The coordinator's four-phase workflow: 1. Research — workers investigate codebase in parallel 2. Synthesis — coordinator alone reads findings and crafts specs 3. Implementation — workers make targeted changes per spec 4. Verification — workers run tests in parallel
Status: archived TypeScript, never ported to the current Bun+Rust stack.
Related Entities
agent-teams— the coordination layerforked-agent-pattern— the shared primitiveworktree-isolation— git-based isolationcoordinator-mode— the archived visioncache-economics— why cache sharing matterskairos— the always-on execution model