Repository navigation
feat(claude): read limits with Claude Code's sign-in when the browser route has none - #18
Merged
Merged
Conversation
… route has none Second route after the cookies and before the statusLine capture. Uses the access token Claude Code keeps in ~/.claude/.credentials.json; never renews it, never reads the refresh token, never writes the file. http_json refuses redirects when it carries an Authorization header.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
The Claude tab can now read its limits with Claude Code's own sign-in when the browser route has nothing (no claude.ai cookie, locked KWallet, rejected session, claude.ai rate-limiting).
Order: cookies (unchanged, still first) → Claude Code sign-in → statusLine capture (still last).
How
GET https://api.anthropic.com/api/oauth/usagewith the access token from~/.claude/.credentials.jsonandanthropic-beta: oauth-2025-04-20. The response uses the same window objects as claude.ai's/usage, soparse_claude_usagereads it unchanged (Weekly, per-model rows, usage split).unauthorized, "open Claude Code to renew it". With any other cookie-path state (wallet locked, rejected session, …) that state is kept.oauthRateLimitedUntilstamp; the cookie path's stamps survive a replacement.http_jsontakes optional headers and refuses redirects wheneverAuthorizationis present.Checked
tests/fixtures/claude_oauth_usage.json) keeps its shape with invented values.make checkandpytest tests/green (998 passed, 31 new intests/test_claude_oauth.py).source: claude-oauthwith the same Weekly and per-model percentages as the cookie path; with browser cookies present the cookie path is unchanged; with no sign-in file nothing changes.Limits
Claude Code's access token lapses about eight hours after Claude Code last ran, so this route covers a machine only while Claude Code is in regular use. Documented in the README.