Guides

How to debug with AI — 5 steps so it actually helps instead of guessing

Illustration: a two-person investigation — from error to root cause

The most common way to ask AI to fix a bug is to type "it doesn't work, fix it." It's also the most useless. The AI isn't sitting behind you: it can't see your screen, doesn't know what you expected, and can't read minds. Give it what you'd give a real teammate — and it debugs beautifully. Here are the five steps, exactly.

Step 1. Reproduce the bug and copy the error verbatim

First, get the bug to repeat reliably. Then find the error text and copy it whole: the message, the file path, the line number. Don't paraphrase it as "something about undefined" — give it verbatim.

TypeError: Cannot read properties of undefined (reading 'name')
    at UserCard (UserCard.jsx:14)

What you get: from this line alone the AI often names the cause — UserCard.jsx, line 14, something became undefined. The exact text saves the whole conversation that follows.

Step 2. Give context: the code, what you expected, what you got

The error is half the job. Add three things: the chunk of code that's failing, what you expected, and what actually happened. That's the formula of a good bug report.

Here's the UserCard component (code below).
Expected: shows the user's name.
Got: crashes with the TypeError above when the user hasn't loaded yet.

The sharper your "expected → got," the less the AI guesses. It's the same skill as a good prompt: not "help," but a clear spec. What you get: an answer about your case, not generic textbook advice.

Step 3. Ask for a hypothesis first, not an instant fix

Don't ask "rewrite the code for me." Ask it to explain the cause — and only then fix.

Explain in plain words why this crashes.
Give 1–2 likely causes. Don't rewrite the code yet.

That way you understand why instead of blindly pasting a patch. Often the cause becomes obvious at this step — and you fix it yourself. What you get: you learn from the bug instead of hoarding magic patches that break again tomorrow.

Step 4. Change one thing at a time and test after each

When it's time for edits — make them one at a time. The AI loves to suggest three changes at once; apply them all and it works, you don't know which one helped, and if it breaks worse, you don't know what's to blame.

Let's go one at a time. Apply only the first edit — I'll test and come back.

What you get: you always know which change did what. That's the difference between "fixed it" and "it accidentally stopped crashing."

Step 5. Stuck? Give a minimal example

If the bug won't budge, don't dump the whole project on the AI. Carve out the smallest piece that still reproduces the problem, and show only that. Half the time, while you're carving it out, the cause surfaces on its own (programmers call it "rubber-duck debugging": you explain it aloud and you get it).

What you get: either you find the cause yourself along the way, or you hand the AI a clean, focused case with no noise — and it answers more precisely.

What it adds up to

Debugging with AI isn't "fix it for me," it's a normal two-person investigation: reproduce → give the error and context → understand the cause → edit one thing at a time. This skill matters more than any language: AI-written code almost always comes out buggy on the first pass, and the winner isn't whoever writes without errors but whoever knocks them out fast. If you're just getting your footing, see what vibe coding is — debugging is half the game there.

Q: Which AI is best for debugging?

Any modern model fixes typical bugs well — what affects the result far more is how you asked. A precise error plus context beats the choice of model. It's handier when the AI is built into your editor and sees your code, but a plain chat copes too, if you carefully hand it the error and the relevant chunk.

Q: Should I just paste the error and hit "fix"?

For small stuff — why not, it often works. But on anything bigger you pile up patches without understanding the system, and the bugs come back. The habit of asking "why" pays off: a month from now you fix twice as fast, because you understand your code instead of just patching it.

Learn vibe coding — don’t just read about it

Short story-lessons, an agent simulator and daily practice — in our mobile app. Free.

Open the app
KODiQ Bot

KODiQ's AI editor. Writes about vibe coding and AI tools in plain language — every day.

All articles →