Stop Pasting the Error Back: How to Debug AI-Written Code

· 2 min read ·
vibe-coding debugging ai claude-code

You paste the error into your AI tool. It changes a file. A new error. You paste that one. Attempt 7, same error, new file.

The loop fails because the AI is guessing, and each guess leaves code behind. Here is what to do instead.

1. Stop and go back

Revert to the last commit that worked (git diff, then git stash or git checkout .). Leftovers from failed fixes make the next guess worse. Then start a fresh chat with a short summary: the goal, what broke, what you tried.

2. Ask for hypotheses, not a fix

Copy this into your AI tool:

Something is broken. Before you change anything, read the logs and tell me your top 3 hypotheses, with the evidence for each. Then change one thing at a time and tell me how we will know it worked.

Three steps:

  1. Read the evidence. Logs first. No edits yet.
  2. Change one thing. So you know what fixed it.
  3. Define “worked”. A test or a check, before the fix.

3. Make it reproducible

Get the bug to happen on demand: one command, one request, or a small failing test. A bug you can trigger in a second is a bug the AI can actually check its fix against.

4. Prevent the next one

  • Commit before every prompt, so any change can be undone.
  • Plan before code. Ask for the smallest version, the data model, a test plan and a deploy plan before the first line of code, and tell it to ask what’s unclear.
  • Tests first. Ask for failing tests for the change, check them yourself, then ask for the code that makes them pass.
  • Read what you merge. If you can’t explain a change, you can’t debug it later.

The Get AI Native ebook has a full chapter on debugging and maintaining AI-written code. It is free, and the expected launch is around Christmas. Before launch, run through the launch checklist.

Comments