Agent skill
iterative-debugging
Install this agent skill to your Project
npx add-skill https://github.com/majiayu000/claude-skill-registry/tree/main/skills/other/iterative-debugging
SKILL.md
Iterative Debugging Skill
Version: 1.0.0 Compiler: manual (bootstrap) Last Updated: 2026-01-22
Systematic fix-verify-iterate debugging cycles with tools, not humans.
When to Activate
Use this skill when:
- Debugging an issue
- Fixing an error
- Investigating why something is broken
- Encountering an error during task execution
Core Principles
1. Hypothesis-Driven Debugging
Form a specific hypothesis about the cause before making changes.
Random changes waste time; targeted changes based on evidence converge faster.
2. One Change At A Time
Make exactly one change, then verify; never batch unrelated fixes.
Batched changes make it impossible to know what worked if it succeeds, or what failed if it doesn't.
3. Verify Immediately
After every change, run the verification step immediately.
Fast feedback loops prevent going down wrong paths.
4. Preserve Evidence
Capture logs, errors, and state at each iteration.
Evidence enables backtracking and pattern recognition across attempts.
5. Escalate With Context
If stuck after 3-5 iterations, escalate with full evidence chain.
Knowing what was tried prevents duplicate effort.
Workflow
Phase 1: Reproduce
Confirm the bug exists and capture initial state.
- Run the failing scenario to confirm the bug
- Capture the exact error message, stack trace, or unexpected behavior
- Note the environment details (versions, config, state)
- Establish baseline - what exactly is broken
Outputs: Confirmed reproduction steps, Initial error evidence, Baseline state
Phase 2: Hypothesize
Form a specific, testable hypothesis about the cause.
- Read the error message carefully - what is it actually saying
- Trace the call stack to identify the failure point
- Consider recent changes that might have caused this
- Form a specific hypothesis (not "something is wrong" but "X is null because Y")
Outputs: Specific hypothesis, Predicted fix
Phase 3: Fix
Make exactly one targeted change based on the hypothesis.
- Implement the minimal fix that addresses the hypothesis
- Make ONLY this one change
- Document what was changed and why
Outputs: Single, targeted code change, Change rationale
Phase 4: Verify
Test whether the fix resolved the issue.
- Run the exact same reproduction steps from Phase 1
- Compare result to baseline
- If fixed, run related tests to check for regressions
- If not fixed, capture new evidence (different error? same error? partial improvement?)
Outputs: Pass/fail result, New evidence if failed, Regression check if passed
Phase 5: Iterate or Complete
Based on verification, either continue debugging or declare victory.
- If fixed - document the root cause and solution
- If not fixed - update hypothesis based on new evidence
- If stuck after 3-5 iterations - compile evidence chain and escalate
- Return to Phase 2 with refined hypothesis
Outputs: Resolution documentation OR Updated hypothesis for next iteration OR Escalation package with evidence chain
Patterns
| Pattern | When | Do | Why |
|---|---|---|---|
| Binary Search Debugging | Bug is somewhere in a large change or code path | Bisect the code or changes to narrow down the exact failure point | Logarithmic reduction beats linear scanning |
| Print Statement Archaeology | State is unclear at a failure point | Add targeted logging around the suspected area, run, examine output | Direct observation beats speculation |
| Diff Against Working | Something that used to work is now broken | Diff current state against last known working state | Changes are finite; one of them caused the bug |
| Minimal Reproduction | Bug is hard to reproduce or involves complex state | Strip away everything not essential to the bug | Isolation reveals the core issue |
| Rubber Duck | Stuck and hypotheses are exhausted | Explain the problem out loud, step by step, as if teaching someone | Articulation often reveals overlooked assumptions |
Anti-Patterns to Avoid
| Anti-Pattern | Why It Fails | Instead |
|---|---|---|
| Shotgun Debugging | If it works, you don't know why; if it fails, you don't know what to undo | One change at a time, verify after each |
| Hypothesis-Free Changes | Random walk through solution space is exponentially slow | Always articulate why you think this change will help |
| Skipping Verification | False confidence; bug may persist or new bugs introduced | Always verify immediately after every change |
| Evidence Amnesia | May retry same failed approaches; cannot escalate effectively | Keep a log of hypothesis, change, and result for each iteration |
| Premature Escalation | Wastes others' time; misses learning opportunity | Try 3-5 focused iterations with evidence before escalating |
| Infinite Loop | Sunk cost fallacy; diminishing returns | Escalate with evidence chain after 3-5 attempts |
Quality Checklist
Before completing:
- Reproduced the bug and captured initial evidence
- Formed a specific, testable hypothesis
- Made exactly one change based on hypothesis
- Verified immediately after the change
- Captured evidence of result (pass or new failure state)
- Either resolved with documentation OR updated hypothesis for next iteration
- After 3-5 failed iterations, escalated with full evidence chain
Examples
API returns 500 error
- Reproduce: curl the endpoint, confirm 500, capture response body
- Hypothesize: Stack trace shows null pointer in UserService.getUser() - hypothesis is user ID is not being passed
- Fix: Add null check and logging for user ID parameter
- Verify: curl again, now see "user_id is null" in logs - hypothesis confirmed but root cause is upstream
- Iterate: New hypothesis - the auth middleware is not extracting user ID from token
- Fix: Check auth middleware, find token parsing bug
- Verify: curl again, now returns 200 with correct user data
- Complete: Document root cause (token parsing) and fix
UI element not rendering
- Reproduce: Load page in browser, confirm element missing, open dev tools
- Hypothesize: Console shows "cannot read property X of undefined" - hypothesis is data not loaded
- Fix: Add defensive check and loading state
- Verify: Reload page, element still missing but no console error - partial progress
- Iterate: New hypothesis - CSS is hiding the element
- Fix: Inspect element, find display:none from parent component
- Verify: Override CSS, element appears - root cause confirmed
- Complete: Fix parent component conditional rendering logic
References
- "The Art of Debugging with GDB, DDD, and Eclipse" - Norman Matloff
- "Debugging: The 9 Indispensable Rules" - David J. Agans
- Session insight - iterative fix cycles during Oracy web app debugging
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
Didn't find tool you were looking for?