Inspired by Nicholas Carlini autonomously building a C compiler with 16 Claude instances. There is no master agent, pure git self-organization, each agent independently claims tasks, writes code, and pushes.
Trigger Conditions
Use this skill when the user mentions "swarm mode", "multi-agent parallel", "infinite loop", "agent swarm", "start swarm".
Prerequisites
- tmux(
brew install tmux) - claude CLI (already installed)
- git repository (existing or newly created)
Usage Flow
Step 1: Describe the project
The user tells me:
- Project directory path (must be a git repository)
- Project goals and overall description
- Initial task list (or let the agent break it down itself)
- Number of agents (default 8)
- Code standards and test commands
Step 2: Initialize the project
bash SKILL_DIR/scripts/setup_project.sh <项目目录>
This will create in the project:
AGENT_PROMPT.md- Generated from a template, needs me to customize it according to user requirementsTASKS.md- Initial task listcurrent_tasks/- Task claiming directoryagent_logs/- Log directory
Then I customize references/agent-prompt-template.md based on AGENT_PROMPT.md, filling in the project-specific information.
Step 3: Start the swarm
bash SKILL_DIR/scripts/start_swarm.sh <agent数量> <项目目录>
This will:
- Create a git worktree for each agent (share the .git object store, no disk waste)
- Create a tmux session, one agent per pane
- Each agent enters an infinite loop: pull → claim task → execute → push → next
Step 4: Open the observation dashboard
python3 SKILL_DIR/scripts/dashboard.py <项目目录> 8420
Open in browser http://localhost:8420,可以:
- View the status of all agents, git log, and task progress in real time
- View the latest log of each agent
- Send commands directly to agents via the input box (written to HUMAN_INPUT.md)
- Stop all agents with one click
You can also monitor via the command line:
# 终端状态
bash SKILL_DIR/scripts/status.sh <项目目录>
# 发送指令
bash SKILL_DIR/scripts/send_input.sh <项目目录> "你的指令"
# 直接进入tmux观察
tmux attach -t swarm-<项目名>
Step 5: Stop
bash SKILL_DIR/scripts/stop_swarm.sh <项目目录>
Automatically stop all agents + merge branches + clean up worktrees.
Core Mechanisms
Git self-organizing coordination
- Each agent claims tasks through
current_tasks/*.lockfiles - Through
TASKS.mdto understand global progress - Through
git logto understand the work of other agents - Conflicts are resolved by the agents themselves
Git Worktree isolation
- No multiple clones, use
git worktreeto achieve isolation - All worktrees share the same
.gitobject store - Each agent works independently in its own worktree
Infinite loop
- Each agent automatically starts the next session after completing one
- Through
git pullto get the latest results of other agents - Through sleep intervals to avoid API rate limiting
Key Configuration
| Parameter | Default Value | Description |
|---|---|---|
| Number of agents | 8 | Can be specified at startup |
| sleep interval | 5 seconds | Adjustable in agent_loop.sh |
| Model | claude-opus-4-6 | Adjustable in agent_loop.sh |
Risks and Mitigation
| Risk | Mitigation |
|---|---|
| API rate limiting | sleep interval + adjustable number of agents |
| Merge conflicts | AGENT_PROMPT guides small-grained commits |
| Infinite loops and useless work | Log monitoring + stop conditions |
| Disk space | stop_swarm.sh automatic cleanup |
| Runaway costs | The number of sessions can be limited in AGENT_PROMPT |
Produced by Hua Shu | AI Native Coder · Indie Developer WeChat Official Account "Hua Shu" | 300K+ followers | AI tools and productivity enhancement Representative work: Xiaomao Fill Light (AppStore Paid Rankings Top 1) · "One Book to Master DeepSeek"