Get featured

How to get out of an AI bug loop

Guide · checked against the docs on

You ask the AI to fix a bug. It says it's fixed. It isn't. You ask again, and now something else breaks. This guide is about getting out of that loop once you're in it. For stopping it from starting, see How to stop AI coding tools breaking your code. Everything below comes from the tool makers' own docs, read on October 16, 2026. We haven't tested these steps ourselves.

Not affiliated with or endorsed by Anthropic, Cursor, OpenAI or GitHub. Features change, so check each tool's docs.

Why the loop happens

Every correction stays in the chat. Anthropic's Claude Code guide describes the pattern: "Correcting over and over. Claude does something wrong, you correct it, it's still wrong, you correct again. Context is polluted with failed approaches." (checked Oct 2026)

There's a second cause. The same page says: "Claude stops when the work looks done. Without a check it can run, "looks done" is the only signal available, and you become the verification loop" (checked Oct 2026)

So the way out is the same for both: a clean chat, and a check the AI has to pass.

Step 1: Stop

Don't send another "still broken". In Claude Code, the Claude Code guide says: "Esc: stop Claude mid-action with the Esc key. Context is preserved, so you can redirect." (checked Oct 2026)

Our advice, not a vendor quote: in any tool, if the same bug has come back twice, stop and treat that as the signal. Anthropic uses the same number for Claude: "After two failed corrections, /clear and write a better initial prompt incorporating what you learned." (checked Oct 2026) OpenAI's Codex guide says: "When Codex makes the same mistake twice, ask it for a retrospective and update AGENTS.md." (checked Oct 2026)

Step 2: Roll back to the last version that worked

Each failed fix may have left changes behind. Go back before you go forward.

Both vendors say checkpoints don't replace git. Cursor: "Checkpoints are stored locally and separate from Git. Only use them for undoing Agent changes; use Git for permanent version control." (checked Oct 2026) For the git commands, see Git basics for AI coders.

Step 3: Start a fresh chat

The old chat is full of wrong guesses. Anthropic: "If you've corrected Claude more than twice on the same issue in one session, the context is cluttered with failed approaches. Run /clear and start fresh with a more specific prompt that incorporates what you learned. A clean session with a better prompt almost always outperforms a long session with accumulated corrections." (checked Oct 2026) For what /clear keeps, see Claude Code /compact vs /clear.

GitHub's Copilot guide says the same: "if none of the context of a particular conversation is helpful, start a new conversation." (checked Oct 2026)

Our advice, not a vendor quote: before you clear, write down in two or three lines what the AI tried and why it failed. Paste that into the new chat so it doesn't repeat it.

Step 4: Give it the exact error and a way to reproduce it

"It's broken" isn't enough. Paste the real error text. Anthropic's example prompt: "the build fails with this error: [paste error]. fix it and verify the build succeeds. address the root cause, don't suppress the error" (checked Oct 2026)

Better still, ask for a failing test first. Anthropic's example: "users report that login fails after session timeout. check the auth flow in src/auth/, especially token refresh. write a failing test that reproduces the issue, then fix it" (checked Oct 2026)

OpenAI says to tell Codex what done means: "Done when: What should be true before the task is complete, such as tests passing, behavior changing, or a bug no longer reproducing?" (checked Oct 2026)

Then ask for proof, not a promise. Anthropic: "Have Claude show evidence rather than asserting success: the test output, the command it ran and what it returned, or a screenshot of the result." (checked Oct 2026)

Step 5: Ask for a plan before more edits

If the AI keeps guessing, make it think first. Anthropic: "Letting Claude jump straight to coding can produce code that solves the wrong problem. Use plan mode to separate exploration from execution." (checked Oct 2026) OpenAI: "If the task is complex, ambiguous, or hard to describe well, ask Codex to plan before it starts coding." Its Plan mode can be toggled "with /plan or Shift+ Tab." (checked Oct 2026)

Plan mode itself is covered in How to stop AI coding tools breaking your code.

Step 6: Make the task smaller

A big fix has more places to go wrong. GitHub: "If Copilot is not providing a helpful response, try rephrasing your prompt, or even breaking your request down into multiple smaller prompts." (checked Oct 2026) Anthropic asks the same question when things go wrong: "Was the context too noisy? The prompt too vague? The task too big for one pass?" (checked Oct 2026)

Our advice, not a vendor quote: fix one symptom at a time. Get one test passing, commit, then move to the next.

A restart prompt you can copy

Our advice, not a vendor quote: this combines the steps above. Swap in your own details.

"Don't edit anything yet. Bug: [what happens] when [steps to reproduce]. Error: [paste exact error]. Already tried and failed: [your short list]. First, explain what you think the cause is. Then write a failing test that reproduces it. Then fix the root cause and show me the test output."

Before you keep the fix

Our advice, not a vendor quote: once the loop is broken, check the diff before you keep anything. Anthropic notes "A fresh context improves code review since Claude won't be biased toward code it just wrote." (checked Oct 2026) See How to review AI-written code before you keep it.

We haven't tested these steps hands-on. This guide collects what the tool makers say.

Not affiliated with or endorsed by Anthropic, Cursor, OpenAI or GitHub. Features change, so check each tool's docs.