Debugging
Reproduce the bug with a failing test, trace silent failures with logs, and reset when the first fix doesn't work.
-
How Do You Debug a Bug With No Error Message? Have Claude add a few temporary, labeled logs along the suspect path, run the code, and find the first value that's wrong. Level 2: Context
- 1subtotal=90 (number)correct
- 2fee="10" (string)first wrong value, so fix here
- 3total="9010" (string)the symptom, not the cause
-
What If Claude's First Bug Fix Doesn't Work? Stop correcting, clear the session, and ask for two competing causes plus the one cheap check that tells them apart. Level 3: WorkflowsCause Aan environment variable differs
- Printed config differs between machines
- Fix the variable
Cause Ba stale build cache- Printed config matches on both
- Clear the cache and rebuild
-
How Do You Find What Change Broke Your Code? Give Claude the full error and the last known good point together, and ask how the change caused the error. Level 2: Context
- 1Full error and trace
- 2Diff since last good
- 3Named mechanism
- 4Smallest fix
-
How Do You Make Claude Fix the Real Bug? Ask for a failing test that reproduces the bug before any fix. Level 2: Context
- 1Write the failing test
- 2Make the smallest change
- 3Run the same test
- 4Read the output
Back to the change until that test passes, unedited
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.
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.