The_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" ~/.claude/skills/ben-alkov-the-swarm-swarm && rm -rf "$T"
src/skills/swarm/SKILL.mdSwarm Dispatcher
Overview
Route swarm requests to the appropriate pattern skill. Read the preset config, determine the pattern, and follow the corresponding skill.
Goal Slug Generation
When pattern skills create team names, they use the format
swarm-{pattern}-{goal-slug}-{timestamp}. Generate the goal slug
from the user's goal description
- Lowercase only
- Replace spaces and special characters with hyphens
- Remove all characters except
,a-z
, and0-9- - Collapse consecutive hyphens into one
- Truncate to 30 characters maximum
- Strip leading and trailing hyphens
- Abort if empty: if the slug is empty after all transformations (e.g., goal was all special characters), abort with: "Could not generate a valid team name from the provided goal."
Examples
- "PR review" →
pr-review - "Security audit of auth module" →
security-audit-of-auth-module - "Fix the OAuth2/OIDC integration!!!" →
fix-the-oauth2-oidc-integrat
Pass the goal slug through to the pattern skill along with the goal, target, and preset.
Stale Worktree Cleanup
Before starting any swarm, check for leftover worktrees from previous sessions
git worktree list
If worktrees exist that are not associated with the current session (stale branches from crashed or abandoned swarms), offer the user two options
- Remove stale worktrees:
for each stale entry. This reclaims disk space but the branches persist and can still be mergedgit worktree remove <path> - Keep them: the user may want to inspect or recover work
Only worktrees whose branch names match the
swarm-* naming
convention should be flagged. Non-swarm worktrees are outside
this plugin's scope.
Steps
-
Identify goal and target from the user's request. If unclear, ask
-
Read roles config from
$CLAUDE_PLUGIN_ROOT/config/swarm-roles.yaml -
Select preset or roles using the same priority as v1. When resolving roles, check for inline definitions in the preset first (entries with a
andname
field), then fall back to global role names in theprompt
sectionroles:- User specifies a preset name -> use it
- User specifies individual role names -> use those (fan-out)
- User describes what they want -> match to preset/roles
- Default for "review" ->
presetpr-review
-
Validate config — check the resolved preset and roles for structural problems before routing to a pattern skill. Abort or warn as indicated
Required role fields
Every role referenced by the preset (whether global or inline) must have
— non-empty. An inline role missingprompt
means the agent would be spawned with no instructions. Abortprompt
— must be one ofsubagent_type
orExplore
. Missing or unrecognized values (typos likegeneral-purpose
) cause opaque spawn failures. AbortExplorer
Isolation consistency
If a role specifies
but itsisolation: worktree
is notsubagent_type
, warn thatgeneral-purpose
will be overridden tosubagent_type
at spawn time (worktree isolation requires write access). This is not an error — pattern skills handle the override — but the role definition is internally inconsistent and should be fixed.general-purposeNumeric fields
(swarm) andworker_count
(speculative) must be positive integers when present. Non-numeric values, zero, or negative values are invalid. Abortapproach_countTopology-pattern agreement
The preset's declared
must match the topology keys present in the preset config:patternPattern Expected keys Unexpected keys fan-outroles
,stagesnodespipeline
orstagesnodesbare rolestask-graphnodes
withoutstagesdepends_onmap-reduce
,map_rolereduce_role
,rolesstagesspeculative
,approach_rolejudge_role
,rolesstagesswarmworker_role
,rolesstagesIf unexpected keys are present, warn that the declared pattern may not match the intended topology. Ask the user to confirm.
Watchdog prerequisite
If the preset has
, verify that thewatchdog: true
role exists in the globalmonitor
section. If missing, abort — the watchdog cannot be spawned without a role definition.roles:Deprecated preset completeness
If the preset has
but nodeprecated: true
field, warn that no replacement can be suggested. The user can still proceed.successorReserved names
If any role name in the preset matches
ormonitor
, warn that these names have special behavior in hooks (exemption from quality gates, speculative gate branching). Using them as regular specialist names will cause incorrect gate logic.judge -
Determine pattern from the selected preset's
field. If absent, default topattern
. If the preset hasfan-out
, warn the user and suggest thedeprecated: true
preset instead. Proceed only if the user confirmssuccessor -
Route to pattern skill — read and follow the corresponding skill
Pattern Skill
(or absent)fan-outswarm-fan-outswarmswarm-swarmpipelineswarm-pipelinetask-graphswarm-pipelinemap-reduceswarm-map-reducespeculativeswarm-speculativeRead the skill file and follow its checklist from step 1. Pass through: goal, target, selected roles/preset, and any user context.
-
Watchdog modifier — if the preset has
, the lead must spawn a monitor agent immediately after creating the team (the pattern skill's "Create Team" step). Spawn it BEFORE spawning any specialist/worker agents.watchdog: trueUse the
role frommonitor
.$CLAUDE_PLUGIN_ROOT/config/swarm-roles.yamlRead
frommonitor_cron_interval_seconds
(default: 60). Include the resolved interval in the monitor's spawn prompt.$CLAUDE_PLUGIN_ROOT/.claude-plugin/settings.json
:namemonitor
: from the monitor role config (typicallysubagent_type
)Explore
:run_in_backgroundtrue
:prompt- Identity: "Your name is monitor. You are part of team {team_name}."
- Immediately send a "Monitoring started" message to the team lead via SendMessage (this satisfies the idle hook gate)
- Call CronCreate with:
: {monitor_cron_interval_seconds} (read fromintervalSeconds
, default 60)$CLAUDE_PLUGIN_ROOT/.claude-plugin/settings.json
: "Check TaskList for anomalies: tasks stuck in_progress, idle workers without findings, failed or blocked tasks. Send a SendMessage alert to the team lead for each anomaly found. Do not intervene directly — report only."prompt
- Do not intervene directly — report to the lead
The monitor does not get its own task — it observes and reports. Include the monitor in shutdown (send
to it).shutdown_requestPattern skills do NOT spawn the monitor. This section is the single source of truth for monitor spawning.