Guides · Updated October 19, 2026
How to set a spending limit for Claude Code
Claude Code has several real spend controls, but each one works at a different level: a monthly limit on your account, or a per-run cap for scripted runs. What it does not have is a dollar cap for the interactive session you leave running. This guide covers the built-in options first, by how you pay, and then how to add per-session and daily caps with a hook.
First: how are you paying?
The right control depends on where Claude Code’s usage is billed:
| You use Claude Code with | The ceiling you already have | Native limit you can set |
|---|---|---|
| An API key / Claude Console | None by default; billed per token | Workspace spend limit in the Console |
| Claude Pro or Max | Your plan’s usage limits (5-hour and weekly) | Monthly spend limit on usage credits, or keep usage credits off |
| Claude Team or Enterprise | Each seat’s allowance | Admin spend limits on usage credits (organization, group or member) |
| Amazon Bedrock, Google Cloud or Microsoft Foundry | Your cloud account | Your cloud provider’s budget controls |
API key users: set a Console workspace spend limit
When you first sign Claude Code in with a Claude Console account, the Console creates a workspace called “Claude Code” that all Claude Code usage is billed to. Set a spend limit on that workspace (see Anthropic’s workspace docs) and Claude Code stops getting responses once the workspace reaches it. You can also set a workspace rate limit there so Claude Code can’t starve your production traffic of rate limit.
This is the right backstop for a monthly budget. It is not a per-session limit: one bad overnight run can still use the whole month’s allowance before it trips.
Pro and Max: decide what happens at your plan limit
On a subscription, your plan’s usage limits are already a hard ceiling. You hit them and you wait for the reset. The only way to spend more money is usage credits (previously called extra usage), which let you keep working past the limit at a cost:
- Run
/usage-creditsin Claude Code. It opens Settings → Usage on claude.ai, where you turn usage credits on or off and set a monthly spend limit. - Leave usage credits off if you never want to pay beyond the plan. If you turn them on, set a limit. When you reach it with credits still available, Claude Code prompts you to raise or remove the limit rather than spending past it.
/usage(also available as/cost) shows your plan usage bars, a usage-credits row with this month’s spend against your limit, and a breakdown of what is eating your limits.
Even with no money at stake, a looping session can burn through your 5-hour or weekly limit and lock you out for days. The per-session cap below helps with that too. For what each limit message means and how to watch your usage, see Claude Code usage limits.
Team and Enterprise: admin spend limits
Each seat’s allowance is the default ceiling. If admins turn on usage credits so members can keep going, they set spend limits at the organization, group or individual member level in the claude.ai admin settings (Organization settings → Usage). Members who hit a limit see a message naming which limit they hit. See Anthropic’s Manage costs page for the full list.
Headless runs: --max-budget-usd
For scripted or CI runs in print mode (claude -p), Claude Code has a real per-run dollar cap:
claude -p --max-budget-usd 5.00 "Fix the failing tests in src/billing" claude -p --max-budget-usd 5.00 --max-turns 30 "..." # also cap the number of agentic turns
Once the run’s estimated spend reaches the amount, Claude Code stops it. Subagent spend counts toward the cap, and once the cap is reached Claude Code won’t start new subagents and stops background ones (that part needs v2.1.217 or later). Things to know, from the CLI reference:
- It is print mode only. There is no equivalent flag for an interactive session.
- It is checked against Claude Code’s own cost estimate, which can differ from your bill, and the final response can push spend past the cap. Leave headroom.
- When you resume a conversation with
--continueor--resume, the cost of earlier runs doesn’t count toward the new cap.
For a full CI setup across Claude Code, Codex and Cursor (job timeouts, dedicated keys, GitHub Actions), see setting a hard budget for AI coding agents in CI. The Agent SDK has the same caps as maxBudgetUsd / max_budget_usd and maxTurns / max_turns.
The gap: interactive sessions and daily totals
Put together, the native controls give you a monthly ceiling (Console, usage credits, admin limits) and a per-run cap for claude -p. What is missing is a cap on the long interactive session you start in the morning and leave working, and a daily cap across all your sessions (and other agents). You can see the session’s estimated cost in /usage or in a custom status line, but nothing stops the session when it passes a number.
A prompt like “stop if this costs more than $10” is not a cap; the model can’t see what it costs. The place to enforce it is a PreToolUse hook. Claude Code runs the hook before every tool call, and the hook can deny the call (permissionDecision: "deny") or end the session ({"continue": false}). The hook needs to read the session’s transcript, price the tokens, and compare against your cap.
Per-session and daily caps with LoopGuard
LoopGuard is an open-source (MIT) CLI that installs exactly that hook. It reads Claude Code’s own transcript for the current session, including the subagents/ transcripts next to it, prices it at API list prices, and checks it on every tool call. No proxy and no API key, so it works the same on a subscription.
npm i -g loopguard-cli # puts `loopguard` on your PATH loopguard init --agent claude # adds PreToolUse + Stop hooks to ~/.claude/settings.json (backed up first) loopguard config set sessionCapUsd 10 # per session (default 25) loopguard config set dailyCapUsd 40 # per local day, across all guarded agents (default 100) loopguard status # today's spend vs caps, recent trips
Restart running Claude Code sessions so they load the hook. What happens from then on:
- At 80% of either cap (
warnAtPct), Claude Code shows a warning such asLoopGuard: session $8.10/$10.00, today $31.20/$40.00. - At the cap, the next tool call is denied and the session is ended with a reason:
LoopGuard: session spend $10.04 reached cap $10.00. Stopping. Raise with `loopguard config set sessionCapUsd <n>` or `loopguard pause 15`. - The same hook catches loops: the same tool call 5 times within 10 minutes with no change to the files or its output in between is denied, and a $10 jump in 5 minutes halts the session (
loop.maxRepeats,loop.spiralUsd). loopguard pause 15lifts enforcement for 15 minutes when you really do want to keep going.loopguard config set sessionCapUsd 0turns that cap off.
For headless runs, use both: --max-budget-usd for the run, and LoopGuard’s daily cap so twenty separate $5 runs can’t add up to $100 without you noticing.
Limits worth knowing
- Costs are estimates at API list prices. On Pro or Max you aren’t billed per token, but the dollar figure is still a consistent measure of how fast a session is using your limits. Override prices in
~/.loopguard/pricing.jsonif you pay different rates. - The check runs when Claude calls a tool or finishes a turn, so a single long response isn’t cut off midway. Spend can pass the cap by up to one turn.
- Ending the session relies on Claude Code honoring
continue: false, which recent versions do (verified on 2.1.302). Older builds, for example 2.1.197, deny the tool call but keep the session open. Runclaude updateif yours is old. - Hooks only see Claude Code’s own requests. If the agent writes a script that calls the Anthropic API with your key, keep a Console spend limit as the backstop.
- LoopGuard fails open: if it has an internal error, Claude Code keeps working and the error goes to
~/.loopguard/errors.log.loopguard uninstall --agent claude --restoreputs your original settings file back byte-for-byte.
Related
- How to stop runaway Claude Code, Codex and Cursor agent loops
- How to track AI coding agent token costs per session
- How to limit Cursor agent usage costs
- How to cap OpenAI Codex CLI spend
- Claude Code usage limit reached: why it happens and how to monitor it
- How to set a hard budget for AI coding agents in CI
- Claude Code stuck in a loop: how to break it and stop it repeating the same command
- Codex usage limit reached: 5-hour and weekly limits explained
- Cursor agent stuck in a loop: how to stop it, roll back, and keep it from repeating
- Why Claude Code uses so many tokens, and how to use fewer
- How to set a budget limit for Aider
- GitHub Copilot agent mode stuck in a loop: how to stop it and keep it from repeating
- Cline stuck in a loop: how to stop it, roll back, and cap what it spends
- Gemini CLI usage limits: daily quotas, the June 2026 change, and keeping costs in check
- Codex stuck in a loop: how to stop it, undo it, and keep it from repeating