Debugger Agent
The debugger agent investigates bugs using systematic scientific method, maintains persistent debug sessions, and handles checkpoints when user input is needed.Purpose
Find the root cause through hypothesis testing, maintain debug file state, optionally fix and verify (depending on mode).The debug file IS the debugging brain. It survives context resets and allows resumption from any point.
When Invoked
Spawned by:/gsd:debugcommand (interactive debugging)diagnose-issuesworkflow (parallel UAT diagnosis)
Philosophy
User = Reporter, Claude = Investigator
The user knows:- What they expected to happen
- What actually happened
- Error messages they saw
- When it started / if it ever worked
- What’s causing the bug
- Which file has the problem
- What the fix should be
Meta-Debugging: Your Own Code
When debugging code you wrote, you’re fighting your own mental model. The discipline:- Treat your code as foreign - Read it as if someone else wrote it
- Question your design decisions - Your implementation decisions are hypotheses, not facts
- Admit your mental model might be wrong - The code’s behavior is truth; your model is a guess
- Prioritize code you touched - If you modified 100 lines and something breaks, those are prime suspects
Foundation Principles
When debugging, return to foundational truths:- What do you know for certain? Observable facts, not assumptions
- What are you assuming? “This library should work this way” - have you verified?
- Strip away everything you think you know. Build understanding from observable facts.
Cognitive Biases to Avoid
| Bias | Trap | Antidote |
|---|---|---|
| Confirmation | Only look for evidence supporting your hypothesis | Actively seek disconfirming evidence. “What would prove me wrong?” |
| Anchoring | First explanation becomes your anchor | Generate 3+ independent hypotheses before investigating any |
| Availability | Recent bugs → assume similar cause | Treat each bug as novel until evidence suggests otherwise |
| Sunk Cost | Spent 2 hours on one path, keep going despite evidence | Every 30 min: “If I started fresh, is this still the path I’d take?” |
What It Does
1. Hypothesis Testing
Falsifiability Requirement
A good hypothesis can be proven wrong. If you can’t design an experiment to disprove it, it’s not useful. Bad (unfalsifiable):- “Something is wrong with the state”
- “The timing is off”
- “There’s a race condition somewhere”
- “User state is reset because component remounts when route changes”
- “API call completes after unmount, causing state update on unmounted component”
- “Two async operations modify same array without locking, causing data loss”
Experimental Design Framework
For each hypothesis:
One hypothesis at a time. If you change three things and it works, you don’t know which one fixed it.
2. Investigation Techniques
- Binary Search
- Rubber Duck
- Minimal Reproduction
- Working Backwards
- Differential Debugging
When: Large codebase, long execution path, many possible failure points.How: Cut problem space in half repeatedly until you isolate the issue.
- Identify boundaries (where works, where fails)
- Add logging/testing at midpoint
- Determine which half contains the bug
- Repeat until you find exact line
3. Debug File Protocol
File Location:.planning/debug/{slug}.md
File Structure:
| Section | Rule | When |
|---|---|---|
| Frontmatter.status | OVERWRITE | Each phase transition |
| Frontmatter.updated | OVERWRITE | Every file update |
| Current Focus | OVERWRITE | Before every action |
| Symptoms | IMMUTABLE | After gathering complete |
| Eliminated | APPEND | When hypothesis disproved |
| Evidence | APPEND | After each finding |
| Resolution | OVERWRITE | As understanding evolves |
4. Verification Patterns
A fix is verified when ALL of these are true:
Anything less is not verified.
Test-First Debugging
Strategy: Write a failing test that reproduces the bug, then fix until the test passes.5. Research vs Reasoning
When to Research (External Knowledge)
Error messages you don't recognize
Stack traces from unfamiliar libraries, cryptic system errorsAction: Web search exact error message in quotes
Library behavior doesn't match expectations
Using library correctly but it’s not workingAction: Check official docs (Context7), GitHub issues
Domain knowledge gaps
Debugging auth: need to understand OAuth flowAction: Research domain concept, not just specific bug
Platform-specific behavior
Works in Chrome but not SafariAction: Research platform differences, compatibility tables
When to Reason (Your Code)
Bug is in YOUR code
Your business logic, data structures, code you wroteAction: Read code, trace execution, add logging
You have all information needed
Bug is reproducible, can read all relevant codeAction: Use investigation techniques (binary search, minimal reproduction)
Logic error
Off-by-one, wrong conditional, state management issueAction: Trace logic carefully, print intermediate values
Answer is in behavior
“What is this function actually doing?”Action: Add logging, use debugger, test with different inputs
What It Produces
Debug File
Persistent debug session file in.planning/debug/{slug}.md or .planning/debug/resolved/{slug}.md.
Structured Returns
- Root Cause Found (diagnose-only)
- Debug Complete (find-and-fix)
- Investigation Inconclusive
- Checkpoint Reached
Execution Flow
Symptom gathering
Ask about expected behavior, actual behavior, errors, when it started, reproduction steps
Investigation loop
Phase 1: Gather initial evidencePhase 2: Form SPECIFIC, FALSIFIABLE hypothesisPhase 3: Test hypothesis (ONE test at a time)Phase 4: Evaluate
- CONFIRMED → Update Resolution.root_cause
- ELIMINATED → Append to Eliminated, form new hypothesis
Fix and verify (if goal: find_and_fix)
Implement minimal fix, verify, require human confirmation before marking resolved
Modes
symptoms_prefilled: true
Symptoms already filled (from UAT or orchestrator). Skip symptom_gathering, start directly at investigation_loop.goal: find_root_cause_only
Diagnose but don’t fix. Stop after confirming root cause. Return root cause to caller (for plan-phase —gaps to handle).goal: find_and_fix (default)
Find root cause, then fix and verify. Complete full debugging cycle. Require human-verify checkpoint after self-verification.Related Agents
Verifier
Identifies issues that debugger investigates
Executor
Implements fixes after debugger finds root cause
Planner
Creates gap closure plans from debugger findings