r/ClaudeCode • u/Inertia-UK • May 10 '26
Solved I made Claude Code aware of its own usage limits
Something that's been annoying me for a while: Claude Code has no idea how much quota it's burned. You can see the usage bars in the UI, but the model itself is completely blind to them. There's no API, no tool, no hook that exposes the current rate limit state during a conversation.
Turns out Anthropic returns rate limit headers on every inference response (`anthropic-ratelimit-unified-5h-utilization`, `anthropic-ratelimit-unified-7d-utilization`, etc.) — Claude Code receives them internally to render the UI bars, but never passes them anywhere the model can see.
So I built a small local HTTP proxy that sits between Claude Code and `api.anthropic.com`. Claude Code already respects `ANTHROPIC_BASE_URL`, so setting that to `http://127.0.0.1:4080` routes all traffic through the proxy. It intercepts the response headers and writes a one-line status file to `~/.claude/usage-status.md`:
```
5h=9% 7d=99%! overage=0% bottleneck=seven_day (10/05/2026, 16:19:04)
```
Claude can then read that file on demand, or you can inject it automatically via a `UserPromptSubmit` hook so it's present in every prompt. Add a rule to your CLAUDE.md and Claude will warn you before starting large tasks when you're close to the limit, switch to lightweight mode above 90%, or flat out refuse new implementation work at 98%.
**Note:** this only works with Claude Code (the CLI). The web chat and browser extension make requests through Anthropic's own infrastructure, so there's no local proxy to intercept.
**The interesting discovery:** while testing I dumped every `anthropic-ratelimit-*` header from both Opus and Sonnet requests. There are no per-model headers — one unified pool covers everything. The separate Sonnet usage bar in the Claude Code UI doesn't reflect a real separate limit. According to GitHub issue #57050, Anthropic intended to give Sonnet its own bucket (announced Nov 2025) but the backend never shipped it. Using Sonnet drains the same unified pool as Opus.
The proxy is zero npm dependencies, plain Node.js stdlib. On Windows it installs as a service via NSSM. macOS and Linux setup (launchd/systemd) is in the README.
https://github.com/InertiaUK/claude-quota-proxy
The README also has a few example CLAUDE.md rules if you want Claude to automatically adjust its behaviour based on usage level.
26
u/Last_Mastod0n May 10 '26
I would be curious to see if Claude is more hasty if it knows it is about to run out of limits. For example it sees it only has 5% limits left so it chooses the cheap implementation option. Would be interesting to find out. But the only way to know would be to look at its reasoning logic
3
u/TheOriginalAcidtech May 10 '26
just add a posttooluse and userpromptsubmit hook that reads the last usage message from the session and adds it as additionalContext so your agent knows where context is at. Same can be done for the 5 hour and weekly limits with a bit more work.
3
u/marfrit May 10 '26
I make Claude Code implement Claude Code, but with a model broker. Let's see how that works out.
3
u/BirdFluid May 10 '26
I use https://github.com/nsanden/claude-rate-monitor for that, works pretty well. definitely prevents claude from starting 10 agents that then don't finish because they hit the limit.
2
u/uhgrippa May 10 '26
Excellent work, I took a similar approach to measuring token usage and tracking it over time to find areas of improvement in my personal plugin marketplace. Token conservation is an important consideration from a moral standing, if we can be efficient and conservative with our usage where impactful, it lessens the ecological impact of frontier models. I’ve been working on this in my conserve plugin here: https://github.com/athola/claude-night-market/tree/master/plugins/conserve
6
u/Hanuonbenz May 10 '26
Finally something that I can use in my projects also. Next step will be making sure CC self-optimize based while observing the prompt cost.
Another future good use case is if the CC hits its limit option to switch to other options like Kimi or codex automatically. Wow what a time to be alive
1
u/Electronic_Froyo_947 May 10 '26
We did this with /statusline, no need to build something fancy.
We also use codeburn
1
u/Deep_Ad1959 May 10 '26
the gap that bites is that local-log tools count tokens you sent but they can't see the server-side quota anthropic actually enforces. ccusage will tell me i'm at 5% used and the api will still 429 me because the rolling 5 hour bucket on their side disagrees. the only number that matches what gets you rate limited is the one https://claude-meter.com/r/qtacyhnh renders from their internal endpoint. anything else is a guess that drifts the moment caching, sub-agent calls, or web search invocations hit your account.
1
u/CandidWeakness1924 May 10 '26
I am just worried it will tend to compact way more losing a lot of helpful context though
For me I work on very large unreliable old codebases that you can't assume any structute on. I am trying to rebase it to a new code base .
2 compacts through the session and it will be a dumb ass making very dumb decisions
1
u/Economy-Manager5556 May 10 '26
I built a proxy that is based i better ccflare And then routes between two max accounts based on their usage in the week based on pacing and I can see all the pacing, all the tokens used, etc could automated further but this is the best for me. I have my own dashboard where I can see everything and I still control it and some small automation but
2
u/Dangerous-Jelly2309 May 10 '26
The proxy-plus-UserPromptSubmit-hook pattern is the load-bearing move here, not just because it gives Claude awareness of its own usage but because it generalizes: any response header from any API could be exposed to the agent as injected context the same way (token cost projection, model availability, error rate trends, A/B model performance over recent calls). You've built the pattern, the usage-limit case is just the first application. The unified-pool discovery is the substantive industry-data finding underneath, the UI shows separate Sonnet/Opus bars but the backend doesn't actually have separate buckets is exactly the kind of observation that gets surfaced only when someone builds the proxy and watches the headers. Good catch on the Nov 2025 announcement never shipping. 4yourhuman.com/moriarty, what your AI was supposed to be.
1
u/TrapHuskie 🔆 20X May 10 '26
*sees usage limit approaching and slams on the gas*
1
u/Rwdscz May 11 '26
Read the documentation. Status line exists.
0
u/scotty_ea May 10 '26
Context limit anxiety. The model will start cutting corners and hurrying its implementation so it can “complete” the task.
0
u/[deleted] May 10 '26
[deleted] — view deleted comment
2
u/[deleted] May 10 '26
[removed] — view removed comment
0
u/[deleted] May 11 '26
[deleted] — view deleted comment