Skip to content

Architecture Reference โ€‹

Understanding how agent teams work internally.

Fresh ๐ŸŒฑ

System Overview โ€‹

Component Details โ€‹

1. Team Lead โ€‹

Role: Orchestrator and coordinator

Capabilities:

  • Spawn teammates
  • Manage task list
  • Synthesize results
  • Direct communication with teammates
  • File editing and tool execution (unless in delegate mode)

Constraints:

  • One team at a time
  • Cannot be replaced/promoted to teammate
  • In delegate mode: coordination-only

Lifecycle:

  • Created when user starts Claude Code
  • Creates team (if requested)
  • Spawns teammates
  • Coordinates work
  • Initiates cleanup

2. Teammates โ€‹

Role: Independent workers on assigned tasks

Capabilities:

  • Work on assigned tasks
  • Communicate with other teammates
  • Update shared task list
  • Read project context (CLAUDE.md, MCP servers)

Constraints:

  • Cannot spawn other teammates
  • Cannot run cleanup
  • Cannot create new teams
  • Own context window only

Lifecycle:

  • Spawned by lead
  • Load project context
  • Receive spawn prompt
  • Work independently
  • Can be shut down gracefully or forced

3. Shared Task List โ€‹

Storage: ~/.claude/tasks/[team-name]/

Structure:

Each task is a separate file with JSON:
{
  "id": 1,
  "title": "Implement authentication",
  "description": "...",
  "status": "in_progress",  // pending, in_progress, completed
  "owner": "Teammate 1",
  "created": "2026-02-12T14:00:00Z",
  "updated": "2026-02-12T14:15:00Z",
  "dependsOn": [2, 3],      // Task IDs this depends on
  "blocks": [4, 5]          // Task IDs waiting on this
}

Features:

  • File locking prevents race conditions
  • Automatic dependency resolution
  • Status tracking (pending โ†’ in_progress โ†’ completed)
  • Owner assignment
  • Blocking relationships

4. Mailbox System โ€‹

Purpose: Message delivery between agents

Behavior:

  • Asynchronous message queue
  • Automatic message delivery
  • No polling required
  • Teammates notified of new messages
  • Lead receives all messages automatically

Message Types:

  • Direct messages (1:1)
  • Broadcast messages (1:many)
  • System notifications
  • Status updates

Example Flow:

Lead โ†’ "Tell Teammate 1: focus on security"
  โ†’ Stored in mailbox
  โ†’ Teammate 1 notified
  โ†’ Teammate 1 reads message
  โ†’ Teammate 1 adjusts work
  โ†’ Complete

5. Team Configuration โ€‹

File: ~/.claude/teams/[team-name]/config.json

Contents:

json
{
  "teamName": "auth-review",
  "created": "2026-02-12T14:00:00Z",
  "leadId": "lead-uuid",
  "members": [
    {
      "name": "Security Reviewer",
      "agentId": "agent-123",
      "agentType": "teammate",
      "spawned": "2026-02-12T14:01:00Z",
      "status": "active"
    },
    {
      "name": "Performance Specialist",
      "agentId": "agent-456",
      "agentType": "teammate",
      "spawned": "2026-02-12T14:01:00Z",
      "status": "active"
    }
  ],
  "settings": {
    "teamMode": "in-process",
    "permissions": "default"
  }
}

Teammate Discovery:

  • Teammates can read this file
  • They know who else is on team
  • They can coordinate through knowledge of team composition

Data Flow โ€‹

Creating a Team โ€‹

User โ†’ "Create agent team"
  โ†“
Lead analyzes request
  โ†“
Lead decides team composition
  โ†“
For each teammate:
  - Generate spawn configuration
  - Create agent instance
  - Load project context
  - Send spawn prompt
  - Wait for startup
  โ†“
Create shared task list
Create team config file
  โ†“
Team ready

Teammate Working on Task โ€‹

Teammate picks up task from list
  โ†“
Teammate reads task details
  โ†“
Teammate updates status: "in_progress"
  โ†“
Teammate works on implementation
  โ†“
Teammate may message other teammates
  โ†“
Teammate finishes work
  โ†“
Teammate updates task status: "completed"
  โ†“
System unblocks dependent tasks
  โ†“
Next teammate can now claim unblocked task

Lead Synthesizing Results โ€‹

Lead requests: "Compile findings"
  โ†“
Lead reads all completed tasks
  โ†“
Lead collects teammate messages/results
  โ†“
Lead synthesizes into coherent summary
  โ†“
Lead saves to document
  โ†“
Ready for output/sharing

Context Management โ€‹

Project Context (Automatic) โ€‹

Each teammate loads:

  • CLAUDE.md - Project instructions
  • MCP Servers - Tools and integrations
  • Skills - Custom prompts
  • Spawn Prompt - Role-specific instructions

Context Isolation โ€‹

  • Lead's conversation history NOT shared
  • Each teammate has independent context
  • No context bleeding between teammates
  • Shared task list is the coordination mechanism

Memory Efficiency โ€‹

  • Each teammate is independent Claude instance
  • Token usage scales with number of teammates
  • Can't pass large conversation histories
  • Better for focused, well-scoped work

Permission Model โ€‹

Permission Inheritance โ€‹

  1. Startup: All teammates inherit lead's permissions
  2. Runtime: Permissions can be changed per teammate
  3. Spawn: Cannot set per-teammate permissions at creation
  4. Flag: --dangerously-skip-permissions affects all agents

Permission Types โ€‹

  • File operations - Read/write/delete
  • Command execution - Run tools and CLI
  • Tool usage - Access to specific tools
  • Network access - External API calls

Display Modes โ€‹

In-Process Mode โ€‹

Architecture:

Single terminal window
  โ”œโ”€ Lead output
  โ”œโ”€ Teammate 1 output (when selected)
  โ”œโ”€ Teammate 2 output (when selected)
  โ””โ”€ Teammate 3 output (when selected)

Navigation: Shift+Up/Down cycles
Storage: Single process

Advantages:

  • Works anywhere
  • Lower resource usage
  • Simple architecture

Split Panes Mode โ€‹

Architecture:

tmux Session
โ”œโ”€ Window 1: Lead
โ”œโ”€ Window 2: Teammate 1
โ”œโ”€ Window 3: Teammate 2
โ””โ”€ Window 4: Teammate 3

All visible simultaneously
Navigation: Click or tmux keys
Storage: Multiple tmux panes

Requirements:

  • tmux or iTerm2 (via it2 CLI)
  • Python API (iTerm2)

File Organization โ€‹

~/.claude/ Directory Structure โ€‹

~/.claude/
โ”œโ”€โ”€ settings.json          # Global settings
โ”œโ”€โ”€ teams/
โ”‚   โ””โ”€โ”€ auth-review/
โ”‚       โ””โ”€โ”€ config.json    # Team configuration
โ”œโ”€โ”€ tasks/
โ”‚   โ””โ”€โ”€ auth-review/
โ”‚       โ”œโ”€โ”€ task-1.json    # Individual tasks
โ”‚       โ”œโ”€โ”€ task-2.json
โ”‚       โ””โ”€โ”€ task-3.json
โ””โ”€โ”€ logs/
    โ””โ”€โ”€ team-sessions/     # Session transcripts

Token Usage โ€‹

Cost Per Agent โ€‹

Each teammate = separate Claude instance:

  • Lead: 1 context window
  • 3 teammates: 4 context windows total
  • 5 teammates: 6 context windows total

Scaling โ€‹

  • Single agent: 1x token cost
  • 3-agent team: 3-4x token cost
  • 5-agent team: 5-7x token cost

When worthwhile:

  • 3x token cost รท 2-3x speedup = 1.5x net cost for 3x faster
  • Breakeven when speedup > token cost multiplier

Synchronization โ€‹

File Locking โ€‹

Task list uses file locks to prevent:

  • Race conditions when claiming tasks
  • Concurrent modifications
  • Data corruption

Message Delivery โ€‹

Mailbox ensures:

  • No message loss
  • Order preservation
  • Automatic retries
  • Timeout handling

Status Consistency โ€‹

  • Each agent updates own status atomically
  • Changes visible to all immediately
  • No eventual consistency delays
  • Synchronous updates

Limitations & Constraints โ€‹

Current Limitations โ€‹

LimitationImpactWorkaround
No session resumptionCan't /resume with teammatesClean up and create new team
One team per leadCan't manage multiple teamsSequential team creation
No nested teamsTeammates can't spawn teamsOnly lead can spawn
Lead is fixedCan't rotate leadershipPlan team lifecycle upfront
Split panes needs tmuxNot available in VS CodeUse in-process mode
Task status can lagTeammates don't mark completeManual status update if stuck

Best Practices for Architecture โ€‹

Minimize Context Size โ€‹

  • Keep spawn prompts concise
  • Don't include entire conversation history
  • Use CLAUDE.md for project context
  • Reference files by path, not content

Design Task Boundaries โ€‹

  • Independent tasks parallelize better
  • Shared files create conflicts
  • Clear ownership per teammate
  • Explicit interfaces between tasks

Plan for Synchronization Points โ€‹

  • Identify where integration happens
  • Set up explicit check-ins
  • Use task dependencies
  • Plan synthesis timing

Resource Efficiency โ€‹

  • Use Haiku for simple, fast tasks
  • Use Sonnet for balanced workloads
  • Use Opus for complex reasoning
  • Monitor overall token usage

See Also โ€‹