The_swarm swarm-fan-out
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-fan-out" ~/.claude/skills/ben-alkov-the-swarm-swarm-fan-out && rm -rf "$T"
src/skills/swarm-fan-out/SKILL.mdFan-Out Orchestration
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 parallel specialist agents for concurrent analysis of code, PRs, or topics. You become the team lead, spawn read-only specialists, collect their findings, and synthesize a unified report.
Core principle: Fan-out N specialists, collect findings, synthesize, present. No file edits, no implementation — analysis only.
When to Use
- User asks for review from multiple angles
- User wants parallel independent analysis
- User explicitly asks for "swarm" or "team review"
- Task benefits from diverse concurrent specialist perspectives
When NOT to Use
- Single-perspective tasks (use a regular agent instead)
- Sequential dependencies between workers
- Simple questions or explorations
- Tasks requiring file edits without
configured on the roleisolation: worktree - A team already exists in the current session
Checklist
You MUST complete these steps in order:
- Identify goal and target
- Select roles
- Check for existing team
- Confirm with user
- Create team and tasks
- Spawn specialists
- Collect findings
- Synthesize and present report
- Await user instructions
- Shutdown and cleanup (when user says done)
Step 1: Identify Goal and Target
Determine from the user's request:
- Goal: What is being reviewed/analyzed? (e.g., "security review", "PR review", "codebase audit")
- Target: Which files, PR, or scope? (e.g., "src/auth/", "PR #42", "the entire API layer")
If unclear, ask the user. Do not guess scope.
Step 2: Select Roles
Roles come from
$CLAUDE_PLUGIN_ROOT/config/swarm-roles.yaml.
Read the config file to get available roles and presets.
Selection priority:
- User specifies a preset name → use that preset's roles
- User specifies individual role names → use those
- User describes what they want → match to appropriate roles
- Default for "review" requests → use
presetpr-review
If the user requests roles not in the config, tell them what's available and ask for clarification. Do not invent roles on the fly.
Validation
The dispatcher has already validated config shape (role existence, required fields,
subagent_type values). The checks below cover
fan-out-specific semantics.
- Non-empty roles: the
list must contain at least 1 entry. If empty or missing, report the error and abort.roles - No duplicates: warn the user if the same role appears more than once in the list.
- Single-role warning: if the
list contains exactly 1 role, warn the user that fan-out orchestration adds overhead with no parallelism benefit. Offer to run a single agent directly instead.roles
Step 3: 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 4: Confirm with User
Present the dispatch plan using
AskUserQuestion:
I'll dispatch a swarm with these specialists: - security-reviewer: Review for vulnerabilities - performance-reviewer: Analyze performance issues - quality-reviewer: Code quality and maintainability Target: [files/PR/scope] Proceed?
Do NOT spawn anything until the user confirms. No surprise token costs.
Step 5: Create Team and Tasks
Team Naming
Use format:
swarm-fan-out-{goal-slug}-{timestamp}
Example:
swarm-fan-out-pr-review-1708200000
Generate the timestamp from the current date/time as a Unix epoch.
Create Team
TeamCreate with team_name: "swarm-fan-out-{goal-slug}-{timestamp}"
Create Tasks
One task per role via
TaskCreate:
: imperative title (e.g., "Review authentication module for security vulnerabilities")subject
: detailed scope, target files, reporting expectationsdescription
: present-continuous spinner label (e.g., "Reviewing authentication security")activeForm
All tasks are independent — no
blocks/blockedBy dependencies in v1.
Step 6: Spawn Specialists
For each role, spawn one teammate via
Agent with:
: the team name from step 5team_name
: the role name (e.g.,name
)security-reviewer
: from the role config (typicallysubagent_type
)Explore
: from the role config (if specified)model
: from the role config (if specified)isolation
:run_in_backgroundtrue
: composed from three parts (see below)prompt
Isolation Handling
Before spawning, check each role's
isolation field:
- If
is set:isolation: worktree- Override
tosubagent_type
(even if the role saysgeneral-purpose
or omits the field)Explore - 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-is (default:subagent_type
), do not passExplore
to Agentisolation
Prompt Construction
Each teammate's prompt is composed from:
Part 1: Identity and Instructions
Your name is {name}. You are part of team {team_name}. Instructions: - Claim your task from TaskList, mark it in_progress, then completed when done. - Send your findings to the team lead via SendMessage when complete. - Include a summary field in your message (5-10 words).
Part 2: Role Prompt
The
prompt field from swarm-roles.yaml for this role.
Part 3: Goal and Target Context
## Goal {goal description from user} ## Target {target files, PR, scope, or other context} {any additional context the user provided}
All task-specific context MUST be in the spawn prompt — teammates do not have access to the lead's conversation history.
Step 7: Collect Findings
Teammates send findings via
SendMessage. Messages are delivered
automatically — you do not need to poll.
Normal flow: Wait for all specialists to report. Teammates go idle after sending — this is expected behavior.
Error handling:
- Idle teammate without findings: send a message asking for status
- No response after nudge: note in report, mark task as blocked
- TeamCreate failure: report error to user, do not proceed
Step 8: Synthesize and Present Report
Once all specialists have reported (or you've noted non-reporters):
Synthesize findings into a unified report organized by severity or theme, not by specialist. Cross-reference overlapping findings.
Report Structure
## Swarm Analysis Report **Goal:** {goal} **Target:** {target} **Specialists:** {list of roles that reported} ### 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}
If specialists disagree, note the disagreement rather than silently picking one perspective.
Step 9: Await User Instructions
After presenting the report:
- Do NOT fix issues specialists found
- Do NOT shut down the team automatically
- Do NOT proceed past reporting without user input
Wait for the user to decide next steps. They may:
- Ask for more detail on specific findings
- Ask you to fix issues (you would exit delegate mode for this)
- Say they're done (proceed to step 10)
Step 10: Shutdown and Cleanup
When the user indicates they're done:
- Send
to each teammate 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
- Read-only specialists: v1 uses
— no file edits, no Bash, no Write. This is enforced at the agent-type level.subagent_type: Explore - One team per session: check before creating.
- No nested teams: teammates cannot spawn their own teams.
- Lead synthesizes: present a unified report, not raw specialist output.
- User controls lifecycle: never auto-shutdown.