Your agent isn't broken. It's just expensive. Here's what's actually happening when OpenClaw loops, and the fastest way to stop the bleeding. Updated for OpenClaw v2026.9.6.
It was 11:47 PM on a Tuesday. I'd set up an OpenClaw agent to summarize support tickets and push updates to Slack. Simple workflow. Twenty minutes, tops.
I went to bed.
I woke up to a $38 API bill from Anthropic. For one night.
The agent had gotten stuck in a retry loop. Every failed Slack post triggered another reasoning cycle. Every reasoning cycle packed more context into the prompt. Every prompt burned more tokens. For six hours straight, my agent was essentially arguing with itself about why a Slack webhook URL was wrong, spending real money on every single turn of that argument.
If you're running OpenClaw and you've seen your API costs spike without explanation, you're not alone. And this isn't a bug. It's a design reality of how autonomous agents work.
Here's what's actually going on.
Why Your OpenClaw Agent Gets Stuck in a Loop (It's Not What You Think)
Most people assume a looping agent means something is misconfigured. Bad config. Wrong API key. Broken skill file.
Sometimes, yes. But the more common cause is subtler and more expensive.
OpenClaw agents operate on a reason-act-observe loop. The agent reads its context, decides what to do, takes an action, observes the result, and then reasons again. This is the core pattern behind every agent framework, not just OpenClaw.
The problem starts when the "observe" step returns ambiguous feedback.
Think about it. If a tool call returns "request failed, please try again," the agent should try again. That's what it's designed to do. It's being a good agent. But without a limit on repeated calls, or any awareness of how much each retry costs, it will keep trying. The agent calls the same tool with slightly different parameters, convinced the next attempt will work.
And every single one of those attempts costs tokens.

The Numbers That Should Scare You
Let's do some quick napkin math on what an OpenClaw loop actually costs.
Say your agent is running Claude Sonnet 5. Each reasoning cycle sends the conversation history plus tool definitions plus the latest observation. That's easily 50,000 to 80,000 input tokens per turn once context starts growing.
At Sonnet 5's $2 per million input tokens, that's roughly $0.10 to $0.16 per turn for input alone. Add output (at $10 per million) and thinking tokens and you're looking at roughly $0.12 to $0.20 per reasoning cycle. Prompt caching can bring the input side down, but a loop that keeps appending error messages keeps changing the prompt.
Now imagine 100 cycles in an hour. That's $12 to $20 burned on a single stuck task.
Switch to Claude Opus 5.5 ($4/$20 per million) and the same loop costs about twice as much. Leave it running overnight or over a weekend with nothing to stop it, and the numbers become painful.
A single runaway loop can consume your monthly API budget in hours. This isn't hypothetical. It happens to people building with autonomous agents every single week, and OpenClaw's own issue tracker has a steady stream of loop bugs, from subagent completion notices re-injected on every turn to compaction that doesn't break a repeating pattern.
This is the risk no one talks about in the "just deploy an agent" tutorials.
The Three Loop Types That Drain Your Wallet
Not all loops are created equal. In our experience running managed agents at BetterClaw, we see three patterns over and over again.
1. The Retry Storm
A tool call fails. The agent retries. Same error. Retries again. Each retry adds the error message to context, making the prompt longer and more expensive. The agent isn't learning from the failure. It's just paying more to fail again.
This is the most common pattern. It usually comes from external API timeouts, rate limits, or webhook misconfigurations.
2. The Context Avalanche
This one is sneakier. The agent successfully calls tools, but each tool returns a massive payload. Full file contents. Entire database query results. Complete API responses. The context window balloons with every turn until OpenClaw compacts it, and then the agent can lose track of what it already did and start over.
If you've looked at how OpenClaw handles API costs, you know that context management is half the battle.
3. The Verification Loop
The agent completes a task successfully but then enters a verification cycle. It checks its own work, decides something might be slightly off, "fixes" it, checks again, fixes again. Round and round, perfecting something that was already done, burning tokens on what is essentially AI anxiety.

What OpenClaw Does (And Doesn't) Do About Loops
Here's what no one tells you about self-hosting OpenClaw: it has real loop guardrails now, but the most useful one ships switched off.
According to the current docs, here's what you get out of the box:
- A post-compaction guard (on by default). After a context overflow forces a compaction and retry, OpenClaw watches the next few tool calls. If the agent repeats the exact same tool, arguments and result, it aborts the run with a
compaction_loop_persistederror. This catches the "overflow, compact, do the same thing again" cycle. - Bounded model retries. When the provider rate-limits or fails, OpenClaw retries with exponential backoff, but the budget is capped (up to 10 attempts for rate limits, eight retries inside a 90-second window for other transient failures). Channel sends retry 3 times by default.
- A run timeout.
agents.defaults.timeoutSecondsaborts a run when it expires. The default is 172,800 seconds. That's 48 hours.
And here's what you have to turn on or build yourself:
- Tool-loop detection (off by default).
tools.loopDetection.enabled: truewatches the rolling tool-call history for repeated patterns that make no progress: the same tool with the same inputs returning the same errors, repeated polling, and retries of tools that don't exist. It warns first, by appending a short note to the tool result so the model can change approach. If the pattern continues, it blocks the whole tool batch and gives the model one more response. A second critical loop in the same run ends the run. - A realistic timeout. Forty-eight hours is a long time for a looping agent. For most chat and automation work, something like 30 minutes is plenty.
- Spending limits. The docs don't describe a per-run dollar cap. Your provider's usage alerts and spend limits are the backstop.
The docs specifically recommend turning loop detection on for smaller models, and note that flagship models rarely need it. After waking up to a $38 bill, I'd turn it on regardless.
You can set it globally or per agent (at agents.entries.<agent>.tools.loopDetection), and since v2026.9.5 it's also a toggle in the Control UI under Settings → Agent Defaults → Tools. One gotcha: setting enabled: false explicitly also disables the post-compaction guard. Leave the key unset, or set it to true.
If you're self-hosting OpenClaw on a VPS, all of this is your responsibility.
How to Stop the Bleeding Right Now
If your agent is stuck in a loop right now, here's what to do.
First, stop the run. Send /stop in the chat where the agent is working. It aborts the current run. If the chat is unresponsive, restart the gateway:
# Restart the managed gateway service
openclaw gateway restart
# Or, if you run OpenClaw in Docker, restart your container
docker restart <your-openclaw-container>
Every second it runs is money spent, so don't wait for it to finish gracefully.
Second, check the damage. openclaw gateway usage-cost summarizes cost from session logs (add --days 7 or --agent <id> to narrow it), and /usage cost prints a local cost summary in chat. Then compare against your API provider's dashboard, which is the number you'll actually be billed.
Third, look at the agent's conversation history. Find the point where it started looping. What tool call failed? What was the response? Turn on /verbose on for the next run to see each tool call as it happens. This is your debugging starting point.
Fourth, add guardrails before restarting. Minimum viable guardrails for any OpenClaw deployment: tools.loopDetection.enabled: true, a shorter agents.defaults.timeoutSeconds, and a spending alert with your provider. Fix the root cause too (the broken webhook URL, the missing permission), or the agent will walk straight back into the same wall.
If you want to go deeper on preventing these issues before they start, our guide on OpenClaw best practices covers the full configuration approach.
The Case for Not Managing This Yourself
I'll be direct here. We built BetterClaw because we got tired of being the human circuit breaker for our own agents.
Every self-hosted agent deployment we ran for ourselves had the same lifecycle: set up the agent, it works great for a week, something goes sideways at 2 AM, wake up to a cost spike, spend half a day debugging, add another guardrail, repeat. The agent itself was doing its job. The infrastructure around it was the problem.
BetterClaw is a no-code AI agent platform that runs your agents on managed infrastructure with built-in cost controls, automatic monitoring, and loop detection baked in. There's a free plan with 1 agent and BYOK, and Pro is $49/month for 5 agents. Your first deploy takes about 60 seconds. We handle the sandboxing, the uptime, the security patches, and the "why is my agent spending $50 at 3 AM" problem.
You handle the interesting part: building the actual workflows your agent runs.
The Bigger Picture: Why This Problem Is Getting Worse
Here's something worth thinking about.
As models get smarter, agent loops get more expensive, not less. Context windows used to cap how long a loop could grow before something broke. Today, Claude Opus 5.5 has a million-token context window in OpenClaw's catalog, which means a looping agent can accumulate far more context, and far more cost per turn, before anything forces a stop. Newer models are also better at generating plausible-sounding reasoning, which means they can loop longer before producing output that looks obviously wrong.
The industry is moving toward longer-running, more autonomous agents. That's exciting. But it also means the cost of a stuck agent is going up, not down.
The tools for building agents are getting better every month. The tools for operating agents safely are still catching up. That gap is where your API budget disappears.
This is why operational infrastructure matters as much as the agent framework itself. The difference between self-hosting and a managed platform isn't just about convenience. It's about whether you have production-grade safeguards running by default or whether you're building them from scratch every time.
What I'd Tell Someone Just Getting Started
If you're setting up your first OpenClaw agent today, here's what I wish someone had told me.
Start with a cheap model for testing. Use Claude Haiku 4.5 ($1/$5 per million tokens) or a similarly small model while you're iterating on your skill files and task configurations. Switch to a more capable model only after you've confirmed the workflow runs without loops. Our model comparison guide breaks down when each model makes sense.
Turn on loop detection from day one. It's one line of config, and it's off by default.
Set cost alerts on your API provider dashboard from day one. Anthropic, OpenAI, and Google all let you set usage alerts. A $5 daily alert is a simple early warning system.
Never leave an agent running overnight on the default 48-hour timeout. Just don't. Setting agents.defaults.timeoutSeconds takes 30 seconds and can save you hundreds of dollars over the life of your deployment.
And if you'd rather skip the infrastructure headaches entirely and just focus on what your agent does, give BetterClaw a try. Free plan with 1 agent and BYOK, $49/month for Pro with 5 agents, and your first deploy takes about 60 seconds. We handle the infrastructure. You handle the interesting part.
The Real Cost Isn't the Bill
The thing that actually bothers me about runaway agent loops isn't the money. Money can be recovered.
It's the trust erosion.
Every time an agent loops and burns your budget, it chips away at your confidence in the whole approach. You start second-guessing whether autonomous agents are ready. You add more manual oversight. You reduce the agent's autonomy. And slowly, the thing that was supposed to save you time becomes another system you babysit.
The fix isn't to distrust agents. The fix is to give them proper guardrails so they can be trusted. A well-configured agent with loop detection, a sane timeout, and spending alerts is more autonomous than one you have to watch like a hawk because it might bankrupt you at 3 AM.
Build the guardrails. Trust the agent. Ship the workflow.
Or let us handle the guardrails and skip straight to the good part.
Frequently Asked Questions
Why does my OpenClaw agent get stuck in a loop?
OpenClaw agents loop when tool calls return ambiguous or failed responses without a clear stop condition. The agent's reason-act-observe cycle keeps retrying because it's designed to be persistent. OpenClaw's rolling tool-loop detection is off by default and the default run timeout is 48 hours, so without configuration a stuck agent can keep going for a long time, burning API tokens on every iteration.
How much does an OpenClaw agent loop cost in API fees?
It depends on the model and how large the context has grown. As a rough estimate with Claude Sonnet 5 ($2/$10 per million tokens) and 50,000-80,000 tokens of context per turn, each reasoning cycle costs about $0.12 to $0.20, so 100 cycles in an hour is $12 to $20. Claude Opus 5.5 roughly doubles that. Overnight, it adds up fast.
How do I stop an OpenClaw agent that's stuck in a loop right now?
Send /stop in the chat to abort the current run. If the chat isn't responding, run openclaw gateway restart (or restart your Docker container). Check the damage with openclaw gateway usage-cost and your provider's dashboard. Before letting it run again, set tools.loopDetection.enabled: true, lower agents.defaults.timeoutSeconds from its 48-hour default, and fix the failing tool call that started the loop.
Does OpenClaw have built-in loop detection?
Yes. tools.loopDetection detects repeated no-progress tool calls, warns the model, then blocks the tool batch and ends the run if the loop continues. The rolling detector is off by default, so you have to set enabled: true (globally or per agent). A separate post-compaction guard is on by default and aborts runs that repeat the same call after a compaction retry. Setting enabled: false explicitly turns off both.
Is BetterClaw worth it compared to self-hosting OpenClaw?
If you value your time and want to avoid surprise API bills, yes. BetterClaw is a no-code AI agent platform with built-in monitoring, loop detection, and managed infrastructure. There's a free plan with 1 agent and BYOK, and Pro is $49/month for 5 agents. Self-hosting OpenClaw is free but requires you to handle updates, security patches, uptime monitoring, and configuring your own cost safeguards.
Related Reading
- OpenClaw Not Working: Every Fix in One Guide: Master troubleshooting guide for all common setup issues
- OpenClaw OOM Errors: Complete Fix Guide: Memory crashes that can trigger restart loops
- OpenClaw Memory Fix Guide: Context compaction issues that cause agents to lose track mid-task
- OpenClaw API Costs: What You'll Actually Pay: Understand the cost impact of runaway loops




