| name | debug-detective |
| description | Systematic debugging approach for ANY codebase, ANY language, ANY bug type. Use when facing unexpected behavior, crashes, performance issues, or intermittent problems. |
Debug Detective - Systematic Bug Hunting
🎯 When to Use This Skill
Use when facing ANY bug:
- Unexpected behavior
- Crashes or errors
- Performance issues
- Intermittent problems
- "Works on my machine" issues
⚡ Quick Start (Find bugs in 5 steps)
The Universal Debug Protocol:
- REPRODUCE - Can you make it happen again?
- ISOLATE - Where exactly is it breaking?
- UNDERSTAND - Why is it breaking?
- FIX - Apply minimal solution
- VERIFY - Confirm fix works
🔍 Step 1: REPRODUCE
WITH MCP Tools:
"Help me create a minimal reproduction for this bug: [describe bug]"
WITHOUT MCP:
echo "=== BUG REPRODUCTION ===" > bug_report.md
echo "1. Start the app with: [command]" >> bug_report.md
echo "2. Navigate to: [location]" >> bug_report.md
echo "3. Perform action: [action]" >> bug_report.md
echo "4. Expected: [what should happen]" >> bug_report.md
echo "5. Actual: [what actually happens]" >> bug_report.md
Quick Tests:
NODE_ENV=production npm start
npm start --debug
docker run ...
🎯 Step 2: ISOLATE
WITH MCP (Architecture Analyzer):
"Trace the execution flow for [feature name]"
"Find all places where [variable/function] is used"
WITHOUT MCP:
Binary Search Method:
console.log('=== MIDPOINT: Data here:', data);
Breadcrumb Trail:
console.log('🔍 1: Starting process');
console.log('🔍 2: Data loaded:', data);
console.log('🔍 3: Processing complete');
console.log('🔍 4: Saving results');
Git Bisect (for regressions):
git bisect start
git bisect bad HEAD
git bisect good v1.2.3
🧠 Step 3: UNDERSTAND
WITH MCP (Smart Reviewer):
"Analyze this function for potential issues: [paste code]"
"What could cause [error message]?"
WITHOUT MCP:
The 5 Whys Technique:
Problem: App crashes on user login
Why? → Authentication fails
Why? → Token is invalid
Why? → Token expired
Why? → Refresh mechanism broken
Why? → API endpoint changed
Root cause found!
Common Bug Patterns Check:
Race Conditions:
someAsyncCall();
doSomethingElse();
await someAsyncCall();
doSomethingElse();
Off-by-One Errors:
for (let i = 0; i <= array.length; i++)
Type Mismatches:
'1' + 1 === '11';
'1' - 1 === 0;
Null/Undefined:
const result = data?.user?.name ?? 'default';
🔧 Step 4: FIX
WITH MCP (Refactor Assistant):
"Fix this bug with minimal changes: [describe issue and paste code]"
WITHOUT MCP:
Minimal Fix Approach:
- Smallest possible change that fixes the issue
- Don't refactor while fixing (separate concerns)
- Add defensive code to prevent recurrence
- Document the fix with a comment
Fix Template:
if (user && user.role === 'admin') {
}
✅ Step 5: VERIFY
WITH MCP (Test Generator):
"Generate a test that verifies this bug is fixed"
WITHOUT MCP:
Verification Checklist:
[Run reproduction steps]
npm test
npm run lint
time npm start
Regression Test:
describe('Bug #123 - Login crash', () => {
it('should handle expired tokens gracefully', () => {
const expiredToken = generateExpiredToken();
expect(() => authenticate(expiredToken)).not.toThrow();
expect(authenticate(expiredToken)).toBe(false);
});
});
🚨 Emergency Debug Tools
Universal Quick Checks:
Memory Issues:
node --inspect app.js
python -m memory_profiler script.py
jmap -dump:file=heap.bin <pid>
CPU Issues:
top -p <pid>
node --prof app.js
node --prof-process isolate-*.log
Network Issues:
curl -v https://api.example.com
netstat -an | grep LISTEN
tcpdump -i any port 3000
🎯 Debug Strategies by Bug Type
"Works on my machine":
- Check environment variables
- Compare dependency versions
- Check OS-specific code
- Verify file paths (case sensitivity!)
- Check timezone/locale differences
Intermittent bugs:
- Add extensive logging
- Check race conditions
- Monitor resource usage
- Check external dependencies
- Use stress testing
Performance degradation:
- Profile before/after
- Check database queries
- Look for N+1 problems
- Check caching
- Monitor memory leaks
💡 Pro Tips
The Rubber Duck Method:
1. Explain the bug to a rubber duck (or colleague)
2. Step through the code line by line
3. Often, you'll spot the issue while explaining
Fresh Eyes Technique:
git stash
git checkout main
git stash pop
Sanity Checks:
- Server running?
- Database connected?
- Correct branch?
- Dependencies installed?
- Environment variables set?
📝 Debug Log Template
Keep a debug log for complex issues:
## Bug: [Description]
**Date:** [Date]
**Severity:** Critical/High/Medium/Low
### Symptoms:
-
### Reproduction:
1.
### Hypotheses Tested:
- [ ] Hypothesis 1: [Result]
- [ ] Hypothesis 2: [Result]
### Solution:
-
### Lessons Learned:
-
Remember: Every bug is a learning opportunity! 🐛→📚