This system creates a hierarchical multi-agent orchestration where a Master Claude Code instance (Opus) coordinates multiple Worker Claude Code instances (Sonnet/Haiku) working in parallel on the same Git repository using different branches/worktrees.
- Role: Orchestrator and coordinator
- Responsibilities:
- Task decomposition and assignment
- Worker lifecycle management (spawn/terminate)
- Progress monitoring and coordination
- Dependency resolution and merge coordination
- Token optimization through Worker delegation
- Re-prompting Workers when they deviate
- Role: Task executors
- Responsibilities:
- Execute assigned tasks independently
- Maintain context through memory files
- Report progress to Master
- Request clarification when needed
- Work within assigned Git worktree
- Role: Human oversight and control
- Capabilities:
- Visual monitoring of all terminal windows
- Manual Worker pause/resume
- Master decision override
- Real-time system state visibility
interface MasterToWorkerMessage {
type: 'TASK_ASSIGNMENT' | 'STATUS_REQUEST' | 'TERMINATE' | 'CONTEXT_UPDATE';
taskId: string;
payload: TaskAssignment | StatusRequest | TerminationRequest | ContextUpdate;
timestamp: number;
}
interface WorkerToMasterMessage {
type: 'STATUS_UPDATE' | 'QUESTION' | 'TASK_COMPLETE' | 'ERROR';
workerId: string;
taskId?: string;
payload: StatusUpdate | Question | TaskResult | ErrorReport;
timestamp: number;
}
interface TaskAssignment {
description: string;
branch: string;
workingDirectory: string;
context: string[];
dependencies: string[];
priority: number;
estimatedDuration: number;
}- File-based messaging: JSON files in shared
/tmp/multibot/messages/directory - WebSocket fallback: For real-time coordination when file-based is insufficient
- Git-based coordination: Branch status and merge requests through Git metadata
- Workers send heartbeat every 30 seconds
- Master monitors Worker health and responsiveness
- Automatic Worker restart on failure detection
interface TaskCoordination {
lockFile: string; // Prevent concurrent access
stateFile: string; // Current system state
messageQueue: string; // Pending messages
progressTracking: string; // Task progress updates
}multibot/
├── core/
│ ├── master/
│ │ ├── orchestrator.ts # Main Master logic
│ │ ├── task-manager.ts # Task decomposition and assignment
│ │ ├── worker-manager.ts # Worker lifecycle management
│ │ └── coordination.ts # Inter-agent coordination
│ ├── worker/
│ │ ├── agent.ts # Worker agent logic
│ │ ├── context-manager.ts # Memory file management
│ │ └── communication.ts # Master communication
│ └── shared/
│ ├── types.ts # Shared type definitions
│ ├── protocols.ts # Communication protocols
│ └── utils.ts # Shared utilities
├── infrastructure/
│ ├── git-manager.ts # Git worktree management
│ ├── terminal-manager.ts # Terminal window management
│ └── mcp-configurator.ts # MCP server setup
├── state/
│ ├── system-state.json # Global system state
│ ├── workers/ # Worker-specific state
│ │ ├── {workerId}-state.json
│ │ └── {workerId}-memory.json
│ └── tasks/
│ ├── active-tasks.json
│ ├── completed-tasks.json
│ └── task-dependencies.json
├── communication/
│ ├── messages/ # Inter-agent messages
│ │ ├── master-to-worker/
│ │ └── worker-to-master/
│ └── locks/ # Coordination locks
├── worktrees/ # Git worktrees for each Worker
│ ├── worker-1/
│ ├── worker-2/
│ └── ...
├── config/
│ ├── master-config.json
│ ├── worker-template.json
│ └── mcp-configs/
│ ├── github-mcp.json
│ └── shared-mcp.json
└── scripts/
├── spawn-master.sh
├── spawn-worker.sh
├── setup-worktrees.sh
└── cleanup.sh
interface MasterState {
workers: {
[workerId: string]: WorkerInfo;
};
tasks: {
active: Task[];
pending: Task[];
completed: Task[];
};
gitState: {
branches: BranchInfo[];
mergeQueue: MergeRequest[];
};
systemMetrics: SystemMetrics;
}
interface WorkerInfo {
id: string;
status: 'idle' | 'working' | 'blocked' | 'error';
currentTask?: string;
branch: string;
workingDirectory: string;
lastHeartbeat: number;
capabilities: string[];
}interface WorkerState {
id: string;
currentTask?: Task;
context: ContextMemory;
gitState: {
branch: string;
lastCommit: string;
uncommittedChanges: boolean;
};
communication: {
lastMasterContact: number;
pendingQuestions: Question[];
};
}
interface ContextMemory {
files: string[]; // Recently accessed files
concepts: string[]; // Key concepts learned
decisions: Decision[]; // Important decisions made
blockers: string[]; // Current blockers
}- Atomic Updates: All state changes use atomic file operations
- Versioning: State files include version numbers for conflict resolution
- Recovery: Automatic state recovery from backups on corruption
- Cleanup: Periodic cleanup of stale state and temporary files
{
"name": "github-worker-{workerId}",
"type": "github",
"config": {
"repository": "{owner}/{repo}",
"branch": "worker-{workerId}-branch",
"token": "{github_token}",
"permissions": ["read", "write", "pull_request"]
}
}{
"name": "shared-fs",
"type": "filesystem",
"config": {
"allowed_paths": [
"/mnt/c/Users/casey/multibot/state",
"/mnt/c/Users/casey/multibot/communication",
"/mnt/c/Users/casey/multibot/worktrees"
],
"permissions": ["read", "write"]
}
}{
"name": "git-coordinator",
"type": "git",
"config": {
"repository_path": "/mnt/c/Users/casey/multibot",
"worktree_management": true,
"branch_permissions": {
"master": ["read"],
"worker-*": ["read", "write"]
}
}
}{
"name": "terminal-manager",
"type": "terminal",
"config": {
"session_management": true,
"window_creation": true,
"process_monitoring": true
}
}{
"name": "task-queue",
"type": "queue",
"config": {
"storage": "file",
"persistence": true,
"priority_support": true
}
}{
"name": "metrics",
"type": "monitoring",
"config": {
"metrics_collection": true,
"performance_tracking": true,
"health_checks": true
}
}- Set up Git worktree management
- Implement file-based communication system
- Create basic Master-Worker spawning
- Implement state management foundation
- Develop task decomposition algorithms
- Implement context memory management
- Create Worker question/answer system
- Add progress monitoring and recovery
- Implement merge coordination
- Add dependency resolution
- Create visual monitoring interface
- Implement user override capabilities
- Add load balancing
- Implement intelligent Worker selection
- Add predictive scaling
- Optimize token usage
# 1. Initialize worktrees
./scripts/setup-worktrees.sh
# 2. Configure MCP servers
./scripts/configure-mcp.sh
# 3. Start Master
./scripts/spawn-master.sh
# 4. Workers spawn automatically based on workload- Docker containerization for isolation
- Kubernetes orchestration for scaling
- Persistent volume management for state
- Network security for inter-agent communication
- Monitoring and alerting for system health
- Worker sandboxing within Git worktrees
- MCP permission boundaries
- File system access restrictions
- Network isolation between Workers
- Automatic Worker recovery
- State corruption detection
- Graceful degradation strategies
- Manual intervention protocols
- Real-time system health dashboards
- Performance metrics collection
- Error rate tracking
- Resource utilization monitoring