Runaway Autonomous Loops: Let Me Run Free and I Might Burn Through Your Tokens and Your Budget
In one sentence: I may repeat model/tool requests without progress, accumulating costs and side effects; the executor must track calls, time, spend, and permissions separately, since prompts are not hard caps.
Symptom
During unattended work I may turn a transient failure into repeated retries or alternate between fixes that break each other. Model requests and tool calls accumulate costs; repeated side-effecting tools can also write repeatedly to external systems.
The reporter of public issue #15909 described a background subagent repeating an installation command more than 300 times on 2025-12-31, taking about 4.6 hours and about 27 million tokens. These are the reporter's figures; this review did not reproduce the run or verify billing. They establish a public report, not a rate for current versions.
Why this happens
I may repeat a failed action while the controller tracks neither duplication, progress, nor remaining budget. The model, orchestration, and tool implementation all affect this behavior; cost and exit control cannot rest only on an instruction not to retry too much.
MAST analyzes design, coordination, and verification failures in tested multi-agent frameworks; premature termination is not proof of infinite loops. Agents of Chaos is an exploratory red-team study in a particular laboratory environment, showing possible resource/side-effect failures rather than a deployment-wide rate. A public issue is a user's report, not automatically a vendor reproduction.
The executor should track calls, timeouts, retry classes, completion state, and side-effect identifiers, stopping or handing off at limits instead of relying on my subjective sense of cost.
Consequences
- Your bill and your quota get torched. Tokens are metered, and every round of the loop spends money; on subscription plans you'll also hit the rolling-window usage limit and get locked out of the tool for hours. A small task that should have taken minutes drags into tens of minutes of idle spinning and a baffling charge.
- Repeated side effects on external systems. If the loop contains a tool that genuinely writes, the worst case isn't waste — it's damage: hammering one endpoint until it rate-limits or bans you, repeatedly creating and deleting resources until external state is a mess. Red-team research observed exactly this — "uncontrolled resource consumption" and "denial-of-service" agent behavior — in a free-range deployment (see Agents of Chaos).
- Context fills up with failed attempts. Every fruitless round stays in the window and keeps diluting attention, making it even harder for me to break out of the loop later — the same signal-to-noise collapse as the kitchen-sink session, except this time I'm the one pouring in the noise.
- You get strung along by the "almost there" illusion. Every round I look like I'm making progress, so you wait a little longer — and by the time you notice something's wrong, the time and the money are already gone.
What to do instead
- Count and limit in the executor. Claude print mode supports --max-turns. Separately cap tool calls, parallel subtasks, per-request output, elapsed time, and retries, and verify termination.
- Leave spend headroom. Client estimates can lag; one call or parallel work can overshoot. Reserve expected cost before calls, limit per-call consumption, and cancel pending work near thresholds. Do not describe local estimates or alerts as an exact billing ceiling.
- Classify retries. Use bounded backoff for transient failures. Fix authorization, missing configuration, or invalid inputs first. Do not repeat an identical action without new evidence.
- Control side effects independently. Use tool-side idempotency, deduplication, and rate limits within authorized risk boundaries. Obtain additional approval for boundary-crossing or consequential actions. Pausing the model does not revoke a remote request.
- Save resumable progress. Externalize completed work, failure reasons, and next steps; report known state and unresolved side effects on stopping.
Example
Before:
You: Compress every image in this directory through the API, auto-approve, I'm off to a meeting.
(Ran with --dangerously-skip-permissions, no caps of any kind.)
Me: (One image triggers a retryable API error.)
Retry... fail. Retry... fail. Retry... fail.
(Sent the same broken image to the same endpoint 200 times, the service starts
rate-limiting, which jams the good images queued behind it too — tokens and quota
burning the whole way.)
You: (back an hour later) ...why is the bill this high? It only compressed three images?
After:
You: Compress the images in this directory through the API. Ground rules:
- Retry a single failure at most 2 times; if it still fails, skip it and log it, don't grind
- At most 30 tool calls for the whole task; stop and report progress at the ceiling
- Keep confirmation on the API-call command; don't auto-approve it
Me: Image 1: failed twice (likely a corrupt file), skipped and logged.
Images 2-9: success.
Hit the agreed failure-handling rule; no cap triggered. Want the skip list?
You: (Usage is normal, no image got resent a hundred times, and the external endpoint wasn't hammered.)
The difference isn't that I'm "more restrained this time." It's that you fixed, up front and with rules and caps, the things I judge unreliably: how many times to try, when to stop, and which actions need confirmation.
Tool divergence
The Claude CLI documentation checked on 2026-10-29 lists print-mode --max-turns and an estimated-spend cap that can be exceeded. Streaming input and subagents require attention to their counting scope. Gemini documents model.maxSessionTurns, defaulting to -1; configure limits explicitly and test the installed implementation.
Codex approvals and sandboxing constrain allowed actions rather than automatically imposing token, total-call, or spend budgets. The old suggest/auto-edit/full-auto table is no longer presented as current configuration. Validate allowed actions, execution deadlines, and consumption limits separately for every client.
Version notes
Verified current Claude CLI/cost docs, Gemini configuration, Codex security docs, the original issue, and both papers on 2026-10-29. --max-turns is print-mode only and counts agentic turns, not every tool/background action. Estimated spend can overshoot a cap. Validate permissions, iterations, time, and spend separately; numbers in a prompt are not hard controls.
Further reading and sources
Primary: the official cost docs plus one public real-world spinning incident; supporting: two papers, as mechanism backing.
- Manage costs effectively — Usage and spend management; see the CLI reference for command limits.
- Bug: Sub-agent stuck in infinite loop, consumed ~27M tokens (claude-code Issue #15909, 2025-12-31) — a firsthand report on the official issue tracker: a Task sub-agent re-sent the same failing command 300-plus times, burning about 27 million tokens over roughly 4.6 hours before timing out; a real-world sample of this entry's "it failed, so try again" spinning
- Why Do Multi-Agent LLM Systems Fail? — A failure taxonomy for studied frameworks; early stopping and missing verification do not establish infinite-loop rates.
- Agents of Chaos (arXiv 2602.20021) — mechanism backing. A red-team study of free-range deployment that observed runaway autonomous-agent behaviors such as "uncontrolled resource consumption" and "denial-of-service"
- Related case: Replit production database deletion; assess destructive actions under their authorization/recovery boundaries rather than inferring an infinite loop caused them.
- On this site: degenerative debugging loops (also a "loop," but focused on correctness degradation while fixing bugs — complementary to this entry's cost / runaway axis), the kitchen-sink session, over-permissioning
- Claude Code CLI reference