Omniscio

OmniscioGuidesPromptsDebugging

Claude Code prompt for debugging

A bug report is a claim about the world, and a fix is a claim about the cause. The gap between them is where most debugging sessions go wrong: the error disappears, nobody is sure why, and the same failure returns three weeks later wearing a different message.

The prompt below puts the cause before the fix, because an error that stops appearing is not the same thing as a bug that is gone.

Checked against Anthropic's Claude Code documentation on November 25, 2026. By the Omniscio team. Updated .

The prompt

Replace the first paragraph with your command, your error and whether it happens every time or only sometimes, and paste the output where the marker is. Do not summarise it — the summary is the part with the clue missing.

npm test fails in tests/checkout.test.ts with "Cannot read properties of undefined (reading 'id')", about one run in five. Here is the full output:

<paste the output here>

Find the cause before you change anything. Tell me which line the undefined comes from, why it only happens sometimes, and what you ruled out to get there.

Then write the smallest test that reproduces the failure and show me it failing before you fix it. After the fix, show me that test passing and the whole suite passing, with the commands you ran.

The output goes into the prompt on purpose. Claude reads the real error, with its stack trace and its exact wording, instead of your description of it. If the log is already on disk, Anthropic's `@` reference includes the file's contents in the conversation, which is the same thing by another route — what does not work is describing the error instead of handing it over.

Why each line is there

"Here is the full output"

Giving Claude the artifact is one of the patterns behind a working prompt: paste the error rather than describing it. Anthropic's own debugging tips point the same way — tell Claude the command that reproduces the issue and get a stack trace, and say whether the error is intermittent or consistent. The full output carries things a summary drops: the frame that threw, the arguments, the order of events.

"about one run in five"

Anthropic's debugging tips include saying whether the error is intermittent or consistent, and the two are different bugs with different causes.

For an intermittent failure it is the most useful hint you can give, and it is ours rather than a documented rule: a failure that happens sometimes is usually about ordering, shared state, or something still in flight when the next thing starts.

"Find the cause before you change anything"

Ask for a fix and you get the smallest one, which is usually at the crash site. This line changes the deliverable from a patch to an explanation, and it is the difference between a session that ends with a null check and one that ends with a reason.

"which line the undefined comes from, why it only happens sometimes"

Two questions with checkable answers. The line can be confirmed by reading the code; the explanation can be confirmed by the reproduction. Vague questions get vague answers, and both of these force the answer to be specific enough to be wrong.

"what you ruled out to get there"

A cause is only as good as the alternatives it beat. Asking what was ruled out turns a plausible story into an argument you can check, and it is the cheapest way to catch the failure mode where a confident explanation is simply one of three possibilities that were never tested.

"write the smallest test that reproduces the failure and show me it failing"

Anthropic's example of a specific prompt has this shape: write a failing test that reproduces the bug, then fix it. Its separate bug-fixing recipe does not require the failing test first, and that recipe is the one a session will follow if you only ask for a fix. The failing run is what makes the test a reproduction rather than a guess, and it is the only thing that proves the fix addressed this bug and not a nearby one. A check that comes back pass or fail also lets Claude close the loop itself, so it keeps going until the test is green rather than stopping when the change looks right.

"with the commands you ran"

The command and its output are evidence; all tests pass on its own tells you very little. For a bug fix this matters more than usual, because the whole claim being made is that a specific failure no longer happens.

The reproduction-first variant

When the cause is genuinely unknown, use this instead of the prompt above: it spends the whole turn on making the failure reproducible, and nothing on explaining it.

npm test fails in tests/checkout.test.ts with "Cannot read properties of
undefined (reading 'id')", about one run in five. Here is the full output:

<paste the output here>

Make this fail on demand. Add the smallest test that reproduces it, and if you
cannot reproduce it in a test, tell me what nondeterminism is in the way and how
you would pin it down.

Do not fix anything in this message.

A bug you can reproduce on demand stops being a mystery. Everything after that is mechanical, and the fixed version has a test that will catch the same failure next time. Use this version when you would rather spend one extra turn than receive a diagnosis you cannot check.

The subagent version

A long log or a wide search is exactly the work a subagent isolates: it reads in its own context window and returns a summary, so the flood never reaches your conversation. The subagent reads the whole log before it summarises, which is the opposite of you summarising it first. For a failure that needs the whole test run read, or a stack trace across a dozen files, that is a real saving in context — though it costs tokens, since the subagent sends its own requests against the same usage, and it can be slower because it has to gather context your conversation already had.

use a subagent to find why tests/checkout.test.ts fails intermittently. It
should return the line the undefined comes from, the sequence that produces it,
and the evidence for that sequence. It should change nothing.

There is a worked file for this on the site: the debugger subagent, among the subagent examples.

What a good answer has to contain

  • A cause with a location. Not "the checkout code assumes a user exists" but the file, the line, and the value that arrives there.
  • A mechanism for the intermittency. The order of two calls, a promise nobody awaited, a cache that is warm on the second run. If it cannot explain why it is intermittent, it has not found the cause of your bug.
  • A failing reproduction, shown. The test, the command, and the failure output, before the fix.
  • The same test passing after. Plus the suite, so you know the fix did not move the failure somewhere else.
  • A list of what it ruled out. Often more convincing than the cause itself.

The common failure

The error stops appearing and the bug is still there. The classic version is a guard at the crash site:

if (!order.customer) return   // the crash is gone, the cause is not

That line is defensible as code and useless as a fix, because it answers "how do we stop the exception" rather than "why is the customer missing". The next caller that needs the customer gets the same failure in a different place, which is why the reproduction comes before the fix: if the test was never red, there is nothing to show it is now green for the right reason.

A second failure looks like the opposite and costs the same. You get several plausible causes, one of them is chosen, and the code is changed to suit it. Nothing is reproduced, so nothing distinguishes the guess from the answer — and one of the three was probably right, which is the worst outcome, because next time you will trust the process that guessed.

Both are prevented by the same two requirements: a cause that names a line and a mechanism, and a test that fails before the fix and passes after.

Make it a one-word command

Claude Code ships two commands for a session that is misbehaving, and neither one debugs your test failure: /doctor runs a setup checkup that diagnoses installation and configuration issues, and /debug turns on debug logging for the session and reads that log. Point them at a problem with the tool, not with the code you are working on — which is why a failing test needs a prompt like the one above.

When the same class of bug keeps coming back — an intermittent test, a queue that stalls, a retry that duplicates — save the prompt as a skill at .claude/skills/debug-that/SKILL.md: YAML frontmatter with a name and a description of when to use it, then the prompt as the body. It runs as /debug-that, and the body loads only when it is used, so the detail costs almost nothing until the moment you need it.

What belongs in CLAUDE.md instead is the reproduction command: how to run one test, how to run the suite, how to get a stack trace out of your own tooling. That is the line that turns a bug report into a debugging session without you explaining it each time.

Worked examples are here: skills examples and CLAUDE.md examples.

How this page was written

Everything here about what Anthropic recommends when reporting a bug, the failing-test-first shape of a fix, what evidence to ask for, and what a subagent costs was read from Anthropic's Claude Code documentation on November 25, 2026, and checked against the wording in the Sources below.

The prompt is ours: an example written for this site, following the patterns Anthropic documents. It is not a prompt Anthropic publishes, and the failure in it is a placeholder.

Sources

  • Anthropic's Common workflows, for the bug-fixing recipe and the tips about the reproduction command, the stack trace and intermittent errors, read November 25, 2026.
  • Anthropic's Best practices for Claude Code, for the specific-prompt example with a failing test, the check that returns pass or fail, asking for evidence, and what subagents cost, read November 25, 2026.
  • Anthropic's Prompt library, for giving Claude the artifact and letting it find the files, read November 25, 2026.
  • Anthropic's Commands reference, for what /doctor and /debug do, read November 25, 2026.
  • Anthropic's Create custom subagents, for context isolation and what a subagent costs, read November 25, 2026.
  • Anthropic's Extend Claude with skills, for where a skill lives and when its body loads, read November 25, 2026.
  • Google's autocomplete suggestions for "claude code debug prompt", read November 25, 2026, for the query this page answers.

Common questions

What is a good Claude Code prompt for debugging?

One that pastes the real error output, asks for the cause before any change, and requires a failing test that reproduces the bug before the fix. The prompt at the top of this page is an example you can copy and point at your own failure.

Why does Claude keep fixing the symptom?

Usually because the prompt asked for a fix rather than a cause. A null check or a try-catch at the crash site makes the error message disappear without touching what produced it, and only a reproduction that fails before the fix and passes after can tell the two apart.

What should I paste into the prompt?

The command you ran, the full output, and whether the failure is consistent or intermittent. Anthropic's guidance is to give Claude the artifact rather than a description of it, so the error text, the log and the stack trace all belong in the prompt. If the output is long, the subagent version above is the way to include it without your own conversation carrying it afterwards.

Is there a built-in debug command?

For Claude Code itself, yes: /doctor runs a setup checkup for installation and configuration problems, and /debug turns on debug logging for the session and reads that log. Neither one debugs a failing test in your repository — for that you need a prompt, because the thing being debugged is your code and the context it needs is your project.

How do I know the fix actually fixed it?

The reproduction test. It has to fail before the change and pass after, and the command and output have to be in the reply. A passing suite on its own does not show that the failure you reported was ever reproduced.

Debug in one session. Lead six from one window.

A debugging prompt runs inside one Claude Code session. Omniscio is the level above: a desktop app for running Claude Code and other coding agents side by side, with one list of sessions and one inbox, so an agent only interrupts you when a decision needs you.

The features page lists what is in it today, pricing covers the plans, and you can download it for Windows, macOS or Linux.