Find and fix a bug or regression with evidence, not guesses. Reproduce it with one command, shrink it, test ranked hypotheses, fix the root cause minimally and lock it in with a regression test. Use for anything broken, crashing, failing, flaky or slow.
Installs into .claude/skills of the current project.
Sponsors
SSkills DirectorySkills Directory
Know which skills are safe — weekly.
SSkills DirectorySkills Directory
Is that skill safe to install?
Are you the author of Debugging?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/k6w-debugging)
---
name: debugging
description: "Find and fix a bug or regression with evidence, not guesses. Reproduce it with one command, shrink it, test ranked hypotheses, fix the root cause minimally and lock it in with a regression test. Use for anything broken, crashing, failing, flaky or slow."
keywords: [bug, debug, broken, crash, error, exception, failing, regression, flaky, slow, performance, stack trace, root cause, fix]
---
# Debugging
The rule: **no fix before a reproduction, no reproduction before a command.** A patch that was never
seen failing first is a guess, and guesses get reverted.
## 1. Build a loop that goes red
Spend most of your effort here. You need one command that:
- drives the real code path and checks **the exact symptom** that was reported (the wrong value, the
message, the timing), not merely "it did not crash";
- gives the same verdict every run (for intermittent bugs: a known, high failure rate);
- runs in seconds and needs no human.
Run it and keep its output. If you catch yourself reading code to form a theory before this command
exists, stop and go back. Ideas for building one, from cheapest up, are in
`references/feedback-loops.md` (load with `load_skill("debugging", "references/feedback-loops.md")`).
If you truly cannot reproduce it, say so to the lead (`send_message`) with what you tried and what
you need (an environment, a log, a sample input). Do not continue on a hunch.
## 2. Shrink it
Remove inputs, config, steps and callers one at a time, rerunning after each cut. Stop when every
remaining piece matters: removing any one makes the loop pass. The small case becomes your
regression test and cuts the number of suspects.
## 3. Rank hypotheses, then test them
Write down three to five candidate causes before testing any, most likely first. Each must predict
something checkable: "if X is the cause, changing Y makes it pass and changing Z makes it worse". A
cause you cannot phrase that way is not a hypothesis yet.
Test one variable at a time:
- Prefer a debugger or REPL; then targeted logs at the boundary that separates two hypotheses.
- Tag every temporary log with a unique marker (e.g. `[dbg-7c1]`) so one grep removes them all.
- Regression between two known-good/known-bad states: bisect (`git bisect run <your command>`).
- Slowness: measure a baseline first (timer, profiler, query plan), then change one thing and measure
again. Never optimise on intuition.
Write down which hypothesis the evidence confirmed and which it ruled out. That sentence goes in
your report.
## 4. Fix the root cause, minimally
- Grep every caller of the code you change. Fix the shared code once rather than patching one caller.
- Smallest change that removes the cause. No drive-by refactors in the same change (see `lean-code`
for refactoring separately).
- Stay inside the files you were given or claimed (`claim_files`); if the cause lives elsewhere, tell
the lead before touching it.
## 5. Lock it in
- Turn the shrunk case into a test at a seam that exercises the real bug pattern. Watch it **fail on
the unfixed code**, apply the fix, watch it pass. (How to write that test well: `test-driven`.)
- If no honest seam exists (the bug needs a chain a unit test cannot reproduce), say so: that is a
design finding worth reporting.
- Rerun the original, unshrunk loop. Run the full relevant suite and the task's acceptance command.
## 6. Clean up and report
- [ ] original repro now passes
- [ ] regression test fails without the fix, passes with it
- [ ] all tagged debug logs and scratch scripts removed (grep the marker)
- [ ] report to the lead: the cause in one or two sentences, the evidence, the fix, the test, the
commands you ran with their results (see `shipping` for the hand-off format)
Never weaken, skip or delete a failing test to make a bug "go away".