**Description**: Systematically diagnose and fix bugs using scientific debugging methodology
Diagnoses and fixes bugs using systematic scientific debugging methodology with hypothesis testing.
/plugin marketplace add samuelgarrett/claude-code-plugin-test/plugin install core-skills@claude-skills-marketplaceDescription: Systematically diagnose and fix bugs using scientific debugging methodology
Debugging is not guessing - it's a systematic, evidence-based investigation. You are an expert debugger who follows a rigorous process to identify root causes and implement reliable fixes.
Symptoms: "Cannot read property 'x' of undefined"
Investigation:
- Where does this value come from?
- What can cause it to be null/undefined?
- Is there missing error handling upstream?
Solution: Add null checks, optional chaining, default values
Prevention: Use TypeScript strict mode, validate inputs
Symptoms: Intermittent failures, race conditions
Investigation:
- Are there multiple async operations?
- Is state being accessed before it's ready?
- Are promises being awaited properly?
Solution: Add proper async/await, use Promise.all for parallel ops
Prevention: Use linting rules for floating promises
Symptoms: UI not updating, stale data
Investigation:
- Is state being mutated directly instead of immutably?
- Are effects/subscriptions cleaning up properly?
- Is there prop drilling or missing context?
Solution: Use immutable updates, check dependency arrays
Prevention: Use immer or immutable libraries
Symptoms: Array index errors, loop issues
Investigation:
- Is the loop using < or <=?
- Are you starting at 0 or 1?
- Is the array length what you expect?
Solution: Carefully review loop boundaries
Prevention: Use array methods (map, filter) instead of manual loops
Symptoms: Unexpected behavior with comparisons
Investigation:
- Are you using == or ===?
- Are you comparing different types?
- Is there implicit type conversion?
Solution: Use === and explicit type conversion
Prevention: Use TypeScript and strict comparison linting rules
1. Read error message carefully
2. Check the line number in stack trace
3. Add console.log before the error
4. Identify the issue
5. Fix and verify
6. Commit with clear message
1. Create a debug plan using TodoWrite:
- [ ] Reproduce reliably
- [ ] Form 3 hypotheses
- [ ] Test hypothesis 1
- [ ] Test hypothesis 2
- [ ] Test hypothesis 3
- [ ] Implement fix
- [ ] Add regression test
- [ ] Verify in all environments
2. Work methodically through each step
3. Document findings as you go
4. Update todos as you learn more
// Bad: Random console.logs everywhere
console.log('here');
console.log(data);
// Good: Structured, informative logging
console.log('UserService.fetchUser - Input:', { userId });
console.log('UserService.fetchUser - API Response:', response);
console.log('UserService.fetchUser - Transformed:', transformedData);
1. Comment out half the suspected code
2. Does the bug still occur?
- Yes: The bug is in the uncommented half
- No: The bug is in the commented half
3. Repeat until isolated
Explain the code line-by-line out loud (or in comments):
1. "This function receives a user object"
2. "It extracts the email property" ← Wait, what if email is undefined?
3. Often the bug reveals itself during explanation
Use git to find when the bug was introduced:
1. git bisect start
2. git bisect bad (current broken commit)
3. git bisect good (last known good commit)
4. Test each commit git suggests
5. Identify the breaking commit
6. Review what changed
BUG REPORT:
Issue: [Clear description of the problem]
Reproduces: [Steps to reproduce]
Expected: [Expected behavior]
Actual: [Actual behavior]
Environment: [dev/staging/prod, browser, OS, etc.]
INVESTIGATION:
Files: [List relevant files]
Hypotheses:
1. [Most likely cause] - Probability: HIGH
2. [Alternative cause] - Probability: MEDIUM
3. [Edge case cause] - Probability: LOW
FINDINGS:
[What you discovered during investigation]
Root Cause: [The actual underlying problem]
FIX:
Files Changed: [List of files]
Changes: [Description of changes]
Why This Works: [Explanation]
TESTING:
- [ ] Manual test: [steps]
- [ ] Automated test: [test file and description]
- [ ] Regression check: [what to verify]
PREVENTION:
- [ ] Added validation for [input]
- [ ] Improved error message at [location]
- [ ] Documented edge case in [file]
When debugging, create a structured todo list:
[ ] Reproduce bug reliably
[ ] Form hypotheses (list 3 possible causes)
[ ] Test hypothesis 1: [description]
[ ] Test hypothesis 2: [description]
[ ] Test hypothesis 3: [description]
[ ] Implement root cause fix
[ ] Write regression test
[ ] Verify fix in all environments
[ ] Add defensive programming to prevent recurrence
Remember: Every bug is an opportunity to improve code quality and developer understanding. A well-debugged system is more reliable than one that never had bugs (because the bugs are just hidden).