Guides · Updated October 26, 2026
Cline stuck in a loop: how to stop it, roll back, and cap what it spends
Cline runs on your own API key (or Cline credits), and with auto-approve on it keeps going on its own: read a file, edit, run the tests, read the error, edit again. When the model keeps making the same fix and the same test keeps failing, every turn re-sends the whole conversation and the task cost in the header climbs fast. This guide covers how to stop it now, how to get your code back, how to restart without walking back into the same loop, and the limits that keep the next one small.
The short version
- Stop it: hit Cancel on the running task. Nothing else runs until you send a message.
- Get your code back: restore the checkpoint from before the loop started (or use git).
- Restart clean: start a new task with what you learned, not “try again” in the same one.
- Bound the next one: keep command auto-approval narrow, use a key with its own spend limit, and keep an eye on the task cost.
1. What a Cline loop looks like
The common shapes:
- The same terminal command (usually a test or build) runs again and again with the same error, with a small edit in between that doesn’t change the outcome.
- Two edits undo each other: the model fixes A and breaks B, then fixes B and breaks A.
- A tool call keeps failing the same way (a file path that doesn’t exist, an edit block that doesn’t match the file, a malformed tool call from a weaker model) and the model keeps retrying it.
- The task keeps reading the same large files to “re-check” them. Each read adds them to the context again.
Recent versions of Cline have some built-in protection. They watch for repeated identical tool calls and nudge the model to change course, and after a run of consecutive errors the task stops with a message that Cline ran into several errors in a row and asks you for guidance. That catches the obvious cases, like the same failing call over and over. It doesn’t catch a loop where each attempt is slightly different but nothing improves, and it doesn’t put a dollar limit on a task. Older versions had a “max requests” setting in the auto-approve menu; it was removed in v3.35, so don’t rely on finding it.
2. Stop it now
- Cancel the task. The Cancel button stops the current request and leaves the task paused. You can read what happened and decide what to do next.
- If a terminal command is hanging (a dev server, a watch-mode test runner, an interactive prompt), stop it in the terminal too. A command that never exits is a common reason a task sits there or retries.
- Don’t answer with “try again”. The failed attempts are all still in the context. The model sees them and tends to repeat them.
3. Get your code back
With checkpoints enabled, Cline snapshots your workspace as the task goes, in a shadow git repository kept separate from your own. Find a message from before the loop started:
- Review the changes since that point first, so you know what the loop actually touched.
- Restore the code to that checkpoint. Depending on your version you can roll back the files, the conversation, or both. Rolling back the files while keeping the conversation is usually what you want after a loop: you keep the record of what was tried and lose the edits.
Checkpoints track file changes in the workspace. They don’t undo what commands did outside it: installed packages, database migrations, files written elsewhere, anything pushed. If the loop made git commits, recent versions of Cline refuse to restore a checkpoint older than those commits rather than rewriting your branch. Use git reset or git revert yourself in that case. If checkpoints are turned off in settings, git is your rollback, which is another reason to commit before a long auto-approved task.
4. Restart without walking back into it
Open a new task and give it the facts the loop uncovered:
The test in tests/parser.test.ts fails with "Unexpected token }" at line 42. Changing the regex in src/parser.ts did not fix it (tried 4 times). Before editing anything: read src/parser.ts and the test, explain the root cause, and propose one fix. Don't run the tests more than twice.
- Start in Plan mode. Have it explain the cause before it gets to edit. A loop is often a wrong theory being retried; Plan mode makes the theory visible.
- Give it the real output. Paste the full error, or have it run the failing command once and read the whole output instead of a truncated summary.
- Switch models if the model is the problem. Malformed tool calls and edits that don’t match the file are more common on smaller models. A stronger model for the fix, then back to the cheaper one, often costs less than the loop did.
- Narrow the files. Mention the two or three files that matter with
@instead of letting it search and re-read the whole repo.
5. Limits that keep the next loop small
- Put the hard cap on the key. Cline can’t spend past what the key allows. Give it a dedicated key: a credit limit on an OpenRouter key, a spend limit on an Anthropic Console workspace, or a budget on an OpenAI project (check whether it blocks requests or only alerts). Prepaid credit with auto-reload off is the bluntest cap. If you use Cline’s own provider, check your Cline account or organization for spend limits; Cline shows a dedicated error when one is hit.
- Keep command auto-approval narrow. Auto-approving file reads and edits is low risk. Auto-approving every terminal command is what lets a test-fix loop run unattended. Approving commands yourself, or only safe ones, puts you back in the loop every time it reruns the tests.
- Watch the task cost. The task header shows tokens and the estimated API cost for the current task. If the cost keeps climbing and the error hasn’t changed in three or four turns, stop. The estimate depends on known model pricing; your provider’s billing page is the real number.
- Keep context small. Long tasks re-send everything with every request. Start new tasks for new problems, and use compaction or a fresh task when a long one starts to drag.
- Hooks. Cline supports hooks (scripts in
.clinerules/hooksand a global hooks folder) that run at points like task start and before a tool runs, and aPreToolUsehook can cancel the call. That’s the place for a project-specific rule such as refusing to run the same test command a fifth time. Check the hooks documentation for your Cline version for the exact payload and output format before relying on one.
For unattended runs (the Cline CLI in scripts or CI), also bound wall-clock time with timeout or your CI job’s timeout and give the job its own key with a small limit. More in setting a hard budget for AI coding agents in CI.
Where LoopGuard fits
LoopGuard enforces per-session and daily dollar caps and blocks no-progress repeats through the hook systems of Claude Code, Codex CLI and Cursor. It doesn’t guard Cline today, so for Cline the key-level limit above is the hard stop. If you also use one of those three agents, npm i -g loopguard-cli && loopguard init adds the caps in about a minute, and loopguard report shows what each session spent. The general patterns are in how to stop runaway agent loops.
Related
- How to stop runaway Claude Code, Codex and Cursor agent loops
- How to track AI coding agent token costs per session
- How to set a spending limit for Claude Code
- How to limit Cursor agent usage costs
- How to cap OpenAI Codex CLI spend
- Claude Code usage limit reached: why it happens and how to monitor it
- How to set a hard budget for AI coding agents in CI
- Claude Code stuck in a loop: how to break it and stop it repeating the same command
- Codex usage limit reached: 5-hour and weekly limits explained
- Cursor agent stuck in a loop: how to stop it, roll back, and keep it from repeating
- Why Claude Code uses so many tokens, and how to use fewer
- How to set a budget limit for Aider
- GitHub Copilot agent mode stuck in a loop: how to stop it and keep it from repeating
- Gemini CLI usage limits: daily quotas, the June 2026 change, and keeping costs in check
- Codex stuck in a loop: how to stop it, undo it, and keep it from repeating