Skip to content
Back to skills

Debug

ASecurity

Use when encountering any bug, test failure, or unexpected behavior. Enforces systematic root-cause investigation before proposing fixes. Prevents guess-and-check debugging.

  • 6 stars
  • 0 votes
  • 0 copies
  • 9 views
  • Added August 31, 2026
ai-agentsshellbashtestingdebuggingrefactoringgit

Security analysis

A100/100

Pro scans all 6 files and shows the line behind each finding

Scanned November 18, 2026

npx -y skills add nicodiansk/turbocharge --skill debug --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Debug?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Debug
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/nicodiansk-debug/badge)](https://www.skillsdirectory.com/skills/nicodiansk-debug)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: debug
description: Use when encountering any bug, test failure, or unexpected behavior. Enforces systematic root-cause investigation before proposing fixes. Prevents guess-and-check debugging.
---

# Systematic Debugging

## Overview

Random fixes waste time and create new bugs. Quick patches mask underlying issues.

**Core principle:** find the root cause before attempting a fix. A fix aimed at the symptom leaves the cause in place to fail again.

## The Iron Law

Propose a fix only after Phase 1 has found the root cause: before that, a fix is a guess, and each guess that misses leaves one more change to undo.

## The Four Phases

Complete each phase before moving to the next: each one supplies what the next one needs.

### Phase 1: Root Cause Investigation

**Before attempting any fix:**

1. **Read Error Messages Carefully**
   - Don't skip past errors or warnings
   - They often contain the exact solution
   - Read stack traces completely
   - Note line numbers, file paths, error codes

2. **Reproduce Consistently**
   - Can you trigger it reliably?
   - What are the exact steps?
   - Does it happen every time?
   - If not reproducible → gather more data, don't guess

3. **Check Recent Changes**
   - What changed that could cause this?
   - Git diff, recent commits
   - New dependencies, config changes
   - Environmental differences

4. **Gather Evidence at Component Boundaries**
   For multi-component systems: log what enters and exits each component. Run once to find WHERE it breaks, then investigate that specific component.

5. **Trace Data Flow**

   **WHEN error is deep in call stack:**

   See `root-cause-tracing.md` in this directory for the complete backward tracing technique.

   **Quick version:**
   - Where does bad value originate?
   - What called this with bad value?
   - Keep tracing up until you find the source
   - Fix at source, not at symptom

6. **Shell traps (zsh)**
   - The Bash tool runs zsh when `$SHELL` is zsh (`CLAUDE_CODE_SHELL` overrides it), and zsh breaks scripts that bash runs fine
   - `command not found: git` right after a script set `path=…`: zsh ties `path` to `PATH`, so rename the variable
   - A loop over `$files` that runs once with every path: zsh doesn't split unquoted variables. Use an array: `files=(a b)`, then `"${files[@]}"`
   - `status` is read-only and `argv` is the argument list, so neither works as a variable name

### Phase 2: Pattern Analysis

**Find the pattern before fixing:**

1. **Find Working Examples**
   - Locate similar working code in same codebase
   - What works that's similar to what's broken?

2. **Compare Against References**
   - If implementing pattern, read reference implementation COMPLETELY
   - Don't skim - read every line
   - Understand the pattern fully before applying

3. **Identify Differences**
   - What's different between working and broken?
   - List every difference, however small
   - Don't assume "that can't matter"

4. **Understand Dependencies**
   - What other components does this need?
   - What settings, config, environment?
   - What assumptions does it make?

### Phase 3: Hypothesis and Testing

**Scientific method:**

1. **Form Single Hypothesis**
   - State clearly: "I think X is the root cause because Y"
   - Write it down
   - Be specific, not vague

2. **Test Minimally**
   - Make the SMALLEST possible change to test hypothesis
   - One variable at a time
   - Don't fix multiple things at once

3. **Verify Before Continuing**
   - Did it work? Yes → Phase 4
   - Didn't work? Form NEW hypothesis
   - DON'T add more fixes on top

4. **When You Don't Know**
   - Say "I don't understand X"
   - Don't pretend to know
   - Ask for help
   - Research more

### Phase 4: Implementation

**Fix the root cause, not the symptom:**

1. **Create Failing Test Case**
   - Simplest possible reproduction
   - Automated test if possible
   - One-off test script if no framework
   - MUST have before fixing
   - TDD is baked into the builder agent — use it

2. **Implement Single Fix**
   - Address the root cause identified
   - ONE change at a time
   - No "while I'm here" improvements
   - No bundled refactoring

3. **Verify Fix**
   - Test passes now?
   - No other tests broken?
   - Issue actually resolved?

4. **If Fix Doesn't Work**
   - STOP
   - Count: How many fixes have you tried?
   - If < 3: Return to Phase 1, re-analyze with new information
   - **If ≥ 3: STOP and question the architecture (step 5 below)**
   - DON'T attempt Fix #4 without architectural discussion

5. **If 3+ Fixes Failed: Question Architecture**

   **Pattern indicating architectural problem:**
   - Each fix reveals new shared state/coupling/problem in different place
   - Fixes require "massive refactoring" to implement
   - Each fix creates new symptoms elsewhere

   **STOP and question fundamentals:**
   - Is this pattern fundamentally sound?
   - Are we "sticking with it through sheer inertia"?
   - Should we refactor architecture vs. continue fixing symptoms?

   **Discuss with your human partner before attempting more fixes**

   This is NOT a failed hypothesis - this is a wrong architecture.

## Red Flags — STOP and Return to Phase 1

| Thought | Why It's Wrong |
|---------|----------------|
| "Quick fix for now, investigate later" | First fix sets the pattern. Do it right from the start |
| "Just try changing X and see if it works" | Seeing symptoms ≠ understanding root cause |
| "Skip the test, I'll manually verify" | Untested fixes don't stick |
| "Multiple changes at once, run tests" | Can't isolate what worked. Causes new bugs |
| "I don't fully understand but this might work" | Partial understanding guarantees bugs |
| "One more fix attempt" (after 2+ failures) | 3+ failures = architectural problem. Question pattern, don't fix again |

If 3+ fixes failed: question the architecture (see Phase 4, step 5).

## Quick Reference

| 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 |

## Integration

**Workflow position:**
```
[bug/failure] → debug → build (for fix) → review
```

**Chains to:**
- **build** - For implementing the fix with TDD via builder agent
- **review** - Verify fix worked before claiming success

**Chains from:**
- Entry point skill - triggered by any bug, test failure, or unexpected behavior

## Verification Checklist

Before declaring a bug fixed:

- [ ] Root cause identified (not just symptoms)
- [ ] Evidence gathered through systematic investigation
- [ ] Failing test case created before fix
- [ ] Single fix applied (not multiple changes)
- [ ] Fix addresses root cause, not symptom
- [ ] All tests pass after fix
- [ ] No regressions introduced

Files in this skill

  • SKILL.md6.4 KB
  • condition-based-waiting-example.ts4.9 KB
  • condition-based-waiting.md3.4 KB
  • defense-in-depth.md3.6 KB
  • find-polluter.sh1.5 KB
  • root-cause-tracing.md5.2 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in ai-agents →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.