DEV Community

Rock News UK
Rock News UK

Posted on Originally published at besttechguides.github.io

How to break a Cursor debug loop

If the agent has already "fixed" the bug twice and the file no longer looks like yours, the next edit is the problem, not the solution.

Most of the debug loops I see start the same way. You paste an error. The agent rewrites a function. The error is still there, or a new one appears in the same place. You say "still broken." It rewrites a bit more, or it replaces the whole file "to make debugging easier." Ten minutes later you cannot tell what changed, and you still cannot reproduce a passing result.

The routine below is the one I use to stop that spiral. It works in Cursor and in Claude Code. You do not have to understand the whole file. You do have to stop the agent editing before it has reproduced the bug.

This article was first published on the VibePlaybooks site.

A bug that looks mysterious until you run it twice

Here is a small example I used when I tested this playbook. An endpoint /api/total?a=2&b=3 was supposed to return 5. It returned "23". That looks like a weird framework issue until you actually call it. Run the same request twice with no edits and the answer is stable: the handler is concatenating strings, not adding numbers.

If you skip that step, an agent will often "fix" it by reshaping the route, adding a library, or rewriting the file. The concatenation is still there, now harder to see. The first prompt exists to prevent that.

Start a new chat

Old chats are already in the loop. They contain the failed edits, the half-theories, and the urge to keep going. Start a new agent chat for this bug, keep a short rule in .cursor/rules/ that forbids refactors while debugging, and paste Prompt 1.

Prompt 1: evidence only, no edits

This is the prompt that does most of the work. Copy it, fill in the brackets, and do not give permission to edit until you like the hypothesis.

We are debugging. Do not edit any files yet.

Bug: [one sentence].
Steps I take: [1, 2, 3].
Expected: [what should happen].
Actual: [what happens].

Here is the error or log output, pasted in full:

[paste]

Read the code on the path that would run for those steps. Then tell me: (a) the files and functions involved, in order, (b) one hypothesis for the cause, (c) the single smallest check or edit that would prove or disprove it. Wait for my yes before editing.
Enter fullscreen mode Exit fullscreen mode

A good reply names a path through the code, one cause, and one small check. A bad reply starts editing, offers three theories at once, or proposes a rewrite "so we can see what is going on." Send it back if it does any of those.

Prompt 2: one hypothesis, one change

Hypothesis we agreed: [quote it]. Make only the smallest change that tests it. Do not refactor. Then run or re-state the exact reproduction steps, and report what happened. If you cannot run it yourself, give me the exact steps to run and wait.
Enter fullscreen mode Exit fullscreen mode

Re-run the same steps you wrote in Prompt 1. If the agent "also cleaned up" a second file, that is already two changes, and you will not know which one mattered. Revert the extra work.

If it fails, try once more, then stop

A second attempt is allowed. A third silent rewrite is how the hole gets deeper.

The bug is still there. This is attempt two, not a rewrite. Say what the first attempt taught us, name a different hypothesis, and propose one change. Wait for my yes.
Enter fullscreen mode Exit fullscreen mode
Stop editing. Do not try a third fix. Write a short brief I can reuse: steps, expected, actual, the two hypotheses we tested, the exact diffs, and what evidence is missing. List two things I could collect (a log line, a screenshot, a network trace, a value you cannot see). Then wait.
Enter fullscreen mode Exit fullscreen mode

If the agent offers to "rewrite this module so debugging is easier," treat that as a third attempt in disguise. Do not let it. The brief from Prompt 4 is the useful output now.

Once it is actually fixed

Summarise the root cause in five lines or fewer, in plain English. List the files that should stay changed. Confirm there are no leftover debug hacks, extra console logs with secrets, or commented-out blocks from the failed attempts. If there are, remove only those leftovers.
Enter fullscreen mode Exit fullscreen mode

How you know you are done

  • The original steps now produce the expected result, or you have the written brief from Prompt 4 and have stopped the loop.
  • git diff (or the agent's file list) shows a small, relevant change, not a rewritten module.
  • The agent did not delete tests or error handling as part of the "fix."

When it still fails

You may be changing two things at once, code and data, or two files. Go back to one. The reproduction may be wrong: a cached build, an old env, a different port. Confirm you are hitting the code you think you are hitting. If the real problem is "I have no idea what this repo does," write a short project brief first, then come back to Prompt 1.

If the bug is in production only, you still start with Prompt 1. Add the log lines you have. Do not "fix production" by rewriting local files you have not evidenced.

Get the playbook files

The free Debug Loop Breaker sample on GitHub has the Cursor rule, the AGENTS.md section, and the full prompt sequence you can paste into a new chat:

The Vibe Launch Pack (£12) adds 15 more playbooks, including a Stripe Checkout path that only fulfils after a verified webhook, and a check for secret keys leaking into the client bundle.

Top comments (0)