Skip to content

Account menu: Claude Code limits say why they are unavailable (#505) - #506

Open
MopigamesYT wants to merge 1 commit into
devfrom
fix/505-claude-limits
Open

MopigamesYT wants to merge 1 commit into
devfrom
fix/505-claude-limits

Conversation

@MopigamesYT

Copy link
Copy Markdown
Member

Closes #505

Summary

A Claude Code account that showed "Limits unavailable" now says why, in plain words, and keeps its last good numbers on screen:

  • Rate limited, try again in 38 min: what the real cc-langloys login gets (see below). Connections on the same Claude login (cc-langloys and cc-machine here) share one read and one pause, so a rate-limited login is no longer asked again every minute.
  • Sign in again (missing credentials file, 401, refresh token revoked), This login can't read usage (403), Session expired, send a message to renew it, Provider unavailable, try later (5xx), Can't reach the provider, Unexpected answer from the provider, Can't read the login files.
  • When an error follows good numbers, the numbers stay (with their own "Checked at" time) and the reason shows in the strip's header next to the account name.
  • An own-login connection whose access token has expired (or is refused with 401) is refreshed with its refresh token and saved back to its .credentials.json.

Screenshots

None: I could not drive the desktop UI here, and screenshots of the account menu show private account names and usage, so none are uploaded.

Technical details

Real cause on this machine (read-only checks, no token printed): the issue assumed cc-langloys is an own-login connection. It is not: it has no claudeLogin: own, so it reads the system login (~/.claude, a team plan, token valid for 2 h+). GET /api/oauth/usage for that token answers 429 rate_limit_error with Retry-After: 2864 (about 48 min), and stays 429 on a second try. The own-login connection (cc-perso) answers 200 with its 5h/7d windows. So it was neither an expired token nor a missing file. Why that login is rate limited I can't tell: 1loop polled it often (menu every minute, after each turn, phone, and once per connection), but the same token is also used by other Claude Code processes.

What changed

  • internal/agent/claude_limits_errors.go (new): limitsHTTPError (status + Retry-After, seconds or date), LimitsNote(err) (error → plain words), LimitsAfterError(last, err) (last good numbers + reason), a per-login-folder shared read (30 s) and pause (the server's Retry-After, between 1 min and 6 h), and the OAuth refresh.
  • internal/agent/account_limits.go: ConnectionLimits goes through the shared read for Claude Code; the usage request carries Retry-After; refresh only after a 401 for own logins; the old "Claude session expired" note is gone.
  • Callers: internal/ui/account_limits.go (desktop menu), internal/ui/phone_server.go and internal/server/mobile_connections.go (phone/headless /api/limits) use LimitsNote/LimitsAfterError and keep the old Checked time on an error; internal/ui/account_limits_controls.go shows the reason in the strip header when numbers are present. The phone gets the same note through the existing Note field, no protocol change.
  • Refresh is deliberately limited to own-login folders. Refresh tokens change at each use; the system login is shared with the user's terminal Claude Code, so 1loop doesn't spend it (it says "Session expired, send a message to renew it", Claude Code renews it when it runs). Before spending a refresh token, the code makes sure the file can be written; it saves through a temp file and rename, keeping other fields. Nothing logs or prints tokens.

Tests (internal/agent/claude_limits_errors_test.go, httptest and fake credentials folders, no real tokens): error → message table, Retry-After parsing, last-good-numbers, own-login refresh (saved, other fields kept, no temp file left), refresh revoked (file untouched), system login never refreshed, 403/401/5xx/expired/bad JSON/missing file, 429 pause shared by two connections (one request), shared read (one request for three calls).

Verified

  • gofmt -l internal cmd empty, go build ./..., go vet on agent/server/ui, go test ./internal/agent ./internal/ui pass.
  • With the real logins on this machine, read-only and a throwaway test: cc-langloys and cc-machine → "Rate limited, try again in 38 min" with one request for both; cc-perso → 5h and 7d windows read as before.

Not verified

  • The token refresh against the real server (platform.claude.com/v1/oauth/token, Claude Code's public client ID): no login here has an expired token and I did not spend a real refresh token. It is only tested against httptest.
  • The desktop and phone screens (no UI run, no screenshot).
  • go test ./internal/server has one failure, TestProjectOnSSHMachine ("no host key waits"); it fails the same way on a clean origin/dev, unrelated to this change.
  • No local -race run (project rule).

Assisted-by: Sonnet 5.5 high

🤖 Generated with Claude Code

"Limits unavailable" hid the real reason. On the dev machine the
cc-langloys login gets HTTP 429 with Retry-After ~48 min from
/api/oauth/usage. Limits now show the reason in plain words (rate limited
with the wait, sign in again, this login can't read usage, session expired,
can't reach the provider...) beside the last good numbers.

- Connections on one Claude login share one read and one pause, so a
  rate-limited login is no longer asked again every minute.
- An own-login connection's expired token is refreshed with its refresh
  token (saved atomically, other fields kept); the system login is not,
  its refresh token is shared with the user's terminal.
- Same reasons on the phone and headless server callers.
@MopigamesYT MopigamesYT added bug Something isn't working desktop Desktop app (Linux, Windows) labels Nov 17, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working desktop Desktop app (Linux, Windows)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants