Debugging with Claude Code
Course contents (20 lessons)
- Meet Claude Code
- What Claude Code is and how it differs from a chat window
- Installing Claude Code and signing in
- Your first session: explore, ask, change
- Asking well and staying in control
- Asking for changes: context, goal, constraints and acceptance criteria
- Reading and approving edits
- Permission modes: how much freedom to give
- Project memory and slash commands
- CLAUDE.md: teaching the tool about your project
- Slash commands and custom commands
- Everyday coding workflows
- The plan-first workflow
- Understanding unfamiliar code
- Debugging with Claude Code
- Refactoring safely
- Writing tests with Claude Code
- Git, small changes, cost and security
- Git workflows: branches, commits and pull request descriptions
- Keeping changes small and reviewable
- Context and cost awareness
- Security habits: secrets, commands and untrusted input
- Extending the tool, teamwork and a final project
- Hooks and MCP servers explained
- Team practices for AI-assisted coding
- Final project: building a small app step by step
Give it evidence, not just a complaint
"The checkout is broken" is where you start, but it is not enough to give. A debugging request should carry the same information you would give a colleague: what you did, what happened, what you expected, and anything that looks relevant, such as an error message or a log line.
Bug: when a customer applies a 10% coupon and then removes an item, the order total stays at the discounted amount of the old cart.
Steps: add 2 items (total 200), apply coupon SAVE10 (total 180), remove one item (100 expected before discount, so 90 expected). Actual: 180.
Where I looked: CartService.RemoveItem does not seem to recalculate totals.
Do not fix yet. First, find the code that calculates the total and list 2 or 3 hypotheses for the cause, with the evidence in the code for each.
Why it works
The reproduction steps and the numbers make the problem exact. My own guess is included but marked as a guess, so it helps without limiting the search. "Do not fix yet" prevents a premature patch. Asking for hypotheses with evidence trains the tool, and you, to reason before acting.
Reproduce with a test first
A bug that cannot be reproduced cannot be proven fixed. Ask for a failing test before the fix.
Write a failing test that reproduces this bug, in the existing CartServiceTests file, using the same style as the other tests. Run it and show me that it fails for the reason we expect, not for some other reason. Then stop.
The last condition matters. A test that fails because of a typo in the test is not a reproduction. Check the failure message yourself.
Then fix, minimally
Now fix the bug with the smallest change that makes the test pass. Do not refactor. Run the whole cart test suite and report the result.
"Smallest change" and "do not refactor" keep the diff reviewable. If the real fix needs a refactor, do it in a separate step.
Paste errors and logs
Paste the exact error message and the relevant stack trace. Trim noise, but do not paraphrase, because the exact wording is what the tool searches for. Before you paste, remove secrets, tokens and personal data from logs.
This exception appears in production logs about twice a day:
System.InvalidOperationException: Collection was modified; enumeration operation may not execute.
at OrderProcessor.Process(Order order) in OrderProcessor.cs:line 88
Look at OrderProcessor and find what could modify the collection during enumeration. Consider concurrency. Do not change anything, explain the likely cause and how to confirm it.
When the tool is stuck
If three attempts at a fix have failed, stop. More attempts at the same approach rarely help. Instead:
- Ask it to summarise what it has tried and what each attempt showed.
- Run
/clearand restart with that summary plus new facts. - Add evidence by running the code with logging or a debugger yourself, and give the output.
- Question the assumptions: is the bug where we think it is?
Do not accept a fix you do not understand
Explain why this change fixes the bug, in three sentences. What was the root cause, and why did the old code behave that way? Could the same mistake exist elsewhere in the project?
The last question often turns up the same flaw in a sibling method, which is a good catch.
Watch for symptom fixes
Some fixes hide a bug instead of solving it: a null check that returns a default value, a retry loop around a failing call, a try-catch that logs and continues. Ask yourself: does this solve the cause or only silence the symptom?
The common mistake
The common mistake is asking the tool to "fix the failing test" when the test is correct and the code is wrong, or the reverse. Say which one is the truth: "The test expectation is correct. Fix the code, not the test."
Try it yourself
Find a real bug from your project's history, or create a small one on purpose in a scratch branch. Run the whole sequence: report with evidence, hypotheses, failing test, minimal fix, explanation. Note which step caught the most mistakes. For me it is almost always the failing test.
This course is free to read. Create a free account to enrol, save your progress and pick up where you left off.
Sign up free I already have an account