~/academy $ claude learn debugging-with-claude-code
Debugging with Claude Code
How to hand Claude Code the error, logs and steps to reproduce, narrow down the cause and prove the fix actually works. 7 min
$ Read
Give it what it cannot see
Claude can read your code, but not your screen, your server or your memory of what happened. A good bug report to Claude has the exact error text, the command or clicks that reproduce it, whether it happens every time or only sometimes, and what changed recently.
Hand things over rather than describing them. Paste the stack trace. Paste a screenshot of the error with Ctrl+V (Alt+V on Windows). Point at a log file with @logs/app.log. Or run the failing command inside the session with ! so its output lands in the conversation.
! npm run build
explain the errors in @logs/app.log from 14:00 onwards
Lesson notes: Debugging with Claude Code
Everything in this lesson as text, for revision or to read without the interactive steps. By the end you will be able to: You can take a bug from "it is broken" to a verified fix with Claude Code doing the digging.
Step 1 of 6 · Read
Give it what it cannot see
Claude can read your code, but not your screen, your server or your memory of what happened. A good bug report to Claude has the exact error text, the command or clicks that reproduce it, whether it happens every time or only sometimes, and what changed recently.
Hand things over rather than describing them. Paste the stack trace. Paste a screenshot of the error with
Ctrl+V(Alt+Von Windows). Point at a log file with@logs/app.log. Or run the failing command inside the session with!so its output lands in the conversation.Run it in the session ! npm run build
Mention a log file explain the errors in @logs/app.log from 14:00 onwards
Step 2 of 6 · Improve a prompt
Write the bug report
Rewrite this prompt so Claude Code can find and fix the problem without ten follow-up questions.
Starting prompt:
the export is broken, fix it
Hint: Include the exact error, how to reproduce it, how often it happens, what changed, what "fixed" looks like and how to check.
Show a strong version
Exporting the monthly report to CSV fails with "TypeError: Cannot read properties of undefined (reading 'date')" in src/reports/export.ts. To reproduce: run npm run dev, open /reports, pick October 2026, click Export. It fails every time for October, never for September. We added refunds to the report last week. Write a failing test that reproduces it, list the likely causes before changing code, then fix it. Fixed means the October export downloads and all report tests pass.
Step 3 of 6 · Try it in the terminal
Pipe a log straight in
From your normal shell, send the contents of error.log to Claude Code in print mode with the question: what is going on here
Hint: cat the file, pipe it with |, then claude -p and your question in quotes.
Show the command
$ cat error.log | claude -p "what is going on here" The log shows 214 timeouts connecting to the payments API between 09:02 and 09:07, all after the deploy at 09:01. The new PAYMENTS_TIMEOUT_MS value is 50, which looks like seconds were intended (50000). Check config/production.env.
Step 4 of 6 · Read
Narrow it down before fixing
Ask for hypotheses before changes: "list the three most likely causes and how we could test each one. Do not change any code yet." Plan mode is ideal for this, because Claude can explore freely while edits stay blocked.
Then test the hypotheses one at a time: a failing test that reproduces the bug, a temporary log line, a smaller input. For a bug in code nobody on the team wrote, or a flaky test, raise the effort with
/effort highso Claude checks more cases before answering.Watch the first minute. Press
Escthe moment it heads the wrong way. If you have corrected the same thing twice and it is still wrong, run/clearand write one better prompt with what you learned, instead of a third correction.Step 5 of 6 · Read
Prove the fix
A fix is not done until the original reproduction steps no longer fail. Ask Claude to rerun them, then the whole test suite, and to show you the output of both.
For anything you can see in an app, run
/verifyafter Claude says it is done: Claude builds and runs the app and looks at the result, which catches problems tests miss.Finally, ask it to remove any temporary logging and commit with a message that explains the cause, not only the change. The next person to hit something similar will thank you.
Step 6 of 6 · Quiz
Check your understanding
Claude has tried two fixes for the same bug and both were wrong. The conversation is long. What is the best next move?
- Explain again, more firmly, what is wrong.
- Switch to bypass permissions so it can try things faster.
- Run /clear and send one new prompt that includes what you have learned so far.
Show the answer
Run /clear and send one new prompt that includes what you have learned so far. Right. A fresh start with a better prompt works better almost every time.