The_swarm swarm-swarm
git clone https://github.com/ben-alkov/the_swarm
T=$(mktemp -d) && git clone --depth=1 https://github.com/ben-alkov/the_swarm "$T" && mkdir -p ~/.claude/skills && cp -r "$T/src/skills/swarm-swarm" ~/.claude/skills/ben-alkov-the-swarm-swarm-swarm && rm -rf "$T"
src/skills/swarm-swarm/SKILL.mdSwarm Orchestration (Self-Claiming Pool)
Overview
This skill is invoked by the
dispatcher. You should already have the goal, target, and selected roles from the dispatcher. If invoked directly, start from step 1.swarm
Orchestrate a pool of interchangeable workers that self-assign from a shared task list. Workers claim tasks, complete them, and loop back for more until the pool is empty.
How This Differs from Fan-Out
- Fan-out: one specialist per role, each gets a unique task
- Swarm: interchangeable workers share a task pool. Workers loop (claim multiple tasks). Task pool can be larger than worker count.
When to Use
- Large workloads with many independent, similar-sized tasks
- Tasks that don't require specialized expertise per task
- The number of tasks exceeds the number of workers
When NOT to Use
- Tasks require different specialist expertise (use fan-out)
- Sequential dependencies between tasks (use pipeline)
- Tasks need structured merging (use map-reduce)
Checklist
You MUST complete these steps in order:
- Identify goal and target
- Read config and determine worker role/count
- Decompose target into work units
- Check for existing team
- Confirm with user
- Create team and tasks
- Spawn workers
- Collect findings
- Synthesize and present report
- Await user instructions
- Shutdown and cleanup
Step 1: Identify Goal and Target
Determine from the user's request (or dispatcher context):
- Goal: What is being done? (e.g., "audit all modules", "review all API endpoints")
- Target: Which files, directories, or scope?
If unclear, ask the user. Do not guess scope.
Step 2: Read Config and Determine Workers
Read
$CLAUDE_PLUGIN_ROOT/config/swarm-roles.yaml to get the
preset config.
From the preset, determine:
: the role all workers share (default:worker_role
)researcher
: how many concurrent workers to spawn (default: 3)worker_count
Validation
The dispatcher has already validated config shape (role existence, required fields,
subagent_type values, numeric ranges). The checks
below cover swarm-specific semantics.
- Scale warning: if
> 7, warn the user that large swarms may hit context limits and recommend 3-5 workers.worker_count
Step 3: Decompose Target into Work Units
Analyze the target to determine discrete work units. Each work unit becomes one task in the pool:
- One task per module or directory
- One task per file group
- One task per endpoint or component
The number of tasks can (and often should) exceed the worker count. Workers will loop through the pool.
Step 4: Check for Existing Team
Only one team can exist per session. Before creating a new team, check if one already exists.
If a team exists:
- Active swarm: warn the user that a swarm is already running
and offer to shut it down first (
).TeamDelete - Orphaned team (from a crashed session or
): agents from the previous session are gone but the team and task list persist. Offer the user two options:/resume- Delete and restart:
the orphaned team, then proceed with a fresh swarm.TeamDelete - Salvage completed work: check
for completed tasks, synthesize any available findings from completed tasks, thenTaskList
and optionally re-run incomplete tasks.TeamDelete
- Delete and restart:
Step 5: Confirm with User
Present the dispatch plan using
AskUserQuestion:
I'll dispatch a swarm with these parameters: - Worker role: {role name} - Worker count: {N} - Task pool: {M} tasks - Target: {files/scope} Tasks: 1. {work unit 1} 2. {work unit 2} ... Proceed?
Do NOT spawn anything until the user confirms.
Step 6: Create Team and Tasks
Team Naming
Use format:
swarm-swarm-{goal-slug}-{timestamp}
Generate the timestamp from the current date/time as a Unix epoch.
Create Team
TeamCreate with team_name: "swarm-swarm-{goal-slug}-{timestamp}"
Create Tasks
One task per work unit via
TaskCreate:
: imperative title for the work unitsubject
: detailed scope, specific files/modules, reporting expectationsdescription
: present-continuous spinner labelactiveForm
All tasks are independent — no
blocks/blockedBy dependencies.
No owner assigned — workers self-claim.
Step 7: Spawn Workers
Spawn N worker agents via
Agent with:
: the team name from step 6team_name
:name
(e.g.,worker-{n}
,worker-1
)worker-2
: from the worker role configsubagent_type
: from the worker role config (if specified)model
:run_in_backgroundtrue
: composed from the parts belowprompt
Isolation Handling
Before spawning, check the worker role's
isolation field:
- If
is set:isolation: worktree- Override
tosubagent_typegeneral-purpose - Print a note:
Role {name}: using general-purpose (worktree isolation requires write access) - Pass
to theisolation: "worktree"
tool callAgent
- Override
- If
is absent: use the role'sisolation
as-issubagent_type
Prompt Construction
Part 1: Identity and Loop Instructions
Your name is {name}. You are part of team {team_name}. You are a pool worker. Your workflow is a loop: 1. Check TaskList for unclaimed tasks (status: pending, no owner) 2. Claim one by setting yourself as owner and marking it in_progress 3. Verify the claim: call TaskGet on the task you claimed. If the owner is not your name, another worker claimed it first — go back to step 1 4. Complete the work described in the task 5. Send your findings to the team lead via SendMessage - Include a summary field (5-10 words) - Include the task subject in your message 6. Mark the task as completed 7. Go back to step 1 When no unclaimed tasks remain, go idle.
Part 2: Role Prompt
The
prompt field from swarm-roles.yaml for the worker role.
Part 3: Goal and Target Context
## Goal {goal description from user} ## Target {target scope — workers will self-select from the task pool} {any additional context the user provided}
Step 8: Collect Findings
Workers send findings via
SendMessage after each task they
complete. Messages are delivered automatically.
Normal flow: Workers loop through multiple tasks, sending findings after each. Workers go idle when the pool is empty.
Error handling:
- Idle worker without findings: send a message asking for status
- No response after nudge: note in report, mark tasks as blocked
- Stuck tasks: reassign by removing the owner if a worker stalls
Step 9: Synthesize and Present Report
Once all tasks are completed (or you've noted stuck ones):
Synthesize findings into a unified report organized by theme or severity, not by worker or task.
Report Structure
## Swarm Analysis Report **Goal:** {goal} **Target:** {target} **Workers:** {N workers, M tasks completed} ### Critical Issues {findings rated critical/high, with file:line references} ### Important Issues {findings rated medium/important} ### Suggestions {lower-priority findings and recommendations} ### Summary {brief overall assessment — 2-3 sentences}
Step 10: Await User Instructions
After presenting the report:
- Do NOT fix issues workers found
- Do NOT shut down the team automatically
- Do NOT proceed past reporting without user input
Wait for the user to decide next steps.
Step 11: Shutdown and Cleanup
When the user indicates they're done:
- Send
to each worker viashutdown_request
(include the monitor agent ifSendMessage
was active)watchdog: true - Wait for
from each. If an agent does not respond after a reasonable wait, send one nudge message. If still unresponsive, proceed — the agent may have crashed or terminated.shutdown_response - Call
to clean up.TeamDelete
is the authoritative cleanup mechanism — it will fail if active agents remain. If it fails, retry after unresponsive agents have timed out.TeamDelete
Design Constraints
- Interchangeable workers: all workers use the same role prompt
- Self-claiming: workers find and claim their own tasks
- No dependencies: all tasks in the pool are independent
- One team per session: check before creating
- Lead synthesizes: present a unified report, not raw worker output
- User controls lifecycle: never auto-shutdown