Agent skill
debug
Systematic root-cause debugging — reproduce, isolate, hypothesize, fix with TDD
Install this agent skill to your Project
npx add-skill https://github.com/majiayu000/claude-skill-registry/tree/main/skills/other/other/coding-andreibesleaga-gabbe
SKILL.md
Debug Skill
Goal
Find the root cause of a bug through systematic investigation, not trial-and-error. Fix it using TDD (write the failing test that reproduces the bug first, then fix the code).
Steps
-
Fill the bug report (or read existing one)
- Use templates/core/BUG_REPORT_TEMPLATE.md if not already filled
- Gather: exact error message, stack trace, reproduction steps, environment
-
Reproduce the bug reliably
- Create a minimal reproduction case
- If you can't reproduce it: ask for more information (environment, data, user actions)
- Note: if the bug is intermittent, identify the conditions that trigger it
-
Write the failing test FIRST (TDD for bugs)
typescript// tests/bug/issue-42-null-user.test.ts test('should not crash when user is null in payment processor', () => { // This test should reproduce the exact bug scenario expect(() => processPayment(null, { amount: 100 })).not.toThrow(); // OR: expect the correct error handling behavior });- Run the test — it MUST FAIL (reproducing the bug)
- This is your regression test that ensures the bug never returns
-
Isolate the fault
- Read the stack trace from bottom up (the bottom frames are your code, top is the error)
- Add logging at the entry point of the failing function
- Binary search: narrow down which function/line causes the issue
- Check: what data enters the function vs what data should enter
-
Classify the bug type
- Null/undefined: Missing validation, unexpected null input
- Logic error: Wrong condition, off-by-one, incorrect algorithm
- Race condition: Async operations in wrong order, missing await
- Data shape mismatch: API response changed, schema migration issue
- State mutation: Shared mutable state, missing deep clone
- Environment difference: Works in dev, fails in prod (env vars, DB state)
- Dependency change: Library upgrade changed behavior
-
Hypothesize the root cause
- State your hypothesis explicitly: "I believe the bug is caused by [X] because [evidence]"
- Test the hypothesis: add a breakpoint/log to verify
- If hypothesis is wrong: revise and re-hypothesize
-
Implement the fix
- Fix the root cause, not the symptom
- Minimal change — don't refactor while fixing a bug
- Common fix patterns:
- Add null/undefined guards at entry points
- Add missing await
- Fix wrong conditional logic
- Add missing error handling
-
Verify the fix
- Run the regression test from Step 3 → must now PASS
- Run the full test suite → must still pass (no new regressions)
- Verify in the environment where the bug was reported (if possible)
-
Add documentation / prevent recurrence
- Add code comment explaining WHY the fix is needed (not what it does)
- If the bug was caused by a missing test: add the test to the permanent test suite
- If the bug was caused by a common mistake: add to agents/memory/CONTINUITY.md
-
Log to AUDIT_LOG.md
- Entry: what the bug was, what the root cause was, what the fix was
Constraints
- NEVER fix a bug without a failing test that reproduces it first
- NEVER change more code than necessary to fix the bug
- If the bug requires an architectural change to fix properly: escalate to human
- If you cannot reproduce the bug after 3 attempts: escalate to human with detailed report
Output Format
Fixed code + regression test. Report: "Bug fixed. Root cause: [X]. Regression test added at [path]. All [N] tests passing."
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
Didn't find tool you were looking for?