/skills:diagnosing-bugsfrom skills
Diagnosis loop for hard bugs and performance regressions. Use when the user says "diagnose"/"debug this", or reports something broken/throwing/failing/slow.
Ships in skills. 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.
A discipline for hard bugs. Skip phases only when explicitly justified.
Core principle: Find root cause before attempting fixes. Symptom fixes are failure.
When exploring the codebase, read CONTEXT.md (if it exists) to get a clear mental model of the relevant modules, and check ADRs in the area you're touching.
This skill has you show commands, outputs and captured artifacts. Redact every secret first — write <REDACTED> in its place. Build loops against env vars, so the credential stays in the environment rather than in what you show. Captured artifacts carry auth headers: quote only the lines that carry the signal.
If the redacted output is not enough to diagnose the bug, say so and ask the user.
This is the skill. Everything else is mechanical. If you have a tight pass/fail signal for the bug — one that goes red on this bug — you will find the cause; bisection, hypothesis-testing, and instrumentation all just consume it. If you don't have one, no amount of staring at code will save you.
Spend disproportionate effort here. Be aggressive. Be creative. Refuse to give up.
Read error messages carefully. Check git diff, recent commits, new dependencies, config changes, environmental differences. The answer is often in what moved.
git bisect run it.scripts/hitl-loop.template.sh so the loop is still structured. Captured output feeds back to you.When the system has multiple components (CI → build → signing, API → service → database), add diagnostic instrumentation before proposing fixes:
Run once to gather evidence showing where it breaks, then investigate that specific component. See defense-in-depth.md in this directory.
Treat the loop as a product. Once you have a loop, tighten it:
A 30-second flaky loop is barely better than no loop; a 2-second deterministic one is tight — a debugging superpower.
The goal is not a clean repro but a higher reproduction rate. Loop the trigger 100×, parallelise, add stress, narrow timing windows, inject sleeps. A 50%-flake bug is debuggable; 1% is not — keep raising the rate until it's debuggable. See condition-based-waiting.md in this directory for replacing arbitrary timeouts with condition polling.
Stop and say so explicitly. List what you tried. Ask the user for: (a) access to whatever environment reproduces it, (b) a redacted captured artifact (HAR file, log dump, core dump, screen recording with timestamps), or (c) permission to add temporary production instrumentation. Do not proceed to hypothesise without a loop.
Phase 1 is done when the loop is tight and red-capable: you can name one command — a script path, a test invocation, a curl — that you have already run at least once (show the invocation and its output, redacted), and that is:
scripts/hitl-loop.template.sh.If you catch yourself reading code to build a theory before this command exists, stop — jumping straight to a hypothesis is the exact failure this skill prevents. No red-capable command, no Phase 2.
Run the loop. Watch it go red — the bug appears.
Confirm:
Once it's red, shrink the repro to the smallest scenario that still goes red. Cut inputs, callers, config, data, and steps one at a time, re-running the loop after each cut — keep only what's load-bearing for the failure.
A minimal repro shrinks the hypothesis space in Phase 3 (fewer moving parts left to suspect) and becomes the clean regression test in Phase 5.
Done when every remaining element is load-bearing — removing any one of them makes the loop go green.
Do not proceed until you have reproduced and minimised.
Generate multiple hypotheses before testing any of them. Single-hypothesis generation anchors on the first plausible idea.
Each hypothesis must be falsifiable: state the prediction it makes.
Format: "If is the cause, then will make the bug disappear / will make it worse."
If you cannot state the prediction, the hypothesis is a vibe — discard or sharpen it.
Show the ranked list to the user before testing. They often have domain knowledge that re-ranks instantly, or know hypotheses they've already ruled out. Cheap checkpoint, big time saver. Don't block on it — proceed with your ranking if the user is AFK.
When the error is deep in the call stack, trace backward: where does the bad value originate? What called this with the bad value? Keep tracing up until you find the source. Fix at the source, not at the symptom. See root-cause-tracing.md in this directory.
Each probe must map to a specific prediction from Phase 3. Change one variable at a time.
Tool preference:
Tag every debug log with a unique prefix, e.g. [DEBUG-a4f2]. Cleanup at the end becomes a single grep. Untagged logs survive; tagged logs die.
Perf branch. For performance regressions, logs are usually wrong. Instead: establish a baseline measurement (timing harness, performance.now(), profiler, query plan), then bisect. Measure first, fix second.
Write the regression test before the fix — but only if there is a correct seam for it.
A correct seam is one where the test exercises the real bug pattern as it occurs at the call site. If the only available seam is too shallow (single-caller test when the bug needs multiple callers, unit test that can't replicate the chain that triggered the bug), a regression test there gives false confidence.
If no correct seam exists, that itself is the finding. Note it. The codebase architecture is preventing the bug from being locked down. Flag this for Phase 6.
If a correct seam exists:
Stop. Count how many fixes you've tried:
Required before declaring done:
[DEBUG-...] instrumentation removed (grep the prefix)Then ask: what would have prevented this bug? If the answer involves architectural change (no good test seam, tangled callers, hidden coupling) hand off to the /improve-codebase-architecture skill with the specifics. Make the recommendation after the fix is in, not before — you have more information now than when you started.
| Thought | Reality |
|---|---|
| "Quick fix for now, investigate later" | First fix sets the pattern. Do it right from the start. |
| "Just try changing X and see if it works" | Guessing without a loop is thrashing. |
| "Add multiple changes, run tests" | Can't isolate what worked. Causes new bugs. |
| "Skip the test, I'll manually verify" | Untested fixes don't stick. |
| "It's probably X, let me fix that" | Seeing symptoms ≠ understanding root cause. |
| "One more fix attempt" (after 2+ failures) | 3+ failures = architectural problem. Stop. |
| "I see the problem, let me fix it" | You don't yet. Phase 1 first. |
When you see these: STOP. Return to Phase 1.
| Phase | Key Activities | Success Criteria |
|---|---|---|
| 1. Feedback loop | Check changes, build tight red-capable loop, gather evidence across boundaries | One command that goes red on this bug |
| 2. Reproduce + minimise | Confirm symptom matches, shrink repro, every element load-bearing | Minimal reproduction scenario |
| 3. Pattern + hypotheses | Find working examples, compare differences, trace data flow, rank 3-5 falsifiable hypotheses | Ranked, falsifiable hypotheses |
| 4. Instrument | Debugger/REPL > targeted logs, one variable at a time, tagged logs | Prediction confirmed or ruled out |
| 5. Fix + regression test | Regression test at correct seam, single fix, verify | Bug resolved, tests pass |
| 6. Cleanup + post-mortem | Remove debug artifacts, document hypothesis, suggest architectural prevention | Clean codebase, documented root cause |
These techniques are part of diagnosing bugs and available in this directory:
root-cause-tracing.md — Trace bugs backward through call stack to find original triggerdefense-in-depth.md — Validate at every layer data passes throughcondition-based-waiting.md — Replace arbitrary timeouts with condition pollingagents/openai.yaml (opens in a new tab)condition-based-waiting-example.ts (opens in a new tab)condition-based-waiting.md (opens in a new tab)defense-in-depth.md (opens in a new tab)find-polluter.sh (opens in a new tab)root-cause-tracing.md (opens in a new tab)scripts/hitl-loop.template.sh (opens in a new tab)What SKILL.md sets; muted values are Claude Code's defaults
Other plugins' skills for the same job
32 skills in this plugin
/ask-mattAsk which skill or flow fits your situation. A router over the skills in this repo./brainstormingYou MUST use this before any creative work - creating features, building components, adding functionality, or modifying behavior. Explores user intent, requirements and design before implementation./codebase-designShared vocabulary for designing deep modules. Use when the user wants to design or improve a module's interface, find deepening opportunities, decide where a seam goes, make code more testable or AI-navigable, or when another skill needs the deep-module vocabulary.npx claudepluginhub artemveduta/skills --plugin skills