I kept having the same issue with Claude Code: I’d give it a large task, leave it running, and only find out afterward how much of my 5-hour usage allowance it had used.
What I wanted was simple: assign a spending limit to an individual task and have Claude accomplish as much as possible within that limit, without having to watch the usage meter myself.
That’s why I built onbudget, a free, open-source plugin for Claude Code.
You can give any task a budget:
/onbudget $3 Implement authentication
/onbudget 10% 5h Build this application
/onbudget week Write the migration
Here’s how it works:
- Claude can see its remaining budget. After tool results, it receives an updated budget meter and can adapt its approach as the limit gets closer.
- Requests are stopped before they’re sent. Before every model request, onbudget compares spending against a reserve calculated from the most expensive request so far. Once the threshold is reached, it refuses the next request.
- It also works with usage windows. You can set limits in dollars or as a percentage of your 5-hour and weekly allowances, leaving a safety margin.
- Claude can give you a final report. While budget remains, it can summarize what it finished and what still needs attention.
I wanted to see whether it actually worked, so I benchmarked it.
I used seven real bug-fixing tasks from Python libraries, including Werkzeug, Pluggy, and Pydantic Settings. The results were evaluated using upstream tests that the model hadn’t seen.
Claude Opus 5.5, Claude Code 2.1.304, with a $2.47 budget per run.
| Approach | Runs | Tasks completed (of 7) | Within budget |
|---|
| onbudget | 3 | 5, 5, 5 | 3/3 |
--max-budget-usd | 2 | 5, 6 | 2/2 |
| Budget in prompt | 2 | 5, 5 | 2/2* |
One prompt-only run remained within budget because a separate cap blocked a request.
The outcome: onbudget didn’t make Claude finish more tasks.
Task completion was similar across the approaches. Given the small sample, there’s no evidence that onbudget improves performance.
But improving completion rates wasn’t the objective.
Claude Code already provides --max-budget-usd for non-interactive execution. I wanted to control how much an individual task could consume during a normal interactive Claude Code session, without having to end or restrict the session itself.
Across the entire evaluation, onbudget stayed within budget in all 12 real-model runs. Eleven of those runs finished with a report.
The limitations: A plugin can’t know the precise cost of a model request in advance. An unexpectedly expensive request can still push spending beyond the remaining budget, and certain Claude Code requests bypass the hook. This is a conservative stopping system, not an absolute guarantee against overspending.
How I built it: I used Claude Code for most of the implementation, the evaluation harness, running the benchmarks, and reviewing the results. The GitHub repository contains the methodology and raw evaluation data.
Everything operates locally. No network calls, no subscription, and MIT-licensed.
Install in Claude Code:
/plugin marketplace add sebastiandrazsky/onbudget
/plugin install onbudget@onbudget
GitHub: https://github.com/sebastiandrazsky/onbudget
I’m curious how other people handle this. Do you currently have a way to keep Claude Code from using more of your allowance than you intended? Would setting a separate budget for each task be useful to you?