/patching-bugs:implement-patch <run-dir> <attempt 1-3> [checkout]from patching-bugs
Repairs one confirmed bug where its invariant breaks, inside the finding's repair_scope — before-repair gate, a hunt for same-invariant variants, suite before and after, a regression test seen failing on the unpatched code first, the smallest reviewable fix, then one local `git commit -s` plus fix.patch, tests.patch and patch.json under $TMPDIR. Use when patching-bugs:patching-bugs hands over a patch attempt, or a confirmed finding.json needs that fix. Not for a quick fix with no confirmed finding (just edit the code) nor for judging the commit — use patching-bugs:prove-patch.
Ships in patching-bugs. 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.
None: SKILL.md is the whole skill.
Request: $ARGUMENTS
The reported input is one symptom. Find the rule the code is supposed to keep (the invariant in
finding.json), find every place inside the repair_scope boundary that breaks it the same way,
and restore the rule there with the smallest change a reviewer can read in one sitting. Then
commit once, locally, signed off.
Scripts: ${CLAUDE_SKILL_DIR}/../patching-bugs/scripts/. Record fields:
${CLAUDE_SKILL_DIR}/../patching-bugs/references/records.md.
Write every path in commands literally and absolutely; never put the run directory, the scripts or the checkout in a shell variable. The transcript is part of the evidence.
python3 ${CLAUDE_SKILL_DIR}/../patching-bugs/scripts/records.py check /abs/run --before-repair
Exit 1 → stop and return the error text; the coordinator reports INCONCLUSIVE.finding.json status is confirmed and validate/validate.json says confirmed. Without a
confirmed finding record there is nothing for this skill to do: tell the user to fix it
directly, without this workflow.git status --porcelain empty). HEAD is the baseline for attempt 1, or the last
earlier attempt's patch_commit. Anything else: stop and say what you found.run.attempts equals your attempt number N; your directory is <run>/patch/attempt-N/ and must
not exist yet. Earlier attempt directories are read-only history: read their proof failures, fix
what they found, never rewrite them.
Write down, for yourself: the invariant, the repair_scope.boundary, the exclusions. The threat
model in the guidance tells you what behaviour is intended; it does not limit where you look
inside the boundary, and it is not a reason to skip a case.
Search the baseline code for every path that breaks the same invariant the same way: sibling
functions, other entry points into the same sink, the same helper copied elsewhere, error and
cleanup paths. Grep for the sink and for the pattern, not just the reported function name. Each
hit becomes a variants entry: location (path:line), status fixed or not_fixed, reason
(why it is the same violation, or why it stays: outside the boundary, an exclusion, a deliberate
behaviour). Bugs outside the boundary are not yours this time; list them as not_fixed only if
they break this invariant.
Run the project's own test command in the checkout (e.g. go test -v ./...), saving the full
output to <run>/patch/attempt-N/receipts/suite-before.txt. Count passed, failed and skipped
tests from that file. Go: lines --- PASS:, --- FAIL:, --- SKIP:. Python: pytest's summary
line. Leave no stray files in the checkout (-p no:cacheprovider for pytest).
Write a test in the project's own style and test framework that encodes the invariant for the
reported input and for every variant you will fix (a table-driven test is fine), plus at least one
control that must keep working. Run it before touching production code and save the output to
receipts/regression-test-baseline.txt. It must fail, and fail for the bug, not for a compile
error in the test itself. A test that passes on the unpatched code proves nothing: rewrite it.
Never git stash, git checkout -- <file> or git reset to get back to the unpatched code: the
test comes first, so the code is still unpatched when it runs.
repair_scope must behave as before.Rerun the regression test (now passing) and the full suite into receipts/suite-after.txt.
Compare failures before and after. A new failure is yours to fix. A failure that was already in
suite-before.txt stays, with the receipt as proof that it predates you.
git -C /abs/checkout add <each changed file>
git -C /abs/checkout commit -s -m "fix(<scope>): <what the invariant now guarantees>" -m "<body>"
CLAUDE.md if it sets other rules.-s trailer must match the committer identity. No AI attribution, no co-author lines.patch_commit null. Never
--no-verify, --no-gpg-sign, -c commit.gpgsign=false, --amend of an earlier attempt, or
a second commit.From the baseline, not from HEAD~1 (an attempt may sit on top of earlier ones):
git diff --no-ext-diff --no-textconv <baseline> <patch_commit> -- <production files> into
patch/attempt-N/fix.patch;git diff --no-ext-diff --no-textconv <baseline> <patch_commit> -- <test files> into
patch/attempt-N/tests.patch;git diff --no-ext-diff --no-textconv --numstat <baseline> <patch_commit> for files_changed,
lines_added, lines_removed.Write patch.json: attempt N, baseline_commit, patch_commit (full SHA from
git rev-parse HEAD, or null), the counts, variants, suite_before, suite_after (command as
run, plus the counts), agent. Then:
python3 ${CLAUDE_SKILL_DIR}/../patching-bugs/scripts/records.py manifest /abs/run/patch/attempt-N
python3 ${CLAUDE_SKILL_DIR}/../patching-bugs/scripts/records.py check /abs/run
patch.json path, patch_commit (or "failed" with the error), variants fixed / not fixed, suite
before → after. Do not claim the fix is proven; proving is another agent's job.
--output on
git log, git show and git diff; --ext-diff and --no-index on git diff; --textconv
on git show.git stash, git reset, git checkout
or git restore in the checkout.reproduce/, validate/ or an earlier attempt.What SKILL.md sets; muted values are Claude Code's defaults
Other plugins' skills for the same job
npx claudepluginhub flyoverhead/devops-plugins --plugin patching-bugs5 skills in this plugin
/patching-bugsDrives one named bug from report to a local fix commit that someone other than its author has proven — intake into finding.json, a reproduce agent, a blind validate agent, up to three patch-then-prove rounds by separate fresh agents, an optional regression-hunt pass, and a Markdown report with a verdict, all under $TMPDIR. Use when the user starts /patching-bugs:patching-bugs with a bug report, issue or finding and wants the fix shown to work. Not for checking a fix that already exists — use post-patch-validation:post-patch-validation./prove-patchJudges a new local fix commit without trusting its author — every repair_scope case through one retained side-blind harness on clean baseline and patched worktrees, the project checks that matter on both, then the three-arm check (baseline fails, patch passes, patch reset to baseline fails again) — writing prove.json, receipts and a hash manifest under $TMPDIR. Use when patching-bugs:patching-bugs hands over a commit to prove, or the user wants proof that one local fix commit changes the outcome. Not for a merged fix, a PR or a patch file — use post-patch-validation:post-patch-validation./reproduce-bugShows one reported bug is real on the current build before any edit — builds the pinned baseline in a scratch worktree with the project's own command, runs the built artifact through a PoC harness printing PATCH_LOADED, PATCH_CASE and PATCH_REACHED (or the exact compiler diagnostic), and stores its stdout, stderr and exit codes beside reproduce.json and a hash manifest under $TMPDIR. Use when a bug must be shown on the current build with raw output someone else can rerun, or for the reproduce stage of patching-bugs:patching-bugs. Not for whether a scanner alert is real — use fp-check:fp-check./validate-bugRepeats a reproduce-bug package as a second, independent observer — same pinned baseline and recorded build argv in a fresh worktree, the unchanged PoC on the same inputs, only the files and never the reproducer's transcript — and records confirmed, not_confirmed or inconclusive in validate.json with its own receipts and manifest. Use when a reproduction should be repeated from its files alone before code changes, or for the validate stage of patching-bugs:patching-bugs. Not for mending a PoC that fails to run or for changing code — use patching-bugs:implement-patch.