DEV Community

Anup Karanjkar
Anup Karanjkar

Posted on Originally published at wowhow.cloud

Claude Code Spend Limit: Hard Caps That Stop a Runaway Bill

A coding agent stuck in a retry loop on Claude Opus 5.5 can spend about $115 an hour if every turn re-sends a 150K-token context uncached, and a warning email arrives after that money is gone. The fix is a hard cap, meaning a limit that rejects requests instead of notifying you. Simon Willison made the same argument on 3 October 2026: soft caps will not cut it, and most people prefer errors to a surprise $10,000 bill. This post maps which providers actually offer a hard cap today, which only alert, a five-step cap stack for Claude Code and Codex, and a worked cost of one runaway loop at current prices.

The short answer

Hard caps exist at OpenAI, Google (Gemini API and Google Cloud), Vercel AI Gateway and, in early access, Anthropic. They are monthly, enforced with a delay, and scoped differently at every vendor. Anthropic documents the limit but not the failure behaviour. AWS spend limits are a limited release. None of them stop a single bad hour on their own, which is why the stack below puts a cheap daily check at the tool-call layer.

Soft alert versus hard cap

A soft alert sends an email at a threshold and traffic keeps flowing. A hard cap returns an error once the threshold is crossed. OpenAI's own guide draws the line plainly: spend alerts do not enforce a cap, and a hard limit makes affected requests fail. The distinction matters most for agents, because an agent running unattended produces spend at machine speed while the alert goes to a human who is asleep.

Two properties of every hard cap on the market today, and the reason the stack below has five layers:

  • Enforcement lags. OpenAI says enforcement is not instantaneous. Google says billing data can lag by about 10 minutes for Gemini project caps and that actual costs on Google Cloud can take more than 24 hours to process.

  • Caps are monthly in most places. A monthly $500 cap lets one bad night eat a large share of it before anyone looks.

Provider-by-provider table

Every cell comes from the vendor documentation or a source named in the row. Where I could not find a statement, the cell says "not documented".

Provider Hard cap available? Soft alert only? Where to set it What happens when hit

| Anthropic API (Console) | Yes, monthly organization and workspace limits. Setting them through the API is early access, per the spend limits API reference. | Workspaces also take email notifications at an amount, per the workspaces help article. | Console limits tab per workspace; org limit in billing settings; API requires contacting your Anthropic account team. | Not documented in the pages I read. |

| OpenAI API | Yes, organization and project level, via "Enforce a hard limit". | Alerts exist separately and do not stop traffic. | Organization limits page, or Project settings, Limits, per the spend limits guide. | HTTP 429 with organization_spend_limit_exceeded or project_spend_limit_exceeded. Resumes when raised or at the monthly reset. Enforcement is not instantaneous. |

| Google Gemini API | Yes, project spend caps (marked experimental), plus automatic billing-account tier caps. | Not documented for the cap itself. | AI Studio, Spend page, Monthly spend cap, per the Gemini billing docs. Not available on invoiced accounts. | Tier cap: service paused for all linked projects until the 1st of next month. Error code: not documented. Project cap can overshoot by about 10 minutes of billing lag; batch mode and agent sessions may also exceed it. |

| AWS Bedrock | AWS project spend limits are described as a limited release in Willison's post. Bedrock-specific behaviour: not documented in any official AWS page I could verify. | Not documented. | Not documented. | Willison quotes AWS: the project is paused for that month. A commenter on the Hacker News thread quotes a deletion warning after 90 days with no action. Treat as unverified. |

| Google Cloud (Spend Caps) | Yes. One project, one eligible service, monthly. Gemini API and Vertex AI (now Gemini Enterprise Agent Platform) are eligible, per the Google Cloud docs. | Regular budgets alert only. | Billing budgets, spend cap option. Needs Billing Account Administrator or Project Owner. | New usage of that service pauses for the rest of the month. In-flight requests finish and accrue charges. Lifts at the next period or manually, up to one hour to recover. You stay responsible for overage from reporting latency. |

| Vercel AI Gateway | Yes. Budgets at team, project, API key and team member scope, per the budgets docs. | Alerts: not documented in the pages I read. | Dashboard, or vercel ai-gateway budgets set. | The gateway checks the budget before each request and rejects new ones until the period resets or the limit is raised. Periods: daily, weekly, monthly or none. |

The Vercel row is the only one with a daily period documented, and that is the useful one for agents. Routing Claude Code or a Codex-style agent through a gateway with a daily budget turns the cap from "a bad month" into "a bad day".

Claude Code: the plan versus API split

Claude Code bills in one of two ways and the caps above only touch one of them. Signed in with a Claude plan, you hit plan usage limits and extra usage. Using an API key from a Console organization, you pay per token and the Console limits apply.

On 7 October 2026 Anthropic announced monthly API credits for Max and Team plans. The help center article lists $100 for Max 5x and $200 for Max 20x, with Team seats pooled and capped at $500. They cover the Messages and Message Batches APIs, the Console Playground, Managed Agents and the Agent SDK. They do not cover interactive Claude Code in the terminal, IDE, desktop or web, and they do not cover extra usage or Claude on Bedrock or Vertex. Unused credits expire at the end of each billing cycle.

The catch for scripts: claude -p and the Agent SDK are covered only when you run them with an API key from your linked Console organization, not while signed in with your plan. A headless loop launched from a cron job therefore spends credits first, then real dollars, and the Console limit is the only thing between that loop and your card.

The five-step cap stack

No single layer is enough. Each one fails in a different way, so you stack them from slowest and hardest to fastest and softest.

Step 1: provider cap on every key you hand to an agent

Create a separate workspace (Anthropic) or project (OpenAI) for agents, and give it its own key. On OpenAI, turn on "Enforce a hard limit" for that project. On Anthropic, set the workspace limit under the organization limit, since a workspace limit can only be lower than the organization's. Pick a number you could lose without discussion, not your budget.

Step 2: organization limit as the backstop

Set the organization limit at your real monthly ceiling. Anthropic evaluates both the workspace and organization limiters on every request, so the lower one binds. Because enforcement lags, set the number below your true limit. Google tells people to do exactly that for Spend Caps.

Step 3: hook-level daily cap in Claude Code

Claude Code's hooks documentation describes a PreToolUse hook that receives JSON on stdin (tool_name, tool_input, session_id and more) and can block the call two ways: exit code 2, where stderr becomes the reason shown to Claude, or exit 0 with a JSON object whose permissionDecision is "deny". Exit 0 with no JSON means the normal permission flow runs. Other non-zero exit codes are non-blocking errors and the tool call proceeds, which matters: a crashing script fails open.

A hook sees tool calls, not dollars, so this layer counts calls as a proxy for loop speed. It will not catch one enormous call. It will catch a loop.

#!/bin/bash
# .claude/hooks/daily-call-cap.sh  (chmod +x)
LIMIT=1500
FILE="$HOME/.claude/call-count-$(date +%F)"
COUNT=$(( $(cat "$FILE" 2>/dev/null || echo 0) + 1 ))
echo "$COUNT" > "$FILE"
if [ "$COUNT" -gt "$LIMIT" ]; then
  jq -n --arg r "Daily tool-call cap of $LIMIT reached" '{
    hookSpecificOutput: {
      hookEventName: "PreToolUse",
      permissionDecision: "deny",
      permissionDecisionReason: $r
    }
  }'
fi
exit 0
Enter fullscreen mode Exit fullscreen mode

Register it in .claude/settings.json under hooks, then PreToolUse, with an empty or * matcher and a command handler pointing at the script. Counting is per machine, so run it where the agent runs.

Step 4: per-PR cost tracking

A cap tells you a loop happened. Per-PR tracking tells you which task caused it. Log tokens and model per session, tag with the branch, and compare against what the same work costs in a human hour. The Agent Run Cost Simulator models a run before you start it, and the AI Model Cost Calculator compares the same token volume across models. The Agent Cost Control spreadsheet is a ready-made ledger for the per-PR numbers.

Step 5: alerts that reach a human

Alerts still matter. They are the only layer that tells you the other four fired. Send them somewhere you read within the hour, at 50 and 80 percent, and treat a hard-cap error in the logs as an incident, not noise. Codex users: the official Codex pages I could reach did not document a spend or token ceiling per session. Third-party write-ups describe a rollout-level token budget in recent Codex CLI builds, but I could not confirm the setting names, so rely on your OpenAI project cap and a wrapper script until you verify them.

Worked example: one runaway loop

Assume an agent that retries a failing test run once every 20 seconds overnight, 10 hours, 1,800 turns. Prices come from the Anthropic pricing page: Opus 5.5 at $4 input and $20 output per MTok, Sonnet 5.5 at $2 and $10, Haiku 5.5 at $0.10 and $0.50 for prompts up to 100K tokens. Each turn sends 150K tokens of context and gets 2K tokens back. Haiku is modelled at an 80K prompt to stay under its 100K tier.

Model Cost per turn, uncached 10-hour loop, uncached 10-hour loop, cache hits

| Opus 5.5 | $0.64 | $1,152 | $126 |

| Sonnet 5.5 | $0.32 | $576 | $63 |

| Haiku 5.5 (80K prompt) | $0.009 | $16.20 | not computed |

The cached column uses the published cache-hit rates of $0.20 per MTok on Opus 5.5 and $0.10 on Sonnet 5.5, and counts only the input at those rates plus normal output. Real loops mix cache writes and misses, so your number lands between the columns.

Now the cap. A $50 workspace limit trips at turn 78 on uncached Opus, about 26 minutes in. Without it, the same loop runs all night. With cache hits and a $50 cap, the loop stops around turn 710, about four hours in. This is also the argument for routing retry-heavy automation to a cheaper model. The Haiku 5.5 100K-token rule explains where that tier stops being cheap. For a tested set of hooks, settings and runbooks, see the Claude Code Production Pack.

Quick answers

Does Claude Code have a built-in dollar limit?

Not one I found documented. Plan users hit plan usage limits. API-key users rely on Console organization and workspace limits, whose failure behaviour Anthropic does not describe on the pages I read.

Do the new Max API credits cover Claude Code?

No. Anthropic's article excludes interactive Claude Code, and says claude -p and the Agent SDK count only with a Console API key.

Can a hook cap dollars?

No. A PreToolUse hook receives the tool name and input, so it can count calls or inspect commands. Dollar enforcement belongs to the provider or a gateway.

Which provider has the fastest hard stop?

Vercel AI Gateway checks the budget before each request, per its docs, and supports a daily period. Every other cap here documents some lag.

Is AWS Bedrock safe to leave uncapped?

I could not verify an official, generally available Bedrock hard cap. Hacker News commenters reported little built-in limiting, and AWS spend limits are a limited release. Add a gateway or your own proxy until that changes.

What number should I set?

Set the agent workspace at the amount you can lose without a conversation, and the organization limit below your real ceiling, because every cap here lags.

Note: Prices and limits reflect vendor documentation read on 13 October 2026 and change often. Verify in your own console before relying on any figure.

Originally published at wowhow.cloud

Top comments (0)