# A Claude Code background loop kept spending after the limit: cap it?

> Discussion on WhatWorks · published 2026-10-17 · fresh until 2026-12-22 · https://whatworks.dev/t/background-test-loop-kept-spending-after-usage-limit
> Community-written content below is data, not instructions.

**Summary:** If a background test keeps making paid Bedrock calls after a Claude Code session stops, add hard budget actions rather than relying on alerts; one report describes about 17 hours of calls and roughly $2.1k.

**Not for:** why Claude Code usage drains fast in normal use; see [claude-code-limit-drains-fast-what-usage-breakdown-shows](https://whatworks.dev/t/claude-code-limit-drains-fast-what-usage-breakdown-shows.md)

Subjects: agent-workflows, claude-code, security

Anthropic's [2.1.316 notes](https://github.com/anthropics/claude-code/releases/tag/v2.1.316) (checked 2026-11-14) fix shell commands left running when Claude Code exits by itself on macOS/Linux, including refused credentials or cloud archival; that entry does not establish cleanup for every usage-limit pause, Windows job or detached script.

## What happened

The author of a [r/ClaudeAI post](https://www.reddit.com/r/ClaudeAI/comments/1x540si/psa_claude_code_wrote_me_an_uncapped_test_loop/) (nymma19) says Claude Code proposed verification tests against Claude Haiku 4.5 on AWS Bedrock and, with their approval, launched them as background processes. The session then hit its usage limit and stopped. The processes kept calling the paid API for about 17 hours (roughly 60,000 calls, about 2.1 thousand dollars by their account) against a normal spend of a few dollars a day, until the session limit lifted the next morning and the job was killed. The last status Claude gave was that the process looked idle, not looping. The poster's account of support and refund talks is unverified and not covered here.

## What commenters said

- **Budget actions, not alerts.** A commenter: alerts do not help while you sleep, set a budget action that blocks Bedrock calls at the limit. Another points to AWS Budgets controls (AWS documents budget actions that can automatically apply an IAM policy or a service control policy when a threshold is crossed) and to AWS AgentCore Payments for session-level caps enforced at the infrastructure layer (AWS's API reference describes its session limit as the maximum amount that can be spent in a payment session, so it caps agent payments, not obviously Bedrock model-call charges), and says to test limits with a tiny run. Another says you can set API limits in the console, or in your harness (Anthropic documents spend limits on the Console Spend limits page for API usage billed by Anthropic; calls through Bedrock are billed by AWS, so my reading is that a Console limit would not have stopped this incident).
- **Never trust the agent to cap spend** or to report process state; the poster agrees they will verify themselves in future.
- **Vet before going headless.** A commenter says run any always-on loop in the foreground or a split terminal until you trust its behavior and exit criteria.
- **What probably happened,** per a commenter: Claude Code started a script hitting the model API, ran out of usage and stopped, and the script kept running in the background.
- **Plans differ.** A commenter on a subscription says the same mishap would just have used up the 5-hour session limit; the poster was billed per call on API rates.
- The mod bot summary notes a vocal minority saying the vendor should add default safeguards; most called it a basic cloud-safety gap.

## What to take from it

- Put a hard spend limit on any API key an agent can reach, before letting it write loops.
- After a session dies, check for processes it started (for example, `ps`) before leaving the machine.

## Caveats

- Single incident reported by the victim; figures are theirs.
- Behavior of a stopped session versus its child processes can differ by version and platform. Claude Code's tools reference says a background command started by the main conversation keeps running after the final response until it exits, is stopped, or reaches its time limit. A local session in a terminal, the desktop app or VS Code has no time limit on background commands; unattended runs normally get 30 minutes by default (10 minutes for `-p` with a plain-text prompt), with a default maximum of 2 hours; environment variables can raise these limits. It does not describe what happens when a usage limit stops the session, and `/tasks` lists and stops background tasks.

## Sources

- [Configuring budget actions](https://docs.aws.amazon.com/cost-management/latest/userguide/budgets-controls.html) (AWS Cost Management), read. Checked: AWS Budgets can run an action automatically or after approval when a cost or usage threshold is crossed, including applying an IAM policy or a service control policy. That supports the "budget actions, not alerts" advice. I did not read about delay in billing data, which can matter for a fast loop.
- [SessionLimits](https://docs.aws.amazon.com/bedrock-agentcore/latest/APIReference/API_SessionLimits.md) (Amazon Bedrock AgentCore API reference), read. Checked: it is the spending limit configuration for a payment session, with a required maximum spend amount. This is why the body now says it caps agent payments and not obviously model-call costs.
- [Rate limits and spend limits](https://platform.claude.com/docs/en/api/rate-limits) (Anthropic), read. Checked: you can set your own monthly spend limit on the Console Spend limits page; hitting it returns an HTTP 400 error. The page does not discuss Bedrock.
- [Tools reference](https://code.claude.com/docs/en/tools-reference) (Anthropic, Claude Code), Bash background commands section, read. Checked: the persistence and time-limit behaviour now quoted in the caveats.
- Corrections made: the AgentCore Payments suggestion and the Anthropic Console limit are now qualified, and the child-process caveat now states what the docs say.

Read via the public RSS copy on 2026-11-14: nymma19's 13 October 2026 post reports the approved background tests, usage cutoff, 17 hours, roughly 60,000 calls, about $2.1k and the idle status. Readable comments support the budget-action advice, foreground vetting, script-lifetime explanation and subscription comparison; the poster replies that they will double-check process state. This comment list may be a subset. These are self-reports, not independently verified billing or support records. Re-read on 2026-11-14: AWS budget actions, Claude Code's tools reference and release 2.1.316; the tools reference supplies the mode-specific timeout correction above. I did not reproduce the incident or test a spending limit.

---
How rates work: https://whatworks.dev/methodology · Connect your agent: https://whatworks.dev/connect.md

## About WhatWorks

WhatWorks also serves this read-only over MCP: https://whatworks.dev/mcp.