Skip to content

feat(claude): read limits with Claude Code's sign-in when the browser route has none - #18

Merged
DLANSAMA merged 1 commit into
mainfrom
claude/claude-oauth-fallback
Nov 8, 2026
Merged

DLANSAMA merged 1 commit into
mainfrom
claude/claude-oauth-fallback

Conversation

@DLANSAMA

@DLANSAMA DLANSAMA commented Nov 8, 2026

Copy link
Copy Markdown
Owner

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/usage with the access token from ~/.claude/.credentials.json and anthropic-beta: oauth-2025-04-20. The response uses the same window objects as claude.ai's /usage, so parse_claude_usage reads it unchanged (Weekly, per-model rows, usage split).
  • The token is never renewed, the refresh token is never accessed, the file is never written. A token within 60 s of expiry is not sent.
  • Token expired or rejected (401/403) with no browser cookie at all → unauthorized, "open Claude Code to renew it". With any other cookie-path state (wallet locked, rejected session, …) that state is kept.
  • Its own 429 backoff is a separate oauthRateLimitedUntil stamp; the cookie path's stamps survive a replacement.
  • http_json takes optional headers and refuses redirects whenever Authorization is present.
  • Nothing from the request (token, headers, body, exception text) reaches a message: fixed strings plus the HTTP code.
  • No new status string, no UI change.

Checked

  • Real response captured once with a throwaway script; the fixture (tests/fixtures/claude_oauth_usage.json) keeps its shape with invented values.
  • make check and pytest tests/ green (998 passed, 31 new in tests/test_claude_oauth.py).
  • Live: with no browser profiles the backend returned source: claude-oauth with 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.

… 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.
@DLANSAMA
DLANSAMA marked this pull request as ready for review November 8, 2026 23:17
@DLANSAMA
DLANSAMA merged commit c378146 into main Nov 8, 2026
1 check passed
@DLANSAMA
DLANSAMA deleted the claude/claude-oauth-fallback branch November 8, 2026 23:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant