Multi-Agent Architecture
claude-code's multi-agent system spans from lightweight in-process teammates to cloud-sandboxed remote execution.
Execution Models
| Model | Isolation | Use Case |
|---|---|---|
InProcessTeammate |
AsyncLocalStorage |
Same terminal, lightweight |
LocalAgentTask |
Async background | Non-blocking sub-agent |
RemoteAgentTask |
Cloud CCR | Full cloud sandbox |
| Worktree | Git worktree | Parallel code editing |
DreamTask |
Background | auto-dream consolidation |
MonitorMcpTask |
Background | MCP server monitoring |
The Forked Agent Pattern
forked-agent-pattern is the shared primitive. All background operations use the same CacheSafeParams-based fork with cloned mutable state but shared prompt cache prefix. Achieves 92% prefix reuse — spawning 5 agents costs nearly the same as 1.
TeammateTool: 13 Operations
teammate-tool covers the full lifecycle: team setup (spawn, discover, cleanup), membership (join, approve, reject), task coordination (create, claim, complete), communication (send, broadcast, shutdown). Task claiming uses file locking with 30 retry attempts.
KAIROS + ULTRAPLAN: Two-Speed System
kairos handles ambient continuous operations (fast thinking). ultraplan handles episodic deep deliberation in remote Cloud Container Runtime (slow thinking). The community drew the parallel to Kahneman's System 1/System 2.
Coordinator Mode
Encodes orchestration logic in natural language prompts rather than procedural DAGs. Four phases: Research (parallel) → Synthesis (coordinator alone) → Implementation (parallel) → Verification (parallel). Coordinators cannot access filesystem directly — least privilege.
Known Limits
TEAMMATE_MESSAGES_UI_CAP = 50— added after 292-agent test consumed 36.8 GBomitClaudeMd: trueon read-only agents saves 5-15 GTok/weekbypassPermissionsbug: teammates in Delegate Mode lose file tools