debugging
Systematic debugging framework with root cause investigation, tracing, defense-in-depth validation, and verification. Use when: 'bug', 'test failure', 'unexpected behavior', 'error', 'not working', 'broken', before proposing fixes, when encountering any technical issue
What this skill does
# Systematic Debugging
## Core Principle
**NO FIXES WITHOUT ROOT CAUSE INVESTIGATION FIRST**
Random fixes waste time and create new bugs. Quick patches mask underlying issues.
## The Iron Law
```
If you haven't completed root cause investigation, you cannot propose fixes.
```
## When to Use
Use for ANY technical issue:
- Test failures
- Bugs in production
- Unexpected behavior
- Performance problems
- Build failures
- Integration issues
**Use this ESPECIALLY when:**
- Under time pressure (emergencies make guessing tempting)
- "Just one quick fix" seems obvious
- You've already tried multiple fixes
- Previous fix didn't work
- You don't fully understand the issue
## Quick Reference: The Four Phases
| Phase | Key Activities | Success Criteria |
|-------|---------------|------------------|
| **1. Root Cause** | Read errors, reproduce, check changes, gather evidence | Understand WHAT and WHY |
| **2. Pattern** | Find working examples, compare | Identify differences |
| **3. Hypothesis** | Form theory, test minimally | Confirmed or new hypothesis |
| **4. Implementation** | Create test, fix, verify | Bug resolved, tests pass |
## Red Flags - STOP and Follow Process
If you notice yourself considering:
- "Quick fix for now, investigate later"
- "Just try changing X and see if it works"
- "Add multiple changes, run tests"
- "Skip the test, I'll manually verify"
- "It's probably X, let me fix that"
- "I don't fully understand but this might work"
- "Pattern says X but I'll adapt it differently"
- "Here are the main problems: [lists fixes without investigation]"
- Proposing solutions before tracing data flow
- **"One more fix attempt" (when already tried 2+)**
- **Each fix reveals new problem in different place**
**ALL of these mean: STOP. Return to Phase 1.**
**If 3+ fixes failed:** Question the architecture (not just symptoms)
## Topic Guides
### ๐ **@references/systematic.md** - Four-Phase Framework
- Complete systematic debugging process
- Phase 1: Root cause investigation
- Phase 2: Pattern analysis
- Phase 3: Hypothesis and testing
- Phase 4: Implementation
- Multi-component system diagnostics
- 3+ fix failure โ architectural questioning
- Human partner signals you're doing it wrong
- Common rationalizations to avoid
### ๐ **@references/root-cause.md** - Backward Tracing
- Trace bugs backward through call stack
- Finding original trigger vs fixing symptoms
- Adding stack trace instrumentation
- Finding which test causes pollution
- Real example: empty projectDir
### ๐ก๏ธ **@references/defense-in-depth.md** - Multi-Layer Validation
- Validate at EVERY layer data passes through
- Layer 1: Entry point validation
- Layer 2: Business logic validation
- Layer 3: Environment guards
- Layer 4: Debug instrumentation
- Making bugs structurally impossible
### โ
**@references/verification.md** - Evidence Before Claims
- The Iron Law: No completion claims without fresh verification
- The Gate Function (5 steps before any claim)
- Common failures and red flags
- Regression test red-green cycle
- Why this matters (trust, quality, honesty)
## Common Patterns
### Multi-Component Diagnostic
```bash
# Layer 1: Workflow
echo "=== Secrets available in workflow: ==="
echo "VAR: ${VAR:+SET}${VAR:-UNSET}"
# Layer 2: Build script
echo "=== Env vars in build script: ==="
env | grep VAR || echo "VAR not in environment"
# Layer 3: Target script
echo "=== State at execution: ==="
./script.sh --verbose
# Reveals: Which layer fails
```
### Stack Trace Addition
```typescript
// Before problematic operation
async function operation(param: string) {
const stack = new Error().stack;
console.error('DEBUG operation:', {
param,
cwd: process.cwd(),
env: process.env.NODE_ENV,
stack,
});
await doRiskyThing(param);
}
```
### Defense-in-Depth Pattern
```typescript
// Layer 1: Entry validation
function createThing(path: string) {
if (!path || path.trim() === '') {
throw new Error('path cannot be empty');
}
// Layer 2: Business logic
if (!existsSync(path)) {
throw new Error(`path does not exist: ${path}`);
}
// Layer 3: Environment guard
if (process.env.NODE_ENV === 'test') {
if (!path.startsWith(tmpdir())) {
throw new Error('Test operations must use temp dir');
}
}
// Layer 4: Debug instrumentation
logger.debug('Creating thing', { path, caller: new Error().stack });
// Now safe to proceed
}
```
## Integration
This skill works with:
- **systematic-thinking** - Deep analysis for complex bugs
- **code-review** - Catch bugs before they ship
- **validate-plan** - Ensure fix approach is sound
## Real-World Impact
From debugging sessions:
- Systematic approach: 15-30 minutes to fix
- Random fixes approach: 2-3 hours of thrashing
- First-time fix rate: 95% vs 40%
- New bugs introduced: Near zero vs common
---
**The Bottom Line:**
1. **Find root cause BEFORE proposing fixes**
2. **Trace backward to original trigger**
3. **Validate at EVERY layer**
4. **Verify BEFORE claiming success**
This is non-negotiable.
Related in Code Review
gstack
IncludedFast headless browser for QA testing and site dogfooding. Navigate pages, interact with elements, verify state, diff before/after, take annotated screenshots, test responsive layouts, forms, uploads, dialogs, and capture bug evidence. Use when asked to open or test a site, verify a deployment, dogfood a user flow, or file a bug with screenshots. (gstack)
startup-due-diligence
IncludedLegal due diligence review for seed-stage and Series A startups (US, Delaware C-Corp focus). Supports both investor and founder perspectives. Capabilities include: (1) Interactive document review and issue spotting; (2) Document request list generation; (3) Cap table and SAFE/convertible note analysis; (4) Red flag identification with severity ratings; (5) Diligence report generation. TRIGGERS: due diligence, DD, startup investment, cap table review, Series A, seed round, investor diligence, legal review startup, SAFE analysis, convertible note, 409A, founder vesting.
interview-master
IncludedThis skill should be used when the user asks to "generate interview questions", "prepare for interview", "optimize resume", "conduct mock interview", "analyze git commits for resume", "generate resume from code", "review my resume", or mentions interview preparation, career assistance, or extracting project experience from git history. Provides comprehensive interview and career development guidance for both job seekers and interviewers.
fix-issue
IncludedFixes GitHub issues using parallel analysis agents for root cause investigation, code exploration, and regression detection. Reads issue context from gh CLI, searches codebase and memory for related patterns, generates a fix with tests, and links the resolution back to the issue via PR. Includes prevention analysis to avoid recurrence. Use when debugging errors, resolving regressions, fixing bugs, or triaging issues.
sf-apex
IncludedGenerates and reviews Salesforce Apex code with 150-point scoring. TRIGGER when: user writes, reviews, or fixes Apex classes, triggers, test classes, batch/queueable/schedulable jobs, or touches .cls/.trigger files. DO NOT TRIGGER when: LWC JavaScript (use sf-lwc), Flow XML (use sf-flow), SOQL-only queries (use sf-soql), or non-Salesforce code.
swift-development
IncludedComprehensive Swift development for building, testing, and deploying iOS/macOS applications. Use when Claude needs to: (1) Build Swift packages or Xcode projects from command line, (2) Run tests with XCTest or Swift Testing framework, (3) Manage iOS simulators with simctl, (4) Handle code signing, provisioning profiles, and app distribution, (5) Format or lint Swift code with SwiftFormat/SwiftLint, (6) Work with Swift Package Manager (SPM), (7) Implement Swift 6 concurrency patterns (async/await, actors, Sendable), (8) Create SwiftUI views with MVVM architecture, (9) Set up Core Data or SwiftData persistence, or any other Swift/iOS/macOS development tasks.