/fix-bug — Structured Bug Fix Workflow
Systematic approach to diagnosing and fixing bugs with TDD regression testing.
Steps
Phase 1: Diagnosis
- •
Gather information — ask the user:
- •What is the expected behavior?
- •What is the actual behavior?
- •Steps to reproduce?
- •When did it start? (recent change? always broken?)
- •Any error messages or logs?
- •
Reproduce the bug — write a test that demonstrates the failure:
- •The test MUST fail before the fix
- •The test describes the correct behavior
- •Name it clearly:
test_[scenario]_should_[expected_behavior]
- •
Run the test — confirm it FAILS for the RIGHT reason
- •
Root cause analysis — investigate:
- •Read the relevant code
- •Trace the execution path
- •Identify where behavior diverges from expectation
- •Document the root cause (not just the symptom)
Phase 2: Fix
- •
Plan the fix — for non-trivial bugs:
- •Save plan to
working/plans/YYYY-MM-DD_fix-description.md - •Describe the root cause and the fix approach
- •Save plan to
- •
Implement the fix — minimal change that addresses the root cause
- •Fix the root cause, not the symptom
- •Don't refactor unrelated code in the same change
- •
Run the regression test — confirm it now PASSES
- •
Run full suite —
make check— ensure no regressions
Phase 3: Review
- •Spawn review subagents using the Task tool:
code
Task(subagent_type="senior-code-reviewer",
prompt="<content of .claude/agents/code-reviewer.md>\n\n
Review this bug fix:\n{changed_files}\n
Root cause: {root_cause}\n
Verify the fix addresses the root cause, not just the symptom.")
Task(subagent_type="senior-code-reviewer",
prompt="<content of .claude/agents/test-reviewer.md>\n\n
Review the regression test for this bug fix:\n{test_files}\n
Verify the test would catch a recurrence of this bug.")
- •Verify —
make checkpasses after any review fixes
Phase 4: Delivery
- •
Present summary:
- •Root cause explanation
- •What was changed (minimal diff)
- •Regression test added
- •Full suite results
- •
Commit — with conventional commit message:
codefix(scope): short description Root cause: [explanation] Regression test: [test name] Closes #[issue]
Rules
- •ALWAYS write a regression test BEFORE fixing
- •The test must FAIL before the fix and PASS after
- •Minimal change: fix the bug, don't refactor surrounding code
- •Commit the test WITH the fix — they travel together
Options
- •
/fix-bug [issue number or description]— start with context - •
/fix-bug— interactive, asks for bug description