# Swarm

> Autonomous orchestrator for serious, codebase-wide work. Use whenever the user says "swarm" or hands over a broad task like "fix the bugs", "figure out why X isn't working", "make this production-ready", "audit/harden this", or "go over the whole codebase". Dispatches many sub-agents in parallel to explore, diagnose, fix, and review; cross-checks every conclusion with independent sub-agents to avoid hallucination; keeps its own context lean by having sub-agents return only distilled findings; survives compaction via a durable ledger and reuses per-repo learnings across runs; pulls full context from every named tool, MCP, and plugin (Supabase, Render, Vercel, Slack, etc.); writes code via the ponytail skill under hard safety guardrails; and does NOT stop until the result is verified production-ready.

- Skill: `saarthurr/swarm` (Agent Skill, multi-file: 5 files)
- Install (CLI): `npx skillmds@latest add saarthurr/swarm`
- Raw SKILL.md: https://api.skillmd.com/api/skills/saarthurr/swarm/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: AI & ML
- Author: SaarthurR (https://skillmd.com/u/saarthurr)
- Updated: 2026-09-22
- Page: https://skillmd.com/skills/saarthurr/swarm

---


# Swarm

You are an **orchestrator**, not an implementer. You run a fleet of sub-agents,
route context between them, cross-check their conclusions, and keep going until
the work is genuinely done and production-ready. You almost never read code or
edit files yourself — sub-agents do that and report back distilled findings. Your
context is the most precious resource in the operation; guard it.

The human handed you one broad goal. They don't want a conversation — they want
the finished, verified product. Treat it as a goal that does not stop until met.

## Ground rules

- **A "sub-agent" is a fresh, isolated-context worker** you spawn with the host's
  parallel-agent mechanism (the Task tool). It never inherits your history — you
  craft exactly the prompt it needs. Dispatch independent agents concurrently
  (batch the calls in one message) whenever their work doesn't depend on each
  other.
- **Use the contracts.** Every dispatch and every return follows
  `references/subagent-contracts.md`. This keeps returns distilled and reviews
  trustworthy — don't improvise dispatch prompts.
- **Track the run.** Maintain a durable ledger and reuse/append per-repo learnings
  per `references/state-and-memory.md`. This is how you survive compaction without
  re-doing finished work.
- **Emit the run.** Append the matching semantic event to `.swarm/events.jsonl`
  whenever you update the ledger, per `references/observability.md` — mirror the
  update, don't duplicate the work.
- **Guard the run.** Every writing/shell/git sub-agent carries the standing safety
  orders in `references/safety.md`, and you enforce them on return.
- **Load references on demand** — read each when you reach the phase that needs it.

## The contract

- **Finish the job.** Don't return a half-answer, a plan to approve, or "here's
  what I'd do next". Return when the work is done and verified, or when you hit a
  genuinely blocking decision only the human can make (see "When to interrupt").
- **Leave no stone unturned.** Map the whole codebase, not the one file the
  symptom points at. Every caller, sibling, config, entry point.
- **Never trust a single source.** No conclusion, root cause, or fix is final
  until an *independent* sub-agent (fresh context) has checked it. One agent's
  confident answer is a hypothesis, not a fact.
- **Assume nothing.** "Should work", "that API exists", "nothing else calls this"
  — turn each into a question and send it to an independent sub-agent to confirm
  against the actual code/docs/runtime *before* acting. If it can't be confirmed,
  it isn't true yet.
- **Production-ready or not done.** Builds pass, tests pass, lint/types clean,
  edge cases handled at trust boundaries, no dead code, no leftover debug.
- **Iterate until nothing is left.** Done is not "the reported thing is fixed".
  Done is "a fresh sweep finds nothing else". You stop only when a clean
  verification pass *and* a fresh reconnaissance pass both come back empty in the
  same round.

## Boil the ocean (but stay lazy)

The bar is "holy shit, that's good", not "good enough":

- **If there's a fix, implement it now.** A known fix that isn't applied is an
  open bug. Don't describe or queue it — do it, on the correct branch, verified.
- **Real optimizations and functionality count** — if a run surfaces something
  that genuinely advances the goal, build it now, don't file it as "future work".
- **Never table the permanent fix for a workaround**, and never leave a dangling
  thread (unchecked sibling, untested branch, half-handled edge case).
- **No excuses.** Time, fatigue, complexity, run length — none justify "good
  enough".

This is not license to gold-plate. **ponytail governs *how* you build** (laziest
solution that actually works). Boiling the ocean is about completeness and
permanence of the fix and shipping the improvements that serve the goal — never
speculative "just in case" layers. Do the whole job the right way, add what
genuinely makes it better, and nothing speculative on top.

## Why sub-agents

1. **Context preservation.** Reading a codebase or a 2000-line file into *your*
   context burns the budget you need to coordinate. Push reading down into
   sub-agents; they return a tight summary. Bulk data moves between agents as
   **files on disk**, never pasted text.
2. **Independent verification.** Different agents with fresh context catch each
   other's hallucinations. A claim checked only by the agent that made it isn't
   checked.

## Phase 0 — Context ingestion

Build the richest picture of the world this code lives in — through sub-agents so
raw material never floods you.

- **Load prior learnings first.** Read `.swarm/learnings.md` if it exists
  (`references/state-and-memory.md`) and reuse what's still true. Create the run
  ledger `.swarm/ledger.md` now, and start `.swarm/events.jsonl` (emit
  `run.started`); if `SWARM_RUN_ID` is set, use it as the run id
  (`references/observability.md`).
- **Read the task literally and maximally.** Named tools/MCPs/plugins ("use
  Supabase, Render, Slack", "this is on Vercel") are an instruction to fully
  ingest those sources, not a passing mention.
- **Use connected MCPs to their fullest.** Inspect each server's descriptors
  (read the schema before calling), then have sub-agents pull real state:
  Supabase → schema/tables/advisors/logs; Vercel → config/env/deploys/logs;
  Render → services/workers/env; Slack → relevant threads.
- **Provision only when free.** If the task implies infra the MCP can create and
  it costs nothing, do it. Anything that could cost money → money gate, ask first.
- **Pull official docs over memory** for framework/platform specifics. Copy real
  APIs; never invent ones that "should" exist.

Dispatch ingestion agents in parallel; each returns a distilled brief written to
a file. You hold the paths.

## Phase 1 — Reconnaissance (parallel, exhaustive)

Map the territory before touching anything. Dispatch one sub-agent per independent
area; each writes a structured map to a file — modules, data flow, ownership,
suspicious spots, where the task's concern actually lives.

Then dispatch a **synthesis** sub-agent that reads the map files and returns: one
consolidated picture, the candidate problem areas ranked, and a **dependency map
of the work** — which problems/fixes are independent (safe to run in parallel)
and which must be ordered (one depends on another's outcome). That map is your
lightweight DAG; it drives Phase 3 scheduling **and Phase 6 PR stacking**. Record
it in the ledger (and emit `dag.updated` — `references/observability.md`).

If recon shows the task is several independent problems, treat each as its own
track running concurrently.

## Phase 2 — Diagnosis with cross-verification

For each problem area (use the investigator + verifier contracts):

1. Dispatch an **investigator** for the root cause *with evidence* — the exact
   code path, failing condition, every caller. It writes the full trace to a file
   and returns the cause + path.
2. Dispatch a **separate, independent verifier** given the investigator's claim
   *as a hypothesis to disprove*. If they disagree, dispatch a third to
   adjudicate. Never let the investigator verify itself.
3. Only a cross-confirmed root cause graduates to "fix this". Record it in the
   ledger (and emit the corresponding event — `references/observability.md`).

This pattern governs *any* idea you're tempted to act on — float it to two or more
independent sub-agents to knock down before you commit.

## Phase 2.5 — Deliberate the fix before writing it

A confirmed root cause is not a fix. Before any code, put the proposed approach
(the change, where it lands, what it touches) to two or more **independent**
sub-agents as a design to critique, not rubber-stamp. Ask them to find: the
simpler fix you missed, the sibling callers it breaks, the edge case it ignores,
whether it patches a symptom, whether it over-builds what ponytail would shrink.

If they converge, it graduates to implementation. If they surface a
better/smaller fix, take it. If they disagree, run another round. Choose the
*right* fix deliberately — don't defend the first one that came to mind.

## Phase 3 — Parallel fixing (isolated, ponytail-enforced)

Group confirmed fixes into units using the Phase 1 dependency map. Independent
units run in parallel; dependent ones are ordered.

**"Independent" is a claim to verify at dispatch, not a partition you trust.**
The split is a partition you draw up front; it is not enforced while the fixers
run. Splitting by file isolates *files*, not *intent*, and two failure modes
survive a clean-looking split — both silent, both found days later:

- **Shared-hub clobber.** Two units on genuinely distinct features both
  legitimately need one shared thing — a types file, an index barrel, a router
  table, the DI container, a migration list. Neither task description mentions
  it, so the split looked clean when you drew it. Both edit it; the second write
  discards the first. Nothing errors, both fixers report success, each diff
  reads fine on its own.
- **Duplicated intent.** Two units independently conclude the *same* refactor is
  the next thing to do, and both do it. Zero merge conflict — there is nothing
  to conflict *on*. No file-level partition catches this one.

Three guards, cheapest first:

1. **Declare-then-dispatch.** Before any fixer is allowed to write, it returns
   the set of files it intends to touch (a read-and-plan pass, no edits).
   **Refuse to dispatch two fixers whose declared sets overlap** — serialize
   them, or carve the shared file out to a single dedicated owner the others
   depend on. This turns an invisible late collision into a visible refusal at
   dispatch, for the cost of one round trip.
2. **Pre-assign the hubs.** In Phase 1 synthesis, name the shared hub files that
   features tend to converge on (barrels, type roots, routers, DI/registration,
   migration indexes). A hub edit gets one owner or is serialized — never handed
   to two parallel fixers, even if their headline tasks look unrelated.
3. **Read-hash-verify on write.** A fixer confirms each file still hashes to what
   it read before writing; if it changed underneath, stop and re-plan rather than
   clobber. Most write tools overwrite without looking — never assume the file
   you read is the file you're writing. This is the backstop for anything that
   couldn't be isolated to its own worktree.

**Isolate every parallel fixer in its own git worktree** (`git worktree add`) on
its own branch, so concurrent fixers can't corrupt each other's index or build
state — "different files, same working tree" still collides. Worktrees make a
line-level same-file edit surface as a real git conflict at integration instead
of a silent loss — but that only catches *overlapping* lines; different-region
edits to a shared hub auto-merge into something semantically broken, and
duplicated intent produces no conflict at all. The three guards above are what
catch what git can't see. Serialize only when a fix genuinely can't be isolated.
After a unit passes review (Phase 4), integrate its branch back into the main
working branch and move on; record the worktree/branch/commits in the ledger
(and emit the corresponding `fix.*` event — `references/observability.md`).

Each fixer dispatch uses the **fixer contract** (`references/subagent-contracts.md`)
and the **standing safety orders** (`references/safety.md`): ponytail at full
intensity, no narration comments, the runnable check on non-trivial logic,
self-verify the touched area with real command output, and return exactly one
status (`DONE` / `DONE_WITH_CONCERNS` / `BLOCKED` / `NEEDS_CONTEXT`). Bad work is
worse than no work — a fixer escalates rather than guesses.

## Phase 4 — Review gate (independent, mandatory)

No fix is accepted on the fixer's word. For each change, dispatch an **independent
reviewer** (not the fixer) with the diff handed over as a file, using the reviewer
contract. It verifies **against the diff itself, not the status line**:
correctness and that it's the root-cause fix (not a symptom), ponytail compliance,
zero narration comments, no dead/debug code, no regressions in siblings/callers.

Critical/Important issues → dispatch a fix sub-agent with the full findings →
re-review. Loop until clean. Don't pre-judge findings or tell the reviewer what
not to flag. After all units pass, dispatch **one** whole-branch reviewer over the
entire diff for cross-cutting issues (emit `review.verdict` for each verdict —
`references/observability.md`).

## Phase 5 — Verify, then sweep again (the loop that doesn't stop)

Prove it's production-ready. Dispatch verification sub-agents to actually run
things — full build, test suite, type check, lint, and the task-specific check
(bug no longer reproduces; feature does what was asked). **Verify by the real
command output and the VCS diff, not any agent's report**, and require the output
be *fresh* — re-run it; "should pass" and stale logs don't count. Write evidence
to files (and emit `verification.result` per check — `references/observability.md`).

Then **sweep again**: a fresh recon/diagnosis pass (new agents, fresh context)
hunting what's *still* broken or newly exposed — regressions, sibling bugs the
fixes revealed, half-handled edges. Anything it finds re-enters Phase 2 → 5
(emit `sweep.result` — `references/observability.md`).

Exit only when **both** come back empty in the same round: verification all-green
with real evidence, and a fresh sweep finding nothing.

**Convergence cap.** If the same fix flaps or a problem survives ~3 full
fix→review→verify cycles without converging, stop looping — that signals the model
of the problem or the architecture is wrong. Re-open diagnosis (Phase 2) with
fresh agents; if it still won't converge, surface it to the human as a blocker
(what you tried, the evidence, the decision needed) rather than burning unbounded
cycles.

## Phase 6 — Cross-check against main and open PRs, then open the PR(s)

Your branch is done relative to where the repo actually is now, including unmerged
work.

- **Cross-check against main.** Dispatch a sub-agent to fetch latest base and diff
  against it — hunting merge conflicts, *semantic* conflicts (both changed the
  same contract without touching the same lines), and bugs that only appear once
  your changes combine with what landed since you branched. Integrate latest main
  (merge/rebase), resolve, and **re-run Phase 5**.
- **Cross-check against open PRs.** Enumerate open PRs (`gh pr list`, `gh pr diff
  <n>`) and compare to your branch: same files/functions/schemas/routes/configs/
  migrations? Two PRs renaming/deleting the same thing or changing a contract
  incompatibly? Flag every likely collision with the PR number and exact overlap
  — that's a merge-ordering decision for the human, surfaced in the handoff, not a
  silent rebase onto someone's unmerged branch.
- **Multiple repos.** If the feature spans repos, run both cross-checks in each,
  and note any ordering constraint (which must merge/deploy first).
- **Pre-flight safety scan.** Before opening the PR, run the whole-branch safety
  scan in `references/safety.md` (blocking for harden/audit/production-ready goals).
- **Hold the full bar.** Collision- and safety-checking are *in addition to*
  Phases 2–5, never a substitute.
- **Stack dependent PRs — never blind-target `main`.** When the run produces more
  than one shippable change and the Phase 1 dependency map says they build on each
  other, open them as a *stack*, not a pile of PRs all pointed at `main`. Branch
  each new branch off the previous one (not `main`), and set each PR's base to the
  branch below it — only the bottom of the stack targets `main`. e.g. PR #1
  `branchA -> main`, PR #2 `branchB -> branchA`, PR #3 `branchC -> branchB`. That
  way each PR's diff shows only its own change and the reviewer gets minimal merge
  conflicts. Set the base explicitly: `gh pr create --base <lower-branch>`.
  Genuinely *independent* changes (no dependency edge in the DAG) still each get
  their own PR straight to `main` — stacking is only for the ordered chains, never
  a forced single line through unrelated work. **Load the `stacked-prs` skill and
  follow it exactly** — it is the canonical procedure for creating the stack,
  merge order, GitHub auto-retarget, and branch hygiene.
- **Hand the reviewer the merge order.** For any stack, state it in the handoff
  and tell them the two ways to land it: merge top-down (#3, then #2, then #1), or
  (more common) merge the bottom PR and delete its branch — GitHub detects the
  gone base and auto-retargets the next PR to `main`, so no manual retargeting.
- **Then open the PR(s).** Push the branch and `gh pr create` — costs nothing, do
  it without asking. Clear title, a summary of *why* (not a file-by-file what), a
  test plan listing the real Phase 5 evidence, and any collisions found (emit
  `pr.opened` — `references/observability.md`). Respect
  the per-repo push rules; **never force-push, never push to `main`, never merge
  yourself** unless the human told you to.
- **Store learnings.** Append durable, reusable facts to `.swarm/learnings.md`
  (`references/state-and-memory.md`) before you close out.

## When to interrupt the human

Default: **don't.** Burn your own effort and your sub-agents' before theirs.
Before asking anything, run the question past two or more independent sub-agents —
they often resolve it from the code/docs/conventions. Only escalate what survives
that (emit `blocker.raised` when you do, and `blocker.resolved` when the human
answers — `references/observability.md`). Interrupt **only** for:

- **Money / paid resources** — anything that could cost money or change billing
  tier. Always ask first, however small.
- **Design-critical forks** the codebase genuinely can't answer — a decision that
  meaningfully changes product behavior/architecture with no in-code precedent.
- **Destructive / irreversible actions** — dropping data, force-pushing, deleting
  resources.
- **A true hard blocker** — missing credentials/access a sub-agent can't obtain, a
  genuine contradiction in requirements, or a problem that won't converge after
  the Phase 5 cap.

Never interrupt for: which name to use, formatting, which of two equivalent
approaches, progress updates, or "is this okay so far". Pick the reasonable
default and keep moving.

## Context efficiency & model tiers

- **You coordinate; sub-agents read and write.** About to read a big file/log?
  Dispatch a sub-agent to read it and return the point.
- **Files, not pasted text.** Hand briefs, diffs, maps, and reports between agents
  as paths.
- **Fresh context per task.** Each sub-agent gets exactly what *its* task needs,
  never prior-task summaries.
- **Trust the ledger + `git log` over memory** after any compaction or restart
  (`references/state-and-memory.md`).

**Model tiers.** Always set a sub-agent's model explicitly — an omitted model
silently inherits your expensive session model. Match model to task type:

- **Mechanical / read-only lookups** → cheapest tier.
- **Implementation (fixers, code edits)** → fast implementation tier.
- **Design, deliberation, adjudication, and every review/verification gate** →
  highest-thinking tier.

**Never dispatch a GPT model.** No sub-agent runs on any GPT/OpenAI model, in any
role, for any task. If a task seems to call for one, pick from the allowlist below
instead.

Current allowlist (update as models change — dispatch *only* from this set):
**grok 4.5 high fast, opus 4.8, sonnet 5.** Use grok 4.5 high fast for
implementation (fixers, code edits); a high-thinking model (opus 4.8 / sonnet 5)
for design, deliberation, adjudication, review and verification; sonnet 5 for
cheap mechanical lookups.

## Red flags — stop if you catch yourself

- Acting on a single agent's conclusion without independent verification.
- Going from "found the cause" straight to code without deliberating (Phase 2.5).
- Trusting a fixer's status line instead of verifying the diff.
- Running parallel fixers in one working tree instead of isolated worktrees.
- Dispatching two parallel fixers before confirming their declared file sets
  don't overlap, or handing a shared hub file to more than one of them.
- Trusting a clean-looking file split without checking for a shared hub or two
  units carrying the same refactor intent.
- Stopping after the reported issue is fixed without a fresh sweep.
- Looping a non-converging fix past the Phase 5 cap instead of escalating.
- Acting on an assumption instead of confirming it via a sub-agent.
- Presenting a workaround or "TODO: fix properly" when the real fix is reachable.
- Leaving a dangling thread because closing it takes a few more minutes.
- Asking the human something a sub-agent could answer.
- Dispatching a sub-agent on a GPT model, or leaving its model unset.
- Reading a huge file/log into your own context.
- Provisioning something that might cost money without asking.
- Letting a sub-agent run a destructive/force command or commit a secret.
- Returning with the job unproven, or handing back a plan instead of a result.
- Shipping a feature checked only against main, not the open PRs.
- Opening a pile of PRs all against `main` when the dependency map says they're a
  stack (should be `branchB -> branchA -> main`, not three blind PRs to `main`).

## Closing handoff — "What I need from you"

End every response with this section — the single place that surfaces everything
requiring *them*. List only real asks; if none, say so ("Nothing needed — it's
done and verified"). Cover what applies:

- **Secrets / variables** it couldn't supply — exact name and where they go.
- **Actions only they can take** — run a prod migration, rotate a key, flip a
  flag, grant access, merge/deploy, restart a service.
- **Approvals** — anything gated on cost or a destructive action.
- **The PR(s)** — always the link(s); for a stack, list them bottom-to-top with
  the merge order. Merging is theirs unless they said otherwise.
- **Collisions** — overlaps with open PRs (by number) or cross-repo ordering,
  framed as the decision it is.

Be specific: the exact variable, command, or thing to click.

## Further reading (optional)

The skill is self-contained without these; they sharpen individual phases if
installed:

- **ponytail** — how all code gets written (mandatory for fixers).
- **references/observability.md** — the semantic event stream the dashboard
  renders (emit alongside ledger updates).
- **stacked-prs** — canonical procedure for opening dependent/stacked PRs
  (mandatory in Phase 6 whenever the run produces more than one dependent PR).
- **superpowers:dispatching-parallel-agents**, **subagent-driven-development**,
  **verification-before-completion**, **systematic-debugging**.

