Claude Swarm
Runs a parallel "swarm" of specialized subagents over a codebase, each scoped to a
narrow category of issue, then synthesizes their raw findings into one deduplicated,
severity-ranked action plan. Optionally executes fixes for approved findings.
Commands
/swarm audit [path] — run the full audit (default path: repo root)
/swarm status — show the last audit summary from persisted state
/swarm execute <severity|id> — fix findings matching a severity tier (critical/high/medium/low) or a specific finding id
/swarm show <id> — show full detail for one finding
State file
All findings persist to .claude/swarm-audit.json at the repo root (create the
.claude/ dir if missing). This lets /swarm execute run in a later session without
re-auditing, and lets /swarm status answer instantly. Always read this file first
if it exists and the user references "the audit" or "findings" without re-running one.
Schema for this file is in references/output-schema.md.
/swarm audit [path] workflow
Scope check. If no path given, default to repo root, but if the repo is large
(rough heuristic: >150 files or the user hasn't specified), ask the user to confirm
scope or suggest a subdirectory. Don't silently audit a massive monorepo — cost and
time scale with size.
Spawn the five audit agents in parallel. Use a single message with five Task
tool calls so they genuinely run concurrently. For each, read the corresponding
agents/*.md file and pass its full contents as the subagent's instructions, plus:
- the repo path/scope for this run
- the shared output schema from
references/output-schema.md
- explicit tool restriction: read-only tools only (Read, Grep, Glob, and a
bash command runner if restricted to read-only commands like
git log,
git blame, test runners in check-mode). Do NOT give audit agents Write/Edit —
the audit phase must not touch files.
Agents to spawn:
agents/security.md
agents/performance.md
agents/tests.md
agents/architecture.md
agents/dead-code.md
Collect raw findings. Each subagent returns a JSON array matching the schema.
If a subagent's output doesn't parse as valid JSON, re-prompt it once asking for
schema-conformant output only; if it fails twice, drop it and note the gap to the
user rather than blocking the whole audit.
Spawn the synthesizer agent (agents/synthesizer.md) with all raw findings
concatenated. The synthesizer:
- deduplicates overlapping findings (e.g. the same auth gap flagged by both
security and architecture agents) — keep the more specific one, merge notes
- assigns/normalizes severity using
references/severity-rubric.md
- orders the final list by impact-weighted-by-effort, not just severity
- assigns each finding a short stable id (e.g.
SEC-01, PERF-03)
Persist the synthesizer's output to .claude/swarm-audit.json, overwriting any
prior audit for that path (keep the previous file as .claude/swarm-audit.prev.json
for one generation of history, no more).
Present a summary to the user — not the full JSON. Format:
Swarm audit complete — <path>
Found 47 issues.
🔴 Critical: 2 🟠 High: 7 🟡 Medium: 18 ⚪ Low: 20
Recommended order:
1. [SEC-01] Fix authentication token vulnerability — auth/session.py:88
2. [PERF-02] Fix database connection leak — db/pool.py:41
3. [PERF-05] Remove N+1 query — api/orders.py:112
...
Run /swarm execute critical to fix the top tier, or /swarm show <id> for detail.
Keep this to the top ~10 items inline; point to the state file / /swarm show for
the rest rather than dumping all 47 into chat.
/swarm execute <severity|id> workflow
- Read
.claude/swarm-audit.json. If missing, tell the user to run /swarm audit
first — do not fabricate findings.
- Filter to the requested severity tier (or single id).
- Confirm with the user before making changes if this is the first execute call
in the session, or if the tier includes more than ~5 findings — briefly list what
will be touched.
- Fix findings one at a time, serially (not parallel — concurrent edits across
agents risk file conflicts and inconsistent partial states). For each:
a. Spawn a fix agent scoped to just that one finding (file + line + issue +
suggested_fix from the record), with Read/Edit/Write tools this time.
b. After the edit, run the project's test command (detect from package.json /
Makefile / pytest.ini / etc., or ask the user if ambiguous).
c. If tests pass: mark the finding
status: "fixed" in the state file, move on.
d. If tests fail: revert the edit, mark status: "failed", note the failure
reason, and continue to the next finding rather than aborting the whole run.
- Report a final summary: fixed / failed / skipped counts, and surface any failed
items with the test failure reason so the user can look at them manually.
Design principles
- Read-only during audit, edit only during execute. Keeps the audit deterministic
and re-runnable, and means a bad audit run can never corrupt the repo.
- Structured output only. Every subagent must return the JSON schema, not prose —
this is what makes synthesis and persistence tractable. Reject free-text findings.
- Serialize the fixes. Parallelism is for finding issues, not for editing
files. Never spawn multiple fix agents concurrently.
- Persist between sessions. Claude Code sessions end; the audit shouldn't have to
be redone because the user closed their terminal.
- Don't silently re-scope. If the user says
/swarm audit with no path on a huge
repo, ask rather than guessing — a full swarm on a monorepo is expensive.
1---2name: swarm3description: Run a multi-agent audit of a codebase by spawning specialized parallel subagents (security, performance, tests, architecture, dead-code), then synthesize their findings into a single prioritized action plan. Use this whenever the user runs /swarm, asks to "audit the repo," "review this codebase," "find issues across the project," wants a comprehensive multi-angle code review, or asks what to fix first in a large or unfamiliar codebase. Also use for /swarm execute to have Claude fix the findings one at a time. Do NOT use this for a single-file review or a narrow bug fix — this skill is for repo-wide, multi-dimensional audits.4---56# Claude Swarm78Runs a parallel "swarm" of specialized subagents over a codebase, each scoped to a9narrow category of issue, then synthesizes their raw findings into one deduplicated,10severity-ranked action plan. Optionally executes fixes for approved findings.1112## Commands1314- `/swarm audit [path]` — run the full audit (default path: repo root)15- `/swarm status` — show the last audit summary from persisted state16- `/swarm execute <severity|id>` — fix findings matching a severity tier (critical/high/medium/low) or a specific finding id17- `/swarm show <id>` — show full detail for one finding1819## State file2021All findings persist to `.claude/swarm-audit.json` at the repo root (create the22`.claude/` dir if missing). This lets `/swarm execute` run in a later session without23re-auditing, and lets `/swarm status` answer instantly. Always read this file first24if it exists and the user references "the audit" or "findings" without re-running one.2526Schema for this file is in `references/output-schema.md`.2728## `/swarm audit [path]` workflow29301. **Scope check.** If no path given, default to repo root, but if the repo is large31 (rough heuristic: >150 files or the user hasn't specified), ask the user to confirm32 scope or suggest a subdirectory. Don't silently audit a massive monorepo — cost and33 time scale with size.34352. **Spawn the five audit agents in parallel.** Use a single message with five Task36 tool calls so they genuinely run concurrently. For each, read the corresponding37 `agents/*.md` file and pass its full contents as the subagent's instructions, plus:38 - the repo path/scope for this run39 - the shared output schema from `references/output-schema.md`40 - explicit tool restriction: **read-only tools only** (Read, Grep, Glob, and a41 bash command runner if restricted to read-only commands like `git log`,42 `git blame`, test runners in check-mode). Do NOT give audit agents Write/Edit —43 the audit phase must not touch files.4445 Agents to spawn:46 - `agents/security.md`47 - `agents/performance.md`48 - `agents/tests.md`49 - `agents/architecture.md`50 - `agents/dead-code.md`51523. **Collect raw findings.** Each subagent returns a JSON array matching the schema.53 If a subagent's output doesn't parse as valid JSON, re-prompt it once asking for54 schema-conformant output only; if it fails twice, drop it and note the gap to the55 user rather than blocking the whole audit.56574. **Spawn the synthesizer agent** (`agents/synthesizer.md`) with all raw findings58 concatenated. The synthesizer:59 - deduplicates overlapping findings (e.g. the same auth gap flagged by both60 security and architecture agents) — keep the more specific one, merge notes61 - assigns/normalizes severity using `references/severity-rubric.md`62 - orders the final list by impact-weighted-by-effort, not just severity63 - assigns each finding a short stable id (e.g. `SEC-01`, `PERF-03`)64655. **Persist** the synthesizer's output to `.claude/swarm-audit.json`, overwriting any66 prior audit for that path (keep the previous file as `.claude/swarm-audit.prev.json`67 for one generation of history, no more).68696. **Present a summary to the user** — not the full JSON. Format:7071 ```72 Swarm audit complete — <path>7374 Found 47 issues.75 🔴 Critical: 2 🟠 High: 7 🟡 Medium: 18 ⚪ Low: 207677 Recommended order:78 1. [SEC-01] Fix authentication token vulnerability — auth/session.py:8879 2. [PERF-02] Fix database connection leak — db/pool.py:4180 3. [PERF-05] Remove N+1 query — api/orders.py:11281 ...8283 Run /swarm execute critical to fix the top tier, or /swarm show <id> for detail.84 ```8586 Keep this to the top ~10 items inline; point to the state file / `/swarm show` for87 the rest rather than dumping all 47 into chat.8889## `/swarm execute <severity|id>` workflow90911. Read `.claude/swarm-audit.json`. If missing, tell the user to run `/swarm audit`92 first — do not fabricate findings.932. Filter to the requested severity tier (or single id).943. **Confirm with the user before making changes** if this is the first execute call95 in the session, or if the tier includes more than ~5 findings — briefly list what96 will be touched.974. Fix findings **one at a time, serially** (not parallel — concurrent edits across98 agents risk file conflicts and inconsistent partial states). For each:99 a. Spawn a fix agent scoped to just that one finding (file + line + issue +100 suggested_fix from the record), with Read/Edit/Write tools this time.101 b. After the edit, run the project's test command (detect from package.json /102 Makefile / pytest.ini / etc., or ask the user if ambiguous).103 c. If tests pass: mark the finding `status: "fixed"` in the state file, move on.104 d. If tests fail: revert the edit, mark `status: "failed"`, note the failure105 reason, and continue to the next finding rather than aborting the whole run.1065. Report a final summary: fixed / failed / skipped counts, and surface any failed107 items with the test failure reason so the user can look at them manually.108109## Design principles110111- **Read-only during audit, edit only during execute.** Keeps the audit deterministic112 and re-runnable, and means a bad audit run can never corrupt the repo.113- **Structured output only.** Every subagent must return the JSON schema, not prose —114 this is what makes synthesis and persistence tractable. Reject free-text findings.115- **Serialize the fixes.** Parallelism is for *finding* issues, not for *editing*116 files. Never spawn multiple fix agents concurrently.117- **Persist between sessions.** Claude Code sessions end; the audit shouldn't have to118 be redone because the user closed their terminal.119- **Don't silently re-scope.** If the user says `/swarm audit` with no path on a huge120 repo, ask rather than guessing — a full swarm on a monorepo is expensive.