MODULE 3 · EVERYDAY WORKFLOWS / 25 MIN Free NOVEMBER 2026 EDITION · CLAUDE CODE 2.1.318
Fixing bugs test-first
Reproduce a bug with a failing test, let Claude fix it until the test passes, and guard against fake fixes.
Updated 5 November 2026 · Reviewed 5 November 2026
What you’ll be able to do
Fix bugs in a way that is proven (a test shows the bug is gone) and durable (the test stops it coming back).
The loop
- Reproduce: write a test that fails because of the bug
- Commit the failing test. It’s your anchor.
- Fix: have Claude change the implementation until the test passes
- Check for fake fixes and regressions
- Commit the fix
Exercise: plant and fix a bug
In loop-practice (from Module 1), introduce a bug yourself:
!git checkout -b fix/slugify-numbers
Then ask Claude:
Write a failing test in slugify.test.js for this bug report:
"slugify('Top 10 Tips') returns 'top-tips' instead of 'top-10-tips'".
If the current implementation already handles it, first change slugify.js to
reproduce the bug (strip digits). Run the tests to show the new test fails.
Don't fix it yet.
Commit the failing state:
!git add -A && git commit -m "test: reproduce digits being stripped in slugify"
Now ask for the fix:
Fix slugify so the new test passes. Do not modify any tests. Run the full test
suite and show me the diff when done.
Guard against fake fixes
Check the diff yourself:
!git diff HEAD --stat
- Did any test file change? If so, ask why.
- Did it special-case the test input (
if (text === 'Top 10 Tips'))? That’s not a fix. - Is the full suite green, not just the new test?
Add the guardrail to your project’s CLAUDE.md so you never have to repeat it:
- When fixing a bug, never modify existing tests to make them pass; fix the implementation.
Real-world bugs: give Claude the evidence
For bugs in your own projects, paste the exact error:
This is failing in production:
TypeError: Cannot read properties of undefined (reading 'id')
at getOrderSummary (src/services/orders.ts:88:31)
...
Reproduce it with a failing test first, then fix the root cause, not just the
symptom. Explain the root cause in one paragraph.
Verify it worked
- You have a commit with a failing test, followed by a commit that fixes it
- The fix commit doesn’t change any test files
- The full suite passes
- Your CLAUDE.md has a rule against fake fixes
Knowledge check
3 QUESTIONS · PASS MARK 80%Tip: select the text that's wrong before clicking, and it's quoted in your report.