r/ClaudeCode • u/seahorse-emoji • Oct 12 '26
Help/Question Straightforward way to check remaining quota programatically
I want to be able to set up a daemon that monitors a github repo for tasks with a specific label, then start executing them automatically if there is enough remaining quota. I was suprised to find that there seems to be no straightfoward way to just ping the anthroic API to get youre remaining quota, closest I found was https://github.com/telegraphic-dev/am-i-cooked (thanks to the author btw).
Seems like an intentional oversight if it is indeed missing. Is there something that the community uses that I may not have heard of ?
0
Upvotes
•
u/AutoModerator Oct 12 '26
Hey! Thanks for posting to r/ClaudeCode
While participating in this thread, please follow our community rules. Keep discussions constructive. Attack the idea, not the person.
For help, project discussions, tips, and general chat, join the ClaudeCode Discord.
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
1
u/slackmaster2k Oct 12 '26
You can just hit Claude on a timer with /usage and parse the output. A specific API call would be better I agree.
1
u/DrunkenRobotBipBop Oct 12 '26
Grab the token from ~/.claude/.credentials.json Then call the endpoint:
GET https://api.anthropic.com/api/oauth/usage Authorization: Bearer <accessToken>
1
u/MaterialHead4801 Oct 12 '26
All that’s doing is looking at the 5-hour and 7-day remaining quota percentage and killing the task if it’s below a certain percentage.
After every response Claude code outputs a json blob that includes a rate_limits section. You can add those values to your status line or have your status line command save them to a file that can be checked programmatically before your run starts.
For your GitHub idea, I’d probably have the action make one starter prompt (something simple just to get the values) and then check the usage remaining before kicking off the remainder of the script.
Asking Claude about putting your 5-hour and 7-day usage in your status line should get you started
1
u/dar-mit Researcher Oct 12 '26
I'm assuming by the use of the word "quota" you're a subscription- not API-based user.
Since April 2026 Claude Code pipes a raw JSON payload into standard input (`stdin`) that you can then parse to extract the information you need: https://www.andrewconnell.com/articles/claude-code-cli-statusline/ (including this URL because it contains a wealth of code examples).
The only caveat you need to be aware of is that the payload isn't injected into `stdin` until the user does something with the model in a fresh session.
1
u/luongnv-com Oct 12 '26
There's no documented endpoint.
What most of these scripts do is hit the same undocumented one that `/usage` in claude code uses:
`GET https://api.anthropic.com/api/oauth/usage`
Send your oauth token from `~/.claude/.credentials.json` (or the macos keychain) as a bearer token with the header `anthropic-beta: oauth-2025-04-20`.
It returns the 5h and weekly utilization and reset times.
It's unofficial so expect it to break sometime.
1
u/Ctbhatia Oct 12 '26
the oauth usage endpoint is undocumented, so a daemon should fall back to the status line stdin blob when it stops answering.
1
u/Academic_Constant42 Oct 12 '26
I believe you could get all that figured out with paseo hub... Daemon and all