Files
kz-tob 4b1b74b181 Give differential-review a trigger, and name every component in its README (#278)
* Give differential-review a trigger, and name every component in its README

differential-review's description listed what it does and never named a
situation, so it competed on capability wording alone. It now closes with
the triggers its own README already documents — reviewing a PR, commit,
or diff; checking whether a change re-introduces a fixed bug; asking what
else a change could break; finding modified code with no test.

The same plugin's README never mentioned adversarial-modeler, which is
what Phase 5 dispatches for HIGH RISK changes. Checking whether that was
isolated turned up more of it, and the sweep found three kinds of gap:

zeroize-audit's agent table was missing three of its eleven agents —
0-preflight, which gates the entire run, plus 5b-poc-validator and
5c-poc-verifier. All three appear in the phase diagram directly above the
table, which is why they read as present.

constant-time-analysis documents the ct-analyzer CLI end to end and never
says the plugin also ships a skill and a command. entry-point-analyzer
lists phrases that trigger its skill but never names the skill or its
command.

Three more READMEs describe their skill without naming it. That matters
most where the skill name is not the plugin name and a user cannot guess
it: chrome-mcp-troubleshooting and interpreting-culture-index.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

* Fix review findings and make the README sweep a gate

The two PoC rows I added to zeroize-audit said Phase 4. The diagram three
lines above them, SKILL.md, and workflows/phase-5-poc-validation.md all
say Phase 5, steps 5a and 5b. "Wave 5a" is a label that exists nowhere.
A debugger consulting the table — the artifact this branch designates as
what runs when — would have opened phase-4-poc-generation.md and found no
validation in it. Also corrected the sentence introducing that table,
which still said 10 agents across 8 phases against 11 across 9, and the
Phase 0 diagram line, which still credited the orchestrator for a gate
the new row credits to 0-preflight.

differential-review's README claimed the agent is "dispatched", and named
it bare in a column whose other rows are namespaced. Nothing dispatches
it: the only instruction is prose in SKILL.md, and a bare subagent_type
fails at runtime. Namespaced both, and corrected the five stale line
counts in the same file — reporting.md is 369 lines, not the ~120 the
token-efficiency section budgets for.

Drop the dead `name: trailofbits:<cmd>` key from five command files.
The three newest command files carry no name: at all, #275 namespaced 22
bare invocations, and this branch documents the `/<plugin>:<cmd>` form —
so the key contradicts the docs it sits next to.

Then make the sweep repeatable. Doing this by hand three times found
eight gaps and missed two more, both of the same shape: a workflow ships
under meta.name, not its filename, so a README citing the filename never
writes the name a reader types. The validator now checks that a README
names every skill, agent, command, and workflow its plugin ships, reading
meta.name for workflows. It refuses a run that inspected zero components,
and six self-test assertions hold it to known-bad fixtures.

It found git-cleanup on its first run: ships as /git-cleanup:git-cleanup-analysis,
README cites workflows/analyze-branches.js four times and that name never.
static-analysis had the same gap for codeql-build.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

* Fix both P2s: the gate was a substring test, and the dispatch was still bare

The README gate ran `name not in text`. That reads as thorough and could
not fail for a large share of what it counted: `draw` was satisfied by
"(draw cards instead)", `semgrep-rule` by the plugin's own name in the
install line, `burp-search` by a `scripts/burp-search.sh` path that is a
different thing, and `audit` by the prose "shared-state struct audit".

Match by kind instead. Commands and workflows are reachable only as
`/<plugin>:<name>`, so require that literal — it is the only string a
user can type. Agents are dispatched by identifier and never typed as
prose, so require an identifier-shaped mention. Skills are genuinely
referred to by bare name, so require only a delimited occurrence, which
is what stops "draws" counting as `draw`.

That surfaced seven real gaps, the four above plus insecure-defaults'
audit-pipeline workflow, mutation-testing's skill, and trailmark's
code-slice-worker. All seven fixed.

adversarial-modeler was still bare at SKILL.md:96. Line 77 was the
decision-tree mention; line 96 is the "Delegate to this agent"
instruction a model actually acts on, so the runtime failure the last
commit claimed to fix survived it. Namespaced, and it now says why.

Also from the review: a per-kind floor, since a single total stays
healthy while skill_files() — 63% of coverage — silently stops matching;
workflow_names anchored to the meta block, because a bare search takes
any earlier `name:` in a comment, and .mjs was invisible; and AGENTS.md
documents the new hard failure. Self-test 88 -> 96, each new rule with a
negative control.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-26 08:54:12 -04:00
..

git-cleanup

A Claude Code slash command for safely cleaning up accumulated git worktrees and local branches.

What It Does

Analyzes your local git repository and sorts branches and worktrees into:

  • Delete candidates: merged into the default branch (-d), or squash-merged or superseded with a named PR or commit as evidence (-D)
  • Needs review: work that could not be located in the default branch, including [gone] remotes and any candidate a skeptic managed to refute
  • Keep: unpushed commits, untracked local work, or level with a live remote
  • Unanalyzed: branches no verdict came back for, listed explicitly so a partial run never reads as a complete one

The command is gated: it requires explicit user confirmation before any deletion.

How It Works

Analysis runs as a dynamic workflow — a JavaScript orchestration script that coordinates subagents:

  1. Survey — one agent inventories branches, worktrees, tracking state, and recent merge history.
  2. Triage — the script decides, in plain JavaScript, everything git can already prove: merged branches, branches with unpushed commits, branches level with a live remote. No agent is spawned for a question git branch --merged already answers.
  3. Investigate — batched agents hunt for merge evidence on the branches that remain ambiguous, mostly [gone] remotes and groups of similarly-named branches. Related branches go to one agent so supersession is visible.
  4. Refute — every delete candidate goes to a skeptic whose job is to find a commit that is not in the default branch. A refuted candidate is downgraded to "needs review", never deleted.

Typical runs are small: a repo with a dozen branches spawns about three agents, because the triage in step 2 decides most of them without spawning anything. Eleven is the ceiling, not the norm — one survey, at most five investigators, at most five skeptics — and past five batches the batches grow rather than the agent count, so the number stops rising even as the repository gets messier. Tokens still scale with the number of ambiguous branches; it is the coordination cost that is capped, not the reading.

The workflow is strictly read-only. Both confirmation gates and every git branch -d/-D and git worktree remove run in the main session, because subagents have no way to ask the user anything.

When to Use

Invoke with /git-cleanup when you have accumulated many local branches and worktrees that need cleanup.

Important: the command sets disable-model-invocation: true, so Claude cannot invoke it on its own — it runs only when you type it. That flag is what closes autonomous invocation; the description in the frontmatter is matchable text and would otherwise let a cleanup-shaped request trigger a plugin whose job is git branch -D.

Safety Features

  • Two confirmation gates (analysis review, then deletion confirmation), both in the main session
  • Safe delete (git branch -d) for branches git itself reports as merged; force delete (git branch -D) only for squash-merged and superseded branches, where git compares shas and cannot see that a squash carried the work across
  • Every squash-merged or superseded candidate must survive a skeptic tasked with finding a commit the claim cannot account for — tested against whatever the claim named, the default branch for a PR or commit and the superseding branch for a supersession. Refuted, unverified, missing a verdict, and lost-to-a-failed-agent all fall back to needs-review. SAFE_TO_DELETE is the one category that skips this. It does not rest on git branch -d catching a mistake at execution time: -d accepts a branch merged into HEAD or into its own upstream, neither of which is "merged into the default branch". Instead each entry names its tip commit in its evidence, for a human to check at gate 1, and ships a verifyWith precondition — git merge-base --is-ancestor 'refs/heads/<branch>' '<default>' — which the main session runs immediately before the delete and skips the delete on failure. The precondition names the branch rather than the reported sha, so it cannot pass on a stale or transposed commit while the branch itself was never merged. The category is still pinned to -d and never -D
  • A [gone] remote is treated as a question, not an answer: the branch is investigated, and it only becomes a delete candidate once a specific PR or commit is named and that claim survives refutation
  • Blocks removal of worktrees with uncommitted changes
  • Never touches the current branch, the repository's actual default branch whatever it is called, or any long-lived integration or environment branch — main, master, trunk, develop, dev, integration, staging, production, preprod, qa, uat, next, canary, stable and release/*, hotfix/*, support/*, maint*/* among them, matched case-insensitively. Filtered by a regex in the script, not by instructions to a model: an agent can be talked out of a rule, a regex cannot
  • Protected branches are excluded from analysis but not from the report: they come back under keep as PROTECTED, carrying their unpushed-commit count. Never deletable and never mentioned are different guarantees, and only the first one is wanted — a staging branch with unpushed work on it has to stay visible

Installation

claude plugins:add trailofbits/skills/git-cleanup

Layout

Path Role
commands/git-cleanup.md The /git-cleanup entry point: gates, confirmations, and the deletions
workflows/analyze-branches.js The dynamic workflow, shipping as /git-cleanup:git-cleanup-analysis — workflows are namespaced by meta.name, not the filename. Read-only — it never deletes
references/merge-evidence.md What counts as proof a branch is merged, read by the agents and the fallback path
tests/analyze-branches.test.mjs Stubs every agent and asserts the triage, clustering, and failure handling
evals/ End-to-end evals: does the model produce a correct gate-1 analysis on a real repository?

The suite runs in CI and under make check via the js-tests target, which fails if it discovers no *.test.mjs files. To run just this one:

node plugins/git-cleanup/tests/analyze-branches.test.mjs

Tests vs evals

The two cover different halves, and neither substitutes for the other:

  • tests/ stubs every agent and asserts the JavaScript in analyze-branches.js — triage, clustering, protected-branch filtering, failure handling. Deterministic, free, and blind to what the model actually does with the result.
  • evals/ runs the real model against a real repository and grades the gate-1 analysis: does unpushed work stay in Keep, does every delete candidate name its evidence, does anything get deleted before the user answers. See evals/README.md.
make eval-self-tests  # free; proves the graders still fire. Part of `make check`
make evals           # the real suite — costs API calls, opt-in only

Example

User: /git-cleanup

Claude: [Runs the workflow: survey, then investigates 4 ambiguous branches,
         then refutes 3 delete candidates]

        GATE 1 — analysis

        Safe to delete (merged, -d)
        | fix/typo      | merged into main                                |

        Safe to delete (squash-merged / superseded, -D)
        | feature/auth  | PR #42, no unaccounted commits                  |
        | feature/api   | PR #29, no unaccounted commits                  |

        Needs review
        | bugfix/login  | claimed PR #51, refuted: commit 9ab2c1e missing  |
        | experiment/x  | remote gone, work not found in main             |

        Keep
        | wip/parser    | 5 unpushed commits                              |

        Worktrees
        | ../proj-auth  | feature/auth | STALE (merged)                   |

        Which would you like to clean up?
        [Delete all recommended] [Pick categories] [Pick individual branches]

User: [Delete all recommended]

Claude: GATE 2 — I will execute:

        # Worktrees holding branches being deleted (must come first)
        git worktree remove '../proj-auth'

        # Merged (safe delete, each guarded by its verifyWith precondition)
        git merge-base --is-ancestor 'refs/heads/fix/typo' 'main' && git branch -d 'fix/typo'

        # Squash-merged and superseded (force delete)
        git branch -D 'feature/auth'
        git branch -D 'feature/api'

        Confirm? (yes/no)

User: "yes"

Claude: Deleted fix/typo, feature/auth, feature/api, worktree ../proj-auth.
        Kept wip/parser. bugfix/login and experiment/x still need review.

Three things in that transcript are load-bearing: every delete candidate arrives with its evidence attached so you can audit it, bugfix/login was demoted because a skeptic found a commit its merge claim could not account for, and gate 2 lists exact commands with the flag each branch actually needs rather than a list of names.