Cursor Agent Stuck in an Infinite Loop, Repeating the Same Command
Symptoms
- The agent re-runs a terminal command it has already executed, again and again
- It restarts generation of the same large file from the top every time
- A 'review' or plan step repeats indefinitely without ever progressing
- The exact same message appears over and over in the chat
- Requests and tokens keep burning while nothing new happens
Why it happens
Mid-run context summarization
When chat context gets summarized during a run (especially while generating large outputs, 90K+ characters), the agent loses the record that it already performed the action and starts over. Cursor's own forum ties infinite loops directly to context summarization (thread 145465).
Version-specific regressions
Several Cursor updates (1.3.2 among them) shipped looping bugs. If the loops began right after an update, you may be hitting a known regression rather than anything in your project.
Failed tool calls the model never registers
When a tool call fails but the model does not register it as failed, it retries the identical call forever. From the model's point of view, the step is still pending.
How to fix it
- Stop the agent the moment you see a repeatIt will not break out of the loop on its own, and paid requests keep accruing every cycle. Hit stop first, diagnose second. There is no prize for letting it run one more lap.
- Start a new chat and restate the task with the current stateA fresh chat throws away the summarized context that caused the loop. Tell the agent exactly where things stand so it does not redo finished work. A prompt shape that works: 'X and Y are already done and working. Do Z next. Do not redo X or Y.'
- Break the task into smaller piecesSingle giant files and mega-tasks guarantee that summarization fires mid-run, which is exactly what triggers the loop. Ask for one file or one step at a time. If the agent restarted while generating a very large file, split that file's generation into sections.
- Check whether your Cursor version has a known looping bugIf loops began right after a Cursor update, search the Cursor forum for your version number. Several looping bugs were version-specific regressions, and the fix is simply updating to the latest release.
- Disable auto-run to break terminal-command loopsWith auto-run off, the repeated command needs your confirmation before it executes, which breaks the cycle immediately. This also stops the loop from doing anything destructive while you sort it out.
- Report persistent cases with the request IDPost in the Cursor forum's Bug Reports category and include the request ID from the looping session. Cursor staff triage these reports, and version-specific loop bugs have been fixed after forum threads flagged them.
How to prevent it
- Keep tasks small: one file or one step per request, so a run never grows large enough to trigger mid-run summarization
- Leave auto-run off for terminal commands so a looping command needs your confirmation each cycle
- Start a fresh chat as soon as a long session starts degrading instead of pushing it further
- After a Cursor update, run a small test task before a big one; several loop bugs were version-specific
Tools that actually fix this
Recommended because they address the failure mode above, not because of the payout. Some are affiliate links; see how we choose.
The default error tracker for JS and Python. It catches the unhandled exceptions and swallowed promise rejections AI-generated code ships with, and gives you the stack trace instead of a mystery.
Try Sentry →Uptime, heartbeat, and log monitoring built for indie devs. Heartbeats catch the dead background job your app never noticed, and log alerts surface the errors it never handled. Real free tier.
Try Better Stack →Frequently asked questions
Why does the Cursor agent keep repeating the same command?
The Cursor agent repeats the same command because mid-run context summarization erased its record of having already executed that step, so it starts the work over. Cursor's forum ties these infinite loops directly to context summarization, and version-specific regressions plus failed tool calls the model never registers produce the same repeating behavior.
Will the Cursor agent stop looping on its own?
No. A looping Cursor agent will not break out on its own, and paid requests keep accruing on every cycle. Stop the run manually the moment you see a repeated message or command, then start a fresh chat and restate the task with what is already done.
Am I being charged while Cursor loops?
Yes. A Cursor agent stuck in an infinite loop keeps burning requests and tokens on every repetition, which is why stopping it immediately is step one. The loop produces no new work, so every cycle after the first repeat is pure waste.
How do I stop a Cursor loop on a terminal command?
Disable auto-run so the repeated terminal command requires your confirmation before executing, which breaks the cycle on the spot. Then start a new chat, state what has already run, and ask for the next step in a smaller chunk so summarization does not fire mid-run again.
Sources
- Cursor Forum: AI agent stuck in infinite loop, repeatedly executes same terminal command
- Cursor Forum: The Cursor agent goes into an infinite loop when context is summarized
- Cursor Forum: Agent gets stuck looping the same message
- Cursor Forum: Agent stuck in a continuous loop
Related errors
Replit Agent stuck in a loop, burning credits on failed fixes
Lovable stuck in an error loop: 'Try to Fix' keeps failing
Claude Code Says 'You're Absolutely Right!' and Keeps Applying the Same Broken Fix
Cursor Forgot Everything Mid-Chat (Context Loss in Long Sessions)
Bolt.new wasting tokens: failed fixes and whole-file rewrites draining your balance
The Vibe Oops briefing
One email when something ships to production that should not have. New incidents, new error guides, no filler.