Related ToolsClaudeClaude Code

One Unattended Claude Loop Cost a Developer $6,000 Overnight

Claude by Anthropic
Image: Anthropic

One evening in late April, a developer set what seemed like a routine automation before going to bed: a loop command instructing Claude to check open GitHub pull requests every 30 minutes and summarize any activity. By the next morning, $6,000 of API budget was gone.

After digging through session logs, the developer found the culprit. The loop had run 46 times over 26 hours, unattended, on Claude Opus 4.7 - Anthropic's most capable and most expensive model tier. A second session, a long analytics run left open in the background, compounded the damage. Together, the two sessions burned through the account's usage limit and generated a bill large enough to cover several months of almost any professional SaaS subscription.

This is the cost profile of agentic AI made visible: software that takes repeated actions on your behalf without needing a human to approve each step.

How the Math Got to $6,000

Each loop iteration read PR descriptions, comments, and code diffs, then generated a summary. That's a text-heavy task. In AI billing, text is measured in tokens (roughly one token per word), and a single PR thread with inline comments can easily run 5,000 to 15,000 tokens. On Claude Opus, the premium tier, the cost per token is significantly higher than on Sonnet or Haiku, Anthropic's mid-tier and entry options.

Multiply that by 46 iterations. Add a second active session running simultaneously. The bill compounds with no natural stopping point unless you've set a hard spending cap - which the developer had not.

What to Configure Before Running Any Automated Loop

Claude Code and Claude's API both support controls that would have limited or prevented this:

Choose the right model tier. Claude Opus is built for complex, multi-step reasoning - legal document analysis, architecture review, nuanced writing. Checking whether a PR has new comments is not that. Claude Sonnet handles structured monitoring work well and costs roughly 80% less per token. Match the model to the complexity of the task, not the maximum capability available.

Set an iteration cap. Loop commands can be configured with a maximum run count. Even a cap of 10 iterations would have reduced the exposure to under $1,500 in this scenario.

Set a monthly usage limit. Anthropic's API allows a hard spending cap per billing period. The default ceiling is high enough that a runaway overnight loop causes serious damage before triggering it. Set it to an amount you'd actually notice.

Close sessions you're not monitoring. The second session - an analytics run left idle in the background - added to the total cost without producing useful output. Agentic sessions that aren't actively supervised should be closed, not left running.

The underlying use case here (automated PR monitoring) is reasonable. Running it on the most expensive model tier, with no iteration limit, on an account without a spend cap, while leaving a second session idle in the background - each choice was worth reconsidering. Together, they created the conditions for a $6,000 overnight bill.