/flow-extras:auditfrom flow-extras
Stage-gated parallel code audit for a whole codebase or module: recon → 6 parallel detection agents (correctness, security, performance, design, tests, style) → dedup + triage → user approval gate → fix planning → second approval gate → serialized apply with revert-on-failure → verification. Use for whole-codebase/module debt inventory, health checks, modernization, production-readiness sweeps, or quality audits. Triggers on: /audit, audit this codebase, audit repo, find tech debt, pay down debt, code health check, make production-ready, refactor everything, apply clean code, quality sweep. Do NOT use for: single-PR or branch review ≤10 files (use /pr-reviewer), one-file cleanup (use /simplify), bug fix (use /fix), feature work (use /flow:next), style-only formatting (run the formatter), or uncommitted-change review (use /review). Scope threshold: whole-codebase or whole-module only — not for incremental branch work.
Ships in flow-extras. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them; scripts run unread.
Auditing a codebase badly makes it worse. You produce 200 findings, the user reads 10, fixes 3, and ignores the rest. Or an agent "cleans up" intentional code and the build breaks. This skill enforces the discipline that keeps audits useful: hot-spot-first entry, bounded parallel detection, hard budget caps, user approval gates before any change, serialized fixes with revert-on-failure, and separate contexts for detect vs. fix.
"An agent that simultaneously detects and fixes has no opportunity for human review between 'this looks wrong' and 'I changed it'. Trust destroyed." — core principle, non-negotiable.
Before running Phase 0, think about the user's actual goal. The answer changes the budget allocation across dimensions and which findings get priority at Phase 2. The Phase 2 scoring formula is severity_weight × confidence, but the pre-flight goal tilts which dimensions' findings reach the budget cap first.
category: security and category: correctness first (ranked by severity_weight × confidence within each category), then fill remaining slots from other categories by score. Performance matters only for user-facing latency.category: design and category: tests first. Set all Phase 4 fix_eligibility to review-required or discussion — no auto-fix path. The audit is a MAP of where to look, not a fix plan.local blast radius with mutation-score > 70% coverage.failure_scenario clarity and blast-radius impact, not severity alone. One killer example beats ten nitpicks.If the user's goal is unclear, ask ONE clarifying question before starting. Record the goal in plan.md — Phase 2 step 8 reads it to apply the category promotion above.
All audit state lives in .audit/ at the project root. This is persistent across sessions — a paused audit can be resumed. If .audit/ already exists when the skill starts, ASK the user: "Resume previous audit or start fresh?" before touching anything.
.audit/
├── recon.txt # Phase 0 output
├── plan.md # which dimensions, which agents, which scope
├── findings-raw/ # Phase 1 — one JSON file per agent
│ ├── correctness.json
│ ├── security.json
│ └── ...
├── findings-consolidated.json # Phase 2 — deduplicated, ranked
├── findings-approved.json # Phase 3 — user-selected subset
├── findings-backlog.json # dropped findings (user can recall)
├── fix-plans/ # Phase 4 — one per approved finding
├── applied-fixes.log # Phase 6 — audit log
└── verification.md # Phase 7 — final report
If the user says "resume", determine the last completed phase from artifact presence and re-enter at the next one. Do NOT re-run completed phases — they're expensive and the existing artifacts are valid.
| Artifact state | Re-enter at |
|---|---|
recon.txt missing | Phase 0 — reconnaissance |
plan.md missing | Phase 0 — re-plan from existing recon |
findings-raw/*.json incomplete (some agents missing) | Phase 1 — re-run ONLY missing agents, do not re-run completed ones |
findings-consolidated.json missing | Phase 2 — dedup from existing raw files |
findings-approved.json missing | Phase 3 — re-present Gate 1 to user from existing consolidated file |
fix-plans/ incomplete | Phase 4 — plan only the approved findings not yet planned |
applied-fixes.log incomplete | Phase 6 — continue from the last applied finding ID, never re-apply |
| all present | Phase 7 — verification (or "audit already complete, re-run?") |
Budget/size-tier is determined by the audited SCOPE (subtree, monorepo package, single subsystem), NOT the total repo size. A single medium package in a huge monorepo uses the medium budget of 15 findings.
These apply regardless of what detection agents claim. No agent override. Internalize before Phase 0.
findings-backlog.json. The user can recall with "show backlog".findings-backlog.json so the user can recall them.(Detection-domain rules — what NOT to flag as findings — live in the Detection anti-patterns section below. This NEVER list covers orchestrator process discipline only.)
Internalize before Phase 0. These are the most common audit noise generators — every finding report with more than three of these loses credibility entirely. Agents that flag them produce noise that trains teams to ignore all audit output.
UserRepository + UserRepositoryImpl never mocked, never swapped = DIP noise. Only flag when substitution is actually needed.console.log / print / dead comments — not debt. Not security. Not audit scope.propose-only, never a primary finding..env.example with placeholder values — if the values are clearly fake, it's documentation, not a leak.failure_scenario — "this might be a problem" is uncitable. Every finding needs input → behavior → failure or it's capped at 0.60 confidence and dropped.failure_scenario that ends with "in the worst case", "could potentially", "an attacker could", or similar hedging is NOT concrete. It's speculation dressed up as evidence. Require the input, the observed behavior, and the exact undesired outcome with no hedging verbs. If the agent cannot phrase it without hedging, it doesn't have evidence.*.d.ts, *_pb.go, *_pb2.py, schema.graphql.ts, OpenAPI SDK output, migration snapshots. These produce finding floods that drown real findings, and there is no actor-owner for the fix (every finding closes as "won't fix — regenerated"). Agents must filter these even if they appear in hot-spots (SDK regeneration produces high churn).Loading discipline: Do NOT pre-load all references at skill activation. References are phase-scoped. Load each reference only when the phase that requires it is reached —
orchestration.mdandfinding-schema.mdat Phase 1 launch,triage.mdat Phase 2 start,finding-schema.mdagain at Phase 3 presentation,fix-safety.mdat Phase 4 start.language-playbooks.mdandsecurity-playbook.mdare loaded by their respective dimension agents, not by the orchestrator.
Architecture note: SKILL.md is the process orchestrator; references carry the domain knowledge. A reference is a tool the orchestrator reaches for, not content that lives in context by default.
Run the reconnaissance script. Do NOT skip this and jump to reading files — you will audit the wrong files.
bash scripts/audit-recon.sh "${PROJECT_DIR:-.}" > .audit/recon.txt
What it produces: detected language stacks, build tools, monorepo structure, size tier (small/medium/large/huge), top-20 hot-spot files by churn × LOC, temporal coupling pairs, test coverage signals, .gitignore hygiene flags.
Hot-spot first, not file-first: Adam Tornhill's principle — complexity is only a problem where there is ALSO high change frequency. Beautiful stable code can wait; messy frequently-changed code is where debt costs real money. The recon output is the input to every other phase.
Monorepo disambiguation: If recon detects nx/lerna/pnpm-workspace/turbo/cargo-workspace/go-workspace, STOP and ask the user which package(s) to audit. Auditing the entire monorepo at once violates the budget cap. Accept user input as any of: filesystem path (packages/api), workspace name (@company/api), or build target (//api:server). Verify the path exists and is non-empty before running recon on it — if no match, re-ask with the list of detected packages.
Size-tier implications:
| Tier | LOC | Findings budget | Agent strategy |
|---|---|---|---|
| small | <5k | 10 | all 6 dimensions |
| medium | 5k-50k | 15 | all 6 dimensions, hot-spot focused |
| large | 50k-500k | 20 | hot-spot top-15, sample by subsystem |
| huge | >500k | 25 per subsystem | audit one subsystem at a time, ask user to pick |
Write plan.md summarizing: stacks detected, size tier, which dimensions will run, hot-spot files, findings budget.
plan.md also carries two tables, so a quiet lens can never be mistaken for full coverage:
| Dir | Why | rows for each top-level dir an agent will read.| Dir | Reason | rows for each top-level dir left out (sampled out by the tier table, generated, vendored). A Skipped row without a reason is rejected.. in either table.## Scanned / ## Skipped heading (a bold **Scanned**: label line also works); rows outside those sections are ignored.Run bash scripts/audit-coverage.sh .audit/plan.md "${PROJECT_DIR:-.}" before launching agents. It compares both tables with git ls-files | cut -d/ -f1 | sort -u, prints UNLISTED:<dir> for each dir in neither table, and exits 1 until the ledger is complete. The size-tier table above is unchanged: medium, large and huge repos still scope to hot-spots or samples, and the ledger records what was left out and why. Only the small tier requires exact-cover slicing, each file read by exactly one agent slice.
Run bash scripts/test-prefilter.sh "${PROJECT_DIR:-.}" > .audit/test-prefilter.txt. Its NO_ASSERTION: and NEAR_DUPLICATE: lines are leads for the tests agent, not verdicts.
Read references/orchestration.md in full before launching agents — wave discipline, agent prompt template, dedup rules, failure modes.
Read references/finding-schema.md in full before launching agents — every agent writes findings in this schema. Schema compliance is validated at Phase 2.
Launch 6 agents in parallel (single message, multiple Agent tool calls). Each agent writes findings as JSON to .audit/findings-raw/<dimension>.json. Each agent is sonnet model, mode: bypassPermissions. Each agent MUST load references/finding-schema.md (schema compliance) plus the specific references in the table below. Do NOT load references from other agents' rows — token waste and scope bleed.
| Dimension | Agent scope | Load (required) | Do NOT load |
|---|---|---|---|
| correctness | type errors, null paths, error handling, contract violations | language-playbooks.md (correctness sections) | security-playbook.md, triage.md |
| security | secrets, dep CVEs, injection, crypto, auth | security-playbook.md | language-playbooks.md, triage.md |
| performance | hot-path allocations, N+1, async blocking, bundle signals | language-playbooks.md (performance sections) | security-playbook.md, triage.md |
| design | hot-spot smells (Fowler), temporal coupling, shallow modules | triage.md | language-playbooks.md, security-playbook.md |
| tests | coverage gaps, brittleness, missing assertions, no mutation signal | (no extra ref — agent prompt template) | all language/security/triage refs |
| style | beyond-formatter inconsistency only | (no extra ref — run formatter check only) | all refs — most findings are dropped as tool-overlap at Phase 2 |
Bounded scope directive — every agent prompt MUST include an explicit "Do NOT cover" clause listing the OTHER dimensions' scope. Without this, findings duplicate.
Facts not opinions: pass only recon facts (hot-spot file list, language, framework) to agents. Never pass severity or classification — let each agent independently score confidence. Severity cascades are a real failure mode.
Wait for ALL agents before proceeding. Check each output file exists and is >20 lines of JSON. Re-run any silent failures.
Second-look pass: once every lens has returned, launch one fresh agent per lens (new context, same scope, same references) that sees the lens's file list and its what_i_checked but not its findings. It writes .audit/findings-raw/<dimension>-second.json (the second-look file). Its job is the quiet miss: a lens that found nothing records what it checked or "not scanned" in what_i_checked, and the second look re-checks exactly that. A single pass over a hot-spot is where silent gaps hide.
Read references/triage.md in full — ranking by business_impact × technical_risk / fix_cost, Fowler quadrant, P0-P3 tiers, when NOT to refactor.
Do NOT delegate this phase to a subagent — synthesis is orchestrator work.
Rules (in order):
file, line_start, severity, confidence, failure_scenario, what_i_checked). A finding that proposes deleting a test is also dropped unless it carries the full retirement card (see finding-schema.md).failure_scenario → confidence capped at 0.60 and labeled question.file + line_range across agents → merge to single finding at highest severity; increment agent_count.pattern_count.question, never auto-fix.severity_weight × confidence (critical=4, major=3, minor=2, nitpick=1), keep top-N where N comes from the size-tier table. Critical + live-secrets + exploited-CVE findings EXCEED the budget (always shown).local (1 file), module (2-5), cross-cutting (6+). Only local is auto-fix eligible.Refute pass (after rule 9): give each surviving finding to a fresh agent whose only job is to disprove it: find the guard, caller, test or comment that makes the failure scenario impossible. A refuted finding goes to the backlog with the refutation attached. For critical findings also run an independent confirm pass in a second fresh context that must reproduce the failure path from the cited lines; a critical finding that is not confirmed drops one tier. Both passes read the code, not the original agent's reasoning, so they do not inherit its mistake.
Dropped findings go to findings-backlog.json (user can recall with "show backlog").
Read references/finding-schema.md in full before presenting §"Report Format" and §"Null Result Format".
Present the ranked, deduplicated findings in Markdown using the template in finding-schema.md. Group by Critical / Major / Cross-Cutting Discussion / Backlog Count.
This gate is not automatable. Do NOT proceed until the user gives a clear answer. "Maybe", "interesting", "looks good" are NOT approval.
Ask: "Which findings should I address? Reply with: all critical, all, 1,3,5, none, show backlog, auto-fix all eligible, or cancel."
Approval vocabulary (parse user input deterministically):
| Command | Behavior |
|---|---|
all critical | Approve all severity: critical findings only |
all | Approve every shown finding |
1,3,5 (comma list of IDs) | Approve only the listed finding IDs |
none / skip | Approve nothing, skip directly to verification summary |
show backlog | Present the dropped findings; then re-ask |
auto-fix all eligible | Approve all AND set auto_fix_opted_in: true — Gate 2 is skipped for fix_eligibility: auto-fix findings, still required for others |
cancel | Abort the audit; leave .audit/ intact for later resume |
Anything else → re-ask. Do NOT interpret "maybe", "interesting", "looks good" as approval.
Null result case: If zero findings survive filters, present the "Clean Audit" template. This IS a success — do not treat silence as failure.
Persist the user's selection to findings-approved.json:
{
"approved_finding_ids": ["C-1", "M-1"],
"auto_fix_opted_in": false,
"approved_at": "<timestamp>",
"user_command": "all critical"
}
Read references/fix-safety.md in full — safe-refactoring decision tree, auto-fix precondition stack, "safe-looking" refactorings that break code.
Orchestrator pre-screening (before spawning any fix agent): The auto-fix eligibility decision is fragile — a misclassification bypasses Gate 2 and risks applying changes without human review. The orchestrator must deterministically evaluate these conditions from existing artifacts BEFORE delegating to a fix agent:
| Condition | How orchestrator checks | If fails |
|---|---|---|
1. confidence ≥ 0.85 | Read from findings-approved.json | → review-required |
2. blast_radius == local | Read from findings-approved.json | → review-required |
| 5. NOT in auth / payments / PII / data deletion | Grep target file for auth/, payment, pii, delete.*user, drop.*table, rm -rf, session / token / credential keywords; if any match → review-required regardless of agent opinion | → review-required |
| 6. NOT a public API / exported symbol | Check if file path matches src/index.*, **/api/**, **/public/**; grep for export on target symbol | → review-required |
| 7. NOT in code with explanatory comment | Read target file, check for // intentional, # audit-ignore, /* explains */ within 5 lines of finding | → review-required |
| 8. NOT same file as another approved finding | Scan findings-approved.json — if two approved findings share a file, both go to review-required (serialization forces review to avoid patch conflicts) | → review-required |
For the findings that pass pre-screening, spawn a fix-planning agent with a FRESH context that sees ONLY: the finding body, the target file, and fix-safety.md. The agent evaluates only the remaining two conditions:
safe-to-automate refactorings in fix-safety.md; NOT in the "looks safe but breaks code" list.auto_fix_opted_in: true).Both must hold for fix_eligibility: auto-fix. Otherwise the agent downgrades to review-required or discussion.
Each fix plan records: proposed diff, blast radius, which preconditions hold (pre-screened by orchestrator vs evaluated by agent), and the final fix_eligibility:
auto-fix — all 8 conditions holdreview-required — needs user to see the diff before applyingdiscussion — cross-cutting or architectural; cannot be fixed mechanically. Skill presents but does not propose a mechanical fix.This gate is the last stop before destructive operations. It must be at least as deterministic as Gate 1.
Skip conditions — a fix skips Gate 2 ONLY when ALL of these hold:
fix_eligibility: auto-fix (all Phase 4 preconditions held)findings-approved.json.auto_fix_opted_in == true (user explicitly said auto-fix all eligible at Gate 1)Otherwise, present each approved fix as a reviewable diff block:
[F-N] <finding subject> [blast_radius: local | module | cross-cutting]
--- <file>
+++ <file>
<unified diff of proposed fix>
Approve, reject, or edit? Reply:
`approve` — apply this fix as-is
`reject` — skip this fix, mark as "user declined"
`edit: <instruction>` — SPAWN A FRESH fix-planning agent with the original finding + current diff + user's edit instruction, then re-present the revised patch at Gate 2. The orchestrator does NOT revise the patch inline — that would reintroduce confirmation bias on the already-reviewed diff, violating the scanner/fixer/verifier isolation principle
`cancel` — abort Phase 6 entirely, leave all remaining fixes unapplied
Record each Gate 2 decision in findings-approved.json under the finding's gate2_status field: approved, rejected, edited, or cancelled. Do NOT proceed to Phase 6 for a finding until its gate2_status is set.
For discussion findings, Gate 2 behaves differently — the skill presents the cross-cutting concern but does NOT propose a mechanical fix. Ask: "This is a design conversation, not a mechanical fix. Note it, dismiss it, or create a ticket?"
Never parallelize fixes. Fix-ordering conflicts on shared files are a real failure mode — fix A changes line numbers, fix B's patch no longer applies.
Protocol for each approved fix, in strict order. The working tree MUST be clean before each iteration — check git status --porcelain first.
git status --porcelain must be empty. If not, STOP — there are uncommitted changes from a prior fix or human edit.git checkout -- <changed-files>, mark the finding "fix attempt failed", escalate. Do NOT commit a broken fix.refactor(audit): <finding-summary> [audit/<finding-id>]. Use refactor: for semantic-preserving, fix: for bug fixes, chore: for tidyings. ONE fix per commit.applied-fixes.log: finding ID, commit SHA, tests-before, tests-after, timestamp.Always test BEFORE committing. The revert at step 5 uses git checkout -- (discards uncommitted changes), not git reset --hard HEAD~1 (which would reset an already-committed state). If the fix has already been committed when a test regression is detected later, use git revert HEAD --no-edit (safer than hard reset because it creates a revert commit and preserves history).
Two-attempt rule mechanics:
git checkout -- <files>, re-read the target file (it may have changed from a prior fix in the queue), produce a MINIMAL revised patch addressing only the same finding, apply once more.Cascade failure threshold: if ≥50% of approved fixes fail both attempts, STOP the apply phase immediately. Present to the user:
"N of M approved fixes failed to apply cleanly — the codebase likely has interdependencies that static analysis missed. Options:
continue(attempt remaining fixes one-by-one with your review),abort(leave remaining fixes unapplied), orreplan(re-run Phase 4 with the failed fixes as additional context)."
This prevents the scenario where an audit consumes significant user attention while producing minimal net improvement.
Spawn a separate verifier agent (fresh context, never the detection or fix agent). Give it: the original finding list, the applied-fixes log, the changed files. It verifies each approved finding is actually resolved by rereading the code.
For each applied fix the verifier also returns TARGETED, NO_NEW_VULNERABILITY and BEHAVIOUR_UNCHANGED, each CONFIDENT, NOT_CONFIDENT or UNSURE with one file:line or test-name line, plus untested=true when no shipped test other than one added by the fix runs the changed function's other callers. A change in which inputs are accepted, beyond the bug's own input, is NOT_CONFIDENT on BEHAVIOUR_UNCHANGED. Any claim that is not CONFIDENT lands the finding under "Remaining for human"; untested=true is listed beside it.
Output .audit/verification.md:
Present a 5-line summary to the user. Done.
references/finding-schema.md (opens in a new tab)references/fix-safety.md (opens in a new tab)references/language-playbooks.md (opens in a new tab)references/orchestration.md (opens in a new tab)references/security-playbook.md (opens in a new tab)references/triage.md (opens in a new tab)scripts/audit-coverage.sh (opens in a new tab)scripts/audit-recon.sh (opens in a new tab)scripts/test-prefilter.sh (opens in a new tab)What SKILL.md sets; muted values are Claude Code's defaults
Other plugins' skills for the same job
npx claudepluginhub tomaspalsson/flow --plugin flow-extras20 skills in this plugin
/babysitDrive one open pull request, or several independent ones, toward merge-ready after flow ships a draft: fix failing CI and resolve merge conflicts. Use when asked to babysit a PR, get it green, fix the CI, resolve the conflicts, or check on one or more PRs. Modes: check (one read-only report) or drive (loop until CI is green and the PR merges clean, or a hard stop). Open review threads are reported and left to the user. Never merges and never marks a draft ready. Not for opening the PR (use /flow:next), not for reviewing someone else's PR (use /pr-reviewer), not for diagnosing a bug from scratch (use /flow:fix)./benchmark-checklistVet a measured number before reporting or acting on it: a speedup, regression, latency, throughput or p95 claim, a before/after in a PR body, or a choice between two libraries or configs based on a run. Names what limits the number, checks warm vs cold, errors, repeated runs with range, end-to-end relevance and a same-way baseline, then gives a verdict (faster, slower, no difference, inconclusive). Also holds the order to try performance fixes in. Not for finding why code is slow with no number yet (use /flow:fix) and not for eval-score significance (use agent-evals)./better-planPresent a plan, design, proposal, or architecture as a polished, interactive, REVIEWABLE page instead of flat markdown — using the locally-installed `better-plan` CLI. Use WHENEVER you are about to show a human a plan they will read and approve: a build/implementation plan, a design doc, an architecture proposal, an API design, a migration plan, an RFC, or a "here's what I'm going to do" before starting work. Renders MDX with diagrams, interactive API specs, annotated code, wireframes, decision records, comparison matrices, timelines, and more, and gives the reviewer an in-page Approve / Request-changes control you can poll. Triggers on - better-plan, /better-plan, "write a plan", "show me the plan", "render the plan", "make a visual plan", "plan this out", "design doc", "proposal", "before you build", "present the plan", "let me review the plan", "plan I can approve", "make the plan readable". Do NOT use for - a one-line answer, a quick code diff, or work you are executing rather than proposing.