Chapter 12: Multi-Agent Architecture

Both agents can spawn sub-agents to handle parallel or delegated work. The implementation reveals different approaches to agent isolation, communication, and coordination.

Codex: In-Process Agent Tree

Architecture

Codex uses an in-process agent system with shared state:

Spawning

The spawn_agents_on_csv tool (in agent_jobs.rs) and AgentControl.spawn_agent() spawn child agents:

Parent Agent
    ├── spawn_agent(FullHistory) → Child Agent 1 (full history fork)
    ├── spawn_agent(LastNTurns(5)) → Child Agent 2 (recent history fork)
    └── spawn_agent(FullHistory) → Child Agent 3 (full history fork)

Each child agent:

Communication

Depth Control

Code Location

Claude Code: Process-Based Isolation

Architecture

Claude Code spawns sub-agents as separate child processes:

Spawning

Parent Process
    ├── spawn() → Child Process 1 (fresh context, task prompt)
    ├── spawn() → Child Process 2 (fresh context, task prompt)
    └── spawn() → Child Process 3 (fresh context, task prompt)

Each child:

Communication

Isolation Options

No Depth Limit

Claude Code does not enforce an explicit depth limit on agent spawning. In practice, context window limits and cost act as natural constraints.

Code Location

Comparison

Aspect Codex (In-Process) Claude Code (Process-Based)
Isolation Shared process, separate async tasks Separate OS processes
Memory Shared memory space Fully isolated
History Forked from parent Fresh context per child
Communication Mailbox (async channels) stdout/stdin
Sibling communication Yes (via mailbox) No
Depth control Configurable limits No explicit limit
Filesystem isolation Shared workspace Optional git worktree
Overhead Low (async task) Higher (process spawn)
Crash isolation Child crash may affect parent Child crash is contained

Tradeoffs

Codex's in-process approach:

Claude Code's process-based approach:

When Sub-Agents Are Used

Both agents use sub-agents for:

The key difference is that Codex's children are aware of the conversation context (forked history), while Claude Code's children are context-free (task prompt only). This means Codex children can make more informed decisions, but at the cost of larger context per child.