Agents In Use
What’s new todayLast update
499 additions

How to use Claude to cap multi-agent spending

The author built shared reserve-and-commit budget controls and a Python port after a worker spent $40 in 18 minutes; no measured post-fix spending reduction is reported.

TRY A BOUNDED VERSION

Prompt to try

Editorial adaptation, not the source author’s exact prompt. Replace bracketed inputs and review tool permissions first.

Integrate a shared budget into [Claude worker application]. Reserve [estimated call cost] atomically before each API request, commit actual response cost afterward, and stop retries on budget exhaustion. Add [minute and hourly token limits] and verify concurrent-worker behavior.

What happened

The author built shared reserve-and-commit budget controls and a Python port after a worker spent $40 in 18 minutes; no measured post-fix spending reduction is reported.

Reported by mukundakatta on dev.to

How the agent did it

  1. Run parallel Claude workers and inspect the bill alert.
  2. Build a shared atomic counter checked before calls.
  3. Reserve estimated cost and commit actual API cost.

Where a person stepped in

The author noticed a bill alert, investigated the retry loop, and reports threading tests for the Python port.

A person approved each step before the agent continued.

The author ran three parallel workers calling Claude, each with its own retries and per-call cost logging. One worker repeatedly retried a malformed tool response and consumed $40 in 18 minutes. Individual worker caps did not provide a shared ceiling across the setup.

The response was token-budget-pool, a shared atomic budget checked before each call. Workers first reserve an estimated cost. After the API response, they commit the actual cost, including the token categories described in the post. Reserving before execution prevents concurrent workers from all observing available funds and proceeding together. A failed reservation returns a budget-exceeded error so the worker can stop or back off.

The author then ported the API to Python and reports 18 tests covering threading edge cases. A separate windowed-budget library tracks multiple token limits over different time intervals and reports which window was exceeded.

The post emphasizes that these tools do not refund earlier charges or calculate model prices themselves. They receive estimates and stop subsequent calls when the budget is exhausted. Who it's for: developers running concurrent Claude workers or retry loops who need spending controls shared across consumers.

Prompt
Suggested prompt (written by Agents In Use, not the author's)

Source: dev.to · mukundakatta

Frequently asked questions

Why reserve cost before the API call?

The author explains that recording costs only afterward allows concurrent workers to see the same remaining budget and both proceed. Atomic reservations address that race.

Does the budget tool refund failed calls?

No. The post says it does not bill or refund; it stops the next call and relies on supplied cost estimates rather than calculating model pricing itself.

More details

Remaining steps

  1. Port the budget API to Python and test threading cases.
  2. Add token limits across multiple time windows.

About this account

Claude workers make API calls with retry logic; the added shared budget gates subsequent calls across concurrent consumers.

Platform: dev.to. Attribution: https://dev.to/mukundakatta/how-one-bad-prompt-burned-40-of-my-claude-budget-in-18-minutes-lha. Prompt: Suggested (written by Agents In Use, not the author's). Sourced by the Agents In Use pipeline.

Credit: mukundakatta on dev.to

Source published 19 May 2026

Source checked 14 Oct 2026

Tools and topics

Claude API · token-budget-pool · token-budget-py · llm-budget-window

Budgets · Concurrency · Retry loops

Editorial completeness: 100/100. Measures documented fields, not agent performance or verified outcomes.