Skip to content

YUHAO-corn/debug-first-skill

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Debug-First AI 🔍

A systematic debugging skill for AI coding assistants. Stop the "fix-guess-fail-repeat" loop.

中文文档


The Problem

When debugging with AI assistants, you've probably experienced this:

  1. "Surface-level fixes" - AI spots something that looks wrong and immediately "fixes" it, without understanding the root cause
  2. "Confident hallucinations" - AI doesn't know the answer but won't admit it, generating plausible-sounding but wrong solutions
  3. "Outdated knowledge" - AI's training data is months or years old, leading to deprecated API calls and obsolete patterns
  4. "The endless loop" - Fix → New error → Fix → New error → ... until you both give up

This skill forces AI to diagnose before fixing, explicitly acknowledge uncertainty, and ask for help when needed.


How It Works

This is a Claude Code Skill - a reusable prompt that activates when you invoke /debug. It transforms how Claude approaches debugging:

Without Debug-First With Debug-First
Sees error → Immediately modifies code Sees error → Asks clarifying questions first
Assumes it knows the technology Declares knowledge gaps about recent SDKs
Fixes symptoms Locates root cause through binary search
Keeps trying when stuck Triggers "direction check" after 2 failures
Never admits uncertainty Explicitly states confidence levels

Installation

For Claude Code (Recommended)

# Navigate to your home directory's Claude skills
mkdir -p ~/.claude/skills

# Clone or download the skill
curl -o ~/.claude/skills/debug https://raw.githubusercontent.com/YUHAO-corn/debug-first-ai/main/skill/debug/SKILL.md

Or manually copy skill/debug/SKILL.md to ~/.claude/skills/debug.

For Project-Specific Use

# In your project root
mkdir -p .claude/skills/debug
cp /path/to/SKILL.md .claude/skills/debug/

Usage

Once installed, simply type /debug in Claude Code when you encounter a bug:

> /debug

The login button doesn't work. It was working yesterday.

Claude will then:

  1. Assess information - Ask for error messages, expected vs actual behavior, reproduction steps
  2. Check knowledge gaps - Declare if it's unfamiliar with the specific technology/version
  3. Diagnose without modifying - Provide analysis with confidence levels
  4. Add verification logs - Suggest strategic console.log placements
  5. Fix only after confirmation - Modify code only after you confirm the diagnosis

The Debugging Protocol

Step 1: Information Assessment

Before any analysis, verify you have:

  • Complete error message/stack trace
  • Expected behavior vs actual behavior
  • Where the problem occurs (input/processing/output)
  • Relevant logs
  • Reproduction steps: Is it consistent? What's the minimal repro?

Step 2: Knowledge Gap Check

Declare uncertainty for:

  • SDKs/APIs released after training cutoff (2024+)
  • Fast-iterating frameworks (AI SDK, Vercel AI, LLM APIs)
  • Uncommon or internal libraries

Format: "This involves [technology]. My knowledge may be outdated. Please provide official docs or a working reference."

Step 3: Diagnostic Analysis

No code modifications in this step.

Output:

  1. Scope: User code or third-party library issue?
  2. Possible causes (ranked by likelihood with confidence %)
  3. Information gaps
  4. Knowledge gaps
  5. Verification plan (where to add logs)

Step 4: Add Verification Logs

After user confirms direction, add strategic logging.

Step 5: Fix After Confirmation

Pre-requisites:

  • Root cause confirmed via logs/evidence
  • User approved the diagnosis
  • Reference obtained for unfamiliar tech

Direction Check (Critical)

Trigger: 2+ failed fixes, or new error types appearing

  1. Question the source: Is this my recommendation or from a reference?
  2. Request reference: Any open source implementations doing similar things?
  3. Challenge assumptions: Are we solving the right problem?
  4. Question the problem itself: Is this the real issue or a symptom?

Why This Matters

AI's Hidden Failure Modes

The Dunning-Kruger AI: LLMs are trained to be helpful and confident. They don't naturally say "I don't know" - they generate the most statistically likely response, which might be plausible but wrong.

Pattern matching ≠ Understanding: AI recognizes patterns but doesn't truly "debug". It matches your error to similar patterns in training data, which fails for novel issues or recent framework changes.

No feedback loop: Unlike human developers who learn from production incidents, AI can't update its knowledge from your specific codebase or recent experiences.

Why Debug-First Works

  1. Forced introspection: Making AI explicitly state its confidence prevents overconfident guessing
  2. Binary search discipline: Localizing where the problem occurs prevents shotgun debugging
  3. Direction checks: Catching wrong-direction fixes early saves hours of wasted effort
  4. Knowledge boundaries: Knowing when AI is in unfamiliar territory lets you bring in the right resources

Real-World Example

Without Debug-First:

User: The API returns 500 error
AI: Let me fix the error handling... [modifies code]
User: Still broken
AI: Let me try a different approach... [modifies more code]
[3 hours later, codebase is now a mess]

With Debug-First:

User: /debug The API returns 500 error
AI: I need more information:
    - What endpoint?
    - What's in the server logs?
    - Did this work before? What changed?

User: [provides logs showing database connection timeout]

AI: Diagnosis (90% confidence):
    Root cause: Database connection pool exhausted
    Evidence: Timeout errors in logs, started after traffic spike

    Before fixing, let's verify:
    Add this log to check pool status: [...]

User: [confirms pool is exhausted]

AI: Now fixing with confirmed diagnosis: [targeted fix]

Contributing

PRs welcome! Especially:

  • Translations to other languages
  • Adaptations for other AI assistants (Cursor, Copilot, etc.)
  • Additional debugging scenarios and edge cases

License

MIT - Use freely, attribute if you share.


Acknowledgments

Born from countless debugging sessions where AI confidently broke things while trying to fix them. This skill encodes hard-won lessons about working with AI's limitations rather than against them.

About

A systematic debugging skill for AI coding assistants. Stop the fix-guess-fail-repeat loop.

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors