| allowed-tools |
|---|
Bash(*), Edit(**) |
Debug this issue: $ARGUMENTS
Extract from $ARGUMENTS:
- Symptom: what's happening (error message, wrong behavior, crash)
- Expected: what should happen
- Repro steps: how to trigger it (if known)
- Scope: file path, endpoint, component, or "unknown"
If $ARGUMENTS is vague ("it's broken"), ask:
1. What's the error message or unexpected behavior?
2. When did it start? (recent change, always broken, intermittent)
3. Can you reproduce it? (steps or command)
If clear, proceed.
- Read CLAUDE.md + identify stack
- Load matched framework reference file from frameworks/_index.md — check Pitfalls first
- Read error logs, stack traces, browser console output
- Check recent git changes:
git log --oneline -10+git diff HEAD~3 - Read the failing code + its tests + its imports
Framework pitfalls shortcut: Many bugs are known framework gotchas. Check the Pitfalls section before deep-diving — it may be a 1-line fix.
List 2-4 ranked hypotheses:
## Bug: [short description]
### Hypotheses (most likely first)
1. [hypothesis] — evidence: [why] — test: [how to confirm/deny]
2. [hypothesis] — evidence: [why] — test: [how to confirm/deny]
3. [hypothesis] — evidence: [why] — test: [how to confirm/deny]
Rules:
- Most likely first (Occam's razor — recent changes > obscure bugs)
- Each hypothesis must have a testable prediction
- Check framework Pitfalls before inventing exotic theories
- "Works on my machine" → check env vars, node_modules, lock files, .env
Test hypotheses in order:
- Add minimal logging/assertions to confirm or eliminate each hypothesis
- Narrow scope: which file, which function, which line
- Find the root cause, not just the symptom
Isolation techniques:
- Binary search: comment out half the code, does it still break?
- Minimal repro: smallest code that triggers the bug
- Git bisect:
git bisect start HEAD [last-good-commit]for regressions - Dependency check:
rm -rf node_modules && npm install(or equivalent)
Once root cause is confirmed:
git stashor commit current debug artifacts- Write the fix — minimal, targeted, no scope creep
- Remove debug logging/assertions
- Run build + lint + test
- Verify the original repro steps now pass
- Check for related instances: does this bug pattern exist elsewhere?
If fix breaks other things: STOP. The root cause analysis was incomplete. Go back to Step 3.
After fixing:
- Add a regression test covering the exact bug
- If it's a framework pitfall not in the reference file — note it
- Commit:
git commit -m "fix: [what was broken] — [root cause]"
## Bug Fixed: [short description]
### Root Cause
[1-2 sentences — the actual problem]
### Fix
[file:line — what changed and why]
### Regression Test
[test file — what it verifies]
### Related
- [other places this pattern exists, if any]
- [framework pitfall reference, if applicable]
- Reproduce first — can't fix what you can't trigger
- Hypothesize before hacking — random changes waste tokens and time
- One change at a time — change, test, observe, repeat
- Root cause, not symptom — "adding a null check" isn't a fix if the value shouldn't be null
- Never suppress errors — catch blocks that swallow exceptions create the next bug
- Check framework pitfalls early — 40% of bugs are documented gotchas
- 2-attempt limit per hypothesis — if a fix doesn't work twice, re-hypothesize
- Clean up debug artifacts — remove console.logs, print statements, temporary code