Skip to content
Skillpedia
Testing107k Β· #768

debugging-and-error-recovery

What it does

This guide helps you systematically find and fix errors in your code. It teaches you to stop, investigate, and resolve problems instead of guessing.

When to use it

  • βœ“When a test fails after a change.
  • βœ“When the program doesn't work as expected.
  • βœ“When you encounter an unexpected error.

Skill link

https://github.com/addyosmani/agent-skills/blob/main/skills/debugging-and-error-recovery/SKILL.md

Copy it and paste it into your AI (Claude, ChatGPT or Cursor), asking it to follow the instructions.

How to use

The easiest way: copy the message and paste it into your AI. It reads the skill and follows the instructions.

Ready-to-paste message

Use this skill to help me: https://github.com/addyosmani/agent-skills/blob/main/skills/debugging-and-error-recovery/SKILL.md Read the SKILL.md file at that link and follow its instructions for my task.
Want your AI to find skills like this on its own?Install the free Skillpedia MCP: one line, and it searches 15,000+ skills before each task.Install in 1 minute β†’

Example of what to ask your AI

β€œMy code is giving a weird error when I try to save a user, can you help me figure out why?”

5 new skills a week. 1 minute to read.

debugging-and-error-recovery: full guide

When something breaks, the natural move is to guess. You change a line, run the code again, and hope. Sometimes it works, and you never learn why. Sometimes it makes things worse. This skill gives your agent a fixed order of work instead: make the failure happen on demand, find where it happens, shrink it to the smallest case, fix the real cause, add a test, and check the result.

It is for anyone who works with an AI agent on code and sees a test fail, a build stop, or a feature that worked yesterday stop working. You do not need to read stack traces yourself. The skill tells the agent to name the cause, make the smallest fix, and say how to confirm it. It also asks the agent to stop adding features while something is broken, so one bug does not turn into three.

Use cases

A test fails after a small change

You renamed a field and now 12 tests fail. The agent first checks whether the code or the test is wrong. It looks for side effects in shared state or imports, then fixes the cause instead of skipping or deleting the failing test.

The build breaks after updating packages

After you update a dependency, the build stops with an import error. The agent works through the build checklist: the missing module, mismatched exports, wrong paths, the config file, then your Node version. It names the cause before it changes anything.

It worked last week and now it does not

A checkout page that was fine is now broken, and nobody knows which commit did it. The agent uses git bisect, which tests older versions of the code in turn, to find the exact change that introduced the bug, then fixes that.

Step by step

  1. 1Install the skill by placing its folder in ~/.claude/skills/debugging-and-error-recovery/, or in your project's .claude/skills/ folder, so your agent can find it.
  2. 2When something breaks, stop asking for new features. Paste the exact error text, the failing test name, or a description of what you expected and what you got.
  3. 3Let the agent reproduce the failure first. Give it the steps you took or the command that fails, so it can make the problem happen again.
  4. 4Ask for the cause in plain words before the fix. The agent narrows down the layer (interface, server, database, build) and shrinks the problem to a minimal case.
  5. 5Check that the agent adds a regression test that fails without the fix, then runs the full test suite and the build to confirm nothing else broke.

Example

What to ask

β€œThe search page returns no results when a task title contains quotes. It worked last week. Find the root cause, fix it, and add a test so it cannot come back.”

What you get

The agent reproduces the empty search with a title like Fix "quotes" & <brackets>, traces it to the query step, and explains why the quotes break matching. It makes a small fix, adds a test that fails without it, then runs the full suite and the build and reports both passing.

Tips

  • βœ“Paste the real error output and the command you ran. The skill tells the agent to treat error text as data, so it will not run commands found inside an error message without asking you.
  • βœ“Do not ask for several changes at once while debugging. Multiple edits mix together, and you can no longer tell which one fixed the problem or which one caused a new one.
  • βœ“A fix that makes the error disappear is not always a root-cause fix. If the agent only hides the symptom, for example by removing duplicates in the interface, ask it why the duplicates exist.
  • βœ“Bugs that appear only sometimes are harder. The skill suggests extra logging, timing checks and environment comparisons. Expect it to ask you for more context rather than promise a quick fix.

Alternatives

  • test-driven-development

    Pick this when you are building a new feature or fix and want the failing test written first, instead of investigating a bug that already exists.

  • webapp-testing

    Pick this when the bug lives in a local web app's interface and you need the agent to drive a browser, read its logs and take screenshots.

  • verify-and-stop

    Pick this when the work is done and you only want a clear pass or fail check against your requirements, without a debugging investigation.

Questions and answers

Does this skill fix bugs automatically?

No. It gives your agent a fixed process: reproduce, localize, reduce, fix, guard and verify. The agent still does the work, but it explains the cause and how to confirm the fix instead of guessing.

Can I use it if I cannot reproduce the bug?

Yes. The skill has a separate path for bugs that appear only sometimes. It checks timing, environment differences and leaked state, adds logging, and records the conditions so you can revisit the problem when it happens again.

Does it only work with JavaScript projects?

The examples use npm and JavaScript, but the skill says to use the repository's own test and build commands. The steps themselves apply to any language.

How it works

It works by asking you to reproduce the error, then find where it's happening, simplify the problem, and finally fix the real cause.

Technical content (original SKILL.md)

Original text by the author, straight from GitHub.

Debugging and Error Recovery

Overview

Systematic debugging with structured triage. When something breaks, stop adding features, preserve evidence, and follow a structured process to find and fix the root cause. Guessing wastes time. The triage checklist works for test failures, build errors, runtime bugs, and production incidents.

When to Use

  • Tests fail after a code change
  • The build breaks
  • Runtime behavior doesn't match expectations
  • A bug report arrives
  • An error appears in logs or console
  • Something worked before and stopped working

The Stop-the-Line Rule

When anything unexpected happens:

1. STOP adding features or making changes
2. PRESERVE evidence (error output, logs, repro steps)
3. DIAGNOSE using the triage checklist
4. FIX the root cause
5. GUARD against recurrence
6. RESUME only after verification passes

Don't push past a failing test or broken build to work on the next feature. Errors compound. A bug in Step 3 that goes unfixed makes Steps 4-6 wrong.

The Triage Checklist

Work through these steps in order. Do not skip steps.

Step 1: Reproduce

Make the failure happen reliably. If you can't reproduce it, you can't fix it with confidence.

Can you reproduce the failure?
β”œβ”€β”€ YES β†’ Proceed to Step 2
└── NO
    β”œβ”€β”€ Gather more context (logs, environment details)
    β”œβ”€β”€ Try reproducing in a minimal environment
    └── If truly non-reproducible, document conditions and monitor

When a bug is non-reproducible:

Cannot reproduce on demand:
β”œβ”€β”€ Timing-dependent?
β”‚   β”œβ”€β”€ Add timestamps to logs around the suspected area
β”‚   β”œβ”€β”€ Try with artificial delays (setTimeout, sleep) to widen race windows
β”‚   └── Run under load or concurrency to increase collision probability
β”œβ”€β”€ Environment-dependent?
β”‚   β”œβ”€β”€ Compare Node/browser versions, OS, environment variables
β”‚   β”œβ”€β”€ Check for differences in data (empty vs populated database)
β”‚   └── Try reproducing in CI where the environment is clean
β”œβ”€β”€ State-dependent?
β”‚   β”œβ”€β”€ Check for leaked state between tests or requests
β”‚   β”œβ”€β”€ Look for global variables, singletons, or shared caches
β”‚   └── Run the failing scenario in isolation vs after other operations
└── Truly random?
    β”œβ”€β”€ Add defensive logging at the suspected location
    β”œβ”€β”€ Set up an alert for the specific error signature
    └── Document the conditions observed and revisit when it recurs

For test failures (npm shown β€” substitute the repository's own test command, per the test-driven-development skill's Discover the Stack First section):

# Run the specific failing test
npm test -- --grep "test name"

# Run with verbose output
npm test -- --verbose

# Run in isolation (rules out test pollution)
npm test -- --testPathPattern="specific-file" --runInBand

Step 2: Localize

Narrow down WHERE the failure happens:

Which layer is failing?
β”œβ”€β”€ UI/Frontend     β†’ Check console, DOM, network tab
β”œβ”€β”€ API/Backend     β†’ Check server logs, request/response
β”œβ”€β”€ Database        β†’ Check queries, schema, data integrity
β”œβ”€β”€ Build tooling   β†’ Check config, dependencies, environment
β”œβ”€β”€ External service β†’ Check connectivity, API changes, rate limits
└── Test itself     β†’ Check if the test is correct (false negative)

Use bisection for regression bugs:

# Find which commit introduced the bug
git bisect start
git bisect bad                    # Current commit is broken
git bisect good <known-good-sha> # This commit worked
# Git will checkout midpoint commits; run your test at each
git bisect run npm test -- --grep "failing test"  # substitute the repository's focused-test command

Step 3: Reduce

Create the minimal failing case:

  • Remove unrelated code/config until only the bug remains
  • Simplify the input to the smallest example that triggers the failure
  • Strip the test to the bare minimum that reproduces the issue

A minimal reproduction makes the root cause obvious and prevents fixing symptoms instead of causes.

Step 4: Fix the Root Cause

Fix the underlying issue, not the symptom:

Symptom: "The user list shows duplicate entries"

Symptom fix (bad):
  β†’ Deduplicate in the UI component: [...new Set(users)]

Root cause fix (good):
  β†’ The API endpoint has a JOIN that produces duplicates
  β†’ Fix the query, add a DISTINCT, or fix the data model

Ask: "Why does this happen?" until you reach the actual cause, not just where it manifests.

Step 5: Guard Against Recurrence

…

FAQ

What does 'preserve evidence' mean?

It means saving important information about the error, like error messages, logs, or the steps you took to make it happen.

Why shouldn't I add new features when something breaks?

Because adding more code can worsen the problem or hide the original cause, making it harder to fix.

What is 'bisection'?

It's a technique to find which specific change caused a problem by testing older versions of the code until you find one that worked.

Details

Original description by the author

Guides systematic root-cause debugging. Use when tests fail, builds break, something that worked yesterday broke, behavior doesn't match expectations, or you encounter any unexpected error. Use when you need to figure out what broke and why β€” a systematic approach to finding and fixing the root cause rather than guessing.

repo: addyosmani/agent-skills

Popularity

GitHub stars
107k
Ranking position
#768
License
MIT
Updated
10/13/2026

Is this skill useful?

0

Sign in to vote.

Comments

  • …

More skills from this repository

Similar skills