Claude · Coding

Debugging

Reproduce the bug with a failing test, trace silent failures with logs, and reset when the first fix doesn't work.

Claude debugging

Pick the approach that fits your bug

The right starting point depends on what you can see. If you have steps to reproduce, ask for a failing test first. If it broke after a recent change, pair the full error with the diff. If there's no error at all, use temporary logs to find the first wrong value. And if Claude has already fixed the wrong thing, clear the session and ask for two competing causes plus one check that tells them apart. Each approach gets Claude to produce evidence before it changes your code.

Debugging in Claude Code or the Claude app

Claude Code can run your failing command, read the output and try again, so you mostly supply the symptom and the command that reproduces it. In the Claude app, you run things yourself and paste the results back, and you need to paste the diff too, since its GitHub integration has no commit history. Claude Code's /debug command won't help with your app, because it reads Claude Code's own debug log. For a bug in code you didn't write or a flaky test, Anthropic's docs suggest /effort high instead.

Frequently asked
How do I debug with Claude?

Give it the symptom, the expected result and a command that reproduces the problem. Ask for a failing test before any fix, and don't accept the fix until that same test passes unchanged.

Why does Claude keep fixing the wrong thing?

It may have settled on the first believable cause, or it's working from your description rather than the real error. Give it the full trace, say where the bug doesn't happen, and ask for two possible causes and a check that separates them.

What should I do when Claude's fix doesn't work?

Anthropic's docs say that after two failed corrections, you should run /clear and write one better prompt using what you learned. The failed attempts otherwise stay in the conversation, and Claude keeps re-reading them.

What does the /debug command do in Claude Code?

It turns on Claude Code's session debug logging and reads that log, to troubleshoot Claude Code itself. It isn't a tool for debugging your own application.

Can Claude read my logs?

Yes, in Claude Code. You can pipe a file with cat error.log | claude -p, or ask it to tail a log with its Monitor tool. Output past roughly 30,000 characters is saved to a file with only a preview shown inline, so keep logs short.