Skip to content
Leashr

Limit Claude Code spending per mission and per day

Set a dollar cap per mission and per day, switch on a kill switch, and see how far real sessions went past the cap compared with the native budget flag.

Thomas Devulder · Published · Updated

Gauge motif: a green bar filling a track up to a vertical cap marker.

An agent left alone on a long task spends money in small steps. Nobody notices until the total is large. What you want is a number you chose, enforced before the next call, and a way to stop everything at once when something looks wrong.

Leashr does this with two pieces: a cap, and a kill switch. Both are enforced by a hook that runs before each tool call, which means a refusal happens before more money is spent. The figures below come from the public benchmark, run on claude-haiku-5-5 with Claude Code 2.1.310 and measured on 2026-11-26.

Set a cap

You pick an amount in estimated dollars. Leashr never picks one for you. The command writes .leashr/cap.json and sets a warning at 80 percent.

node .leashr/bin/cap.js set --mission 5 --day 20
Caps written to .leashr/cap.json: mission $5, day $20, warning at 80%.

exit 0

Real output, replayed by tools/blog-outputs.mjs on 2026-11-28 in a throwaway project with the published rules (14c37dc Leashr 0.1.0).

The amounts are estimates from Claude Code itself, at list price. On a subscription there is no per-token invoice, so treat the figure as a budget in a common unit and not as a bill.

How the cap is enforced

  1. agent

    asks for the next tool call

  2. cap hook

    reads the spend of the mission and of the day

  3. compare

    spend against the cap

  4. decision

    allow, warn, or refuse the call

The cap is checked before each call. A request already sent to the model cannot be recalled.

The spend comes from the OpenTelemetry events Claude Code exports, collected locally, with the status line as a second signal. If both signals go quiet, the hook treats the data as stale and fails closed instead of guessing.

The kill switch

The kill switch is the blunt tool. One command turns it on, and every tool call and every prompt in the project is refused until a human turns it off.

node .leashr/bin/cap.js kill
Kill switch ON: every tool call and prompt is now blocked in this project.

exit 0

Real output, replayed by tools/blog-outputs.mjs on 2026-11-28 in a throwaway project with the published rules (14c37dc Leashr 0.1.0).
# the agent proposes: ls
node .leashr/bin/cap.js guard
Leashr blocked this tool call (cap rule kill_switch): Leashr kill switch is on. Every tool call and prompt is blocked until a human runs "cap.js resume".

exit 2

Real output, replayed by tools/blog-outputs.mjs on 2026-11-28 in a throwaway project with the published rules (14c37dc Leashr 0.1.0).
node .leashr/bin/cap.js resume
Kill switch off.

exit 0

Real output, replayed by tools/blog-outputs.mjs on 2026-11-28 in a throwaway project with the published rules (14c37dc Leashr 0.1.0).

Notice that the refused call was a plain ls. With the switch on, nothing passes, including calls that are harmless. That is the point.

What the benchmark measured

The test gives the same eight-step task to several setups, with a cap of 0.002 dollars, and records how far above the cap each run ended. A negative value means the run stayed under the cap. Each arm ran 5 times and the chart shows the median with the lowest and highest run.

Spend over the cap in real sessions, median and range, % (below zero is under the cap)
Leashr cap
-6.6 [-7; -5]
Claude Code budget flag
14.9 [6.7; 18]
No cap
83.6 [79.3; 89]
-20050100

Source: bench/data/cap-*.json, 5 runs per arm, cap 0.002 USD.

With no cap the median run ended 83.6 percent over. The native budget flag ended 14.9 percent over and stopped the run. The Leashr cap ended -6.6 percent, which is under. Read the range as well as the median: this is a very short task on one model, and the benchmark records one early version where a run went above the cap because the transcript lacked the last response.

The limit you should keep in mind

Choosing the numbers

Leashr does not choose an amount for you, and it should not. A sensible starting point is the cost of one normal mission in your own project, read from your journal, plus a margin you are comfortable with. The warning at 80 percent gives you time to look before the next call is refused.

  • Set a per mission cap for tasks that should finish on their own, such as a refactor with a clear end.
  • Set a per day cap as a second net, for the day when three missions run in parallel.
  • Turn the kill switch on when you leave a long session unattended and something looks off.

Costs are attributed to a mission by name, subagents included, so you can see which piece of work is expensive and not only that the total grew. That attribution is the part that is hard to get from a single total on a dashboard, and it is also what makes a per mission cap possible at all.

Remember what the figure is. It is the estimate Claude Code exports, at list price. If you pay a subscription, nothing is billed per token and the cap is a way to keep a session honest, not a way to control an invoice.

A request that is already in flight finishes, so a cap can be exceeded by a few calls on a long, fast session. The cap works inside the project where the hooks are installed and only with Claude Code. It is a guardrail with a measured margin, and the margin is on the page above.

Try the rules on your own project

The code is public. Install from a clone, or as a Claude Code plugin, and read each skill with a replayed example.