Help for owners
My AI agent keeps looping and my usage bill is rising
Short answer
An agent works in a loop: the model asks for a tool, your code runs it and returns the result, and this repeats until the model answers. Without a step limit, a budget and a check for repeated calls, a confused agent can go round indefinitely, and every round costs tokens.
Does this sound like your situation?
- The usage dashboard shows a sudden jump.
- The agent keeps calling the same tool.
- Tasks never finish.
- Costs differ wildly between runs.
- I cannot tell what it did.
Why does this happen?
The loop is how agents work
The model returns a tool request, your application runs it and sends back a result, and the model continues. Nothing in that cycle stops it on its own.
Confirmed by platform.claude.com
Every round adds to the bill
Pricing depends on the input tokens sent, including tool definitions and results, and the output tokens generated. Server-side tools can add usage-based charges.
Confirmed by platform.claude.com
The conversation grows each time
Each turn carries all earlier turns, tool results included. Anthropic notes that as token count grows, accuracy and recall degrade, so long loops also get worse at the task.
Confirmed by platform.claude.com
A tool keeps returning an error or nothing
If a tool fails or returns no useful data, the model may retry the same call. Without a rule to stop, it repeats.
Nobody set a ceiling
No maximum steps, no spending alert and no timeout means the first sign is the invoice.
What can I do about it today?
- Check the provider's usage pageSee which key and date caused the jump.
- Pause the automationTurn off the schedule or trigger that starts the agent, and keep the logs.
- Set a spending limitUse the provider's own limit or alert settings if they exist.
- Rotate the key if it leakedIf you did not start the usage, create a new key and remove the old one.
- Do not delete logsThey show which tool looped.
When should I bring someone in?
- Spend is high and you do not know why.
- The agent can change data or send messages.
- You need it running unattended.
How do I handle it?
- Read the tracesI look at the sequence of tool calls to find the repeat.
- Cap the loopMaximum steps, maximum tokens and a time limit for every run.
- Detect repeatsThe same call with the same input twice stops the run and raises an alert.
- Make tool errors clearA tool returns a plain message the model can act on, or tells it to stop.
- Add cost alerts and a logUsage per run is recorded and an alert fires on unusual cost.
The price depends on what I find, so I quote in writing after a short discovery call. Tell me what is happening and I reply within 24 hours.
What do owners ask about this?
Is looping a bug in the model?
Usually it is a missing limit or a tool that keeps failing, not the model alone.
Will a cheaper model fix it?
It may lower the cost per round, but without limits the loop remains.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Found a mistake? Tell me.