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.
Suggested prompt
Suggested prompt written by Agents In Use, not the source author. 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.
Reach people exploring AI agents
See placements →Evidence at a glance
Sourced account- Source author
- mukundakatta
- Original account
- Read the source ↗
- Published
- Source link checked
- Reported result
- 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.
- Human involvement
- The author noticed a bill alert, investigated the retry loop, and reports threading tests for the Python port.
A linked account supports attribution. It does not mean we independently reproduced its result.
Report an issue with this case
Open correction emailOpens your email app with the case link included. Nothing is sent automatically.
How the agent did it
- Run parallel Claude workers and inspect the bill alert.
- Build a shared atomic counter checked before calls.
- Reserve estimated cost and commit actual API cost.
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
- Port the budget API to Python and test threading cases.
- 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
Added to Agents In Use
Source checked
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.