Skip to content

feat(tray): show Claude Code and Codex usage limits left - #9

Merged
itsmbaqer merged 1 commit into
mainfrom
feat/usage-limits
Sep 24, 2026
Merged

itsmbaqer merged 1 commit into
mainfrom
feat/usage-limits

Conversation

@itsmbaqer

Copy link
Copy Markdown
Owner

What

The tray now shows how much of the Claude Code and Codex usage limits is left:

  • Menu: one section per provider (● Claude usage, ● Codex usage), each with a 5-hour row and a weekly row, e.g. 5h · 45% left · resets 1h 21m. A header shows ⚠ when that provider can't be read or has under 20% left.
  • Beside the icon: the 5-hour window left for each provider, e.g. C 46% · X 100%. This follows the tray label setting and is hidden when it is Off.

How

  • New module src-tauri/src/usage.rs:
    • Claude Code: the OAuth token comes from the Keychain item Claude Code-credentials on macOS, or ~/.claude/.credentials.json elsewhere, and is sent to GET api.anthropic.com/api/oauth/usage.
    • Codex: the token comes from ~/.codex/auth.json and is sent to GET chatgpt.com/backend-api/wham/usage.
  • Requests go through the system curl, so there are no new crates and no TLS stack. Headers are passed on stdin, so tokens don't appear in ps.
  • A background thread polls every 5 minutes and wakes the tick loop when it has new numbers.
  • Failures show a reason in the menu instead of numbers: sign in again, offline, HTTP n. A 429 keeps the last reading and backs off for 15 minutes.
  • Expired Claude tokens are never sent, because the endpoint answers them with a 429 and an hour-long Retry-After instead of a 401. The row says "run claude to refresh" instead.
  • Headers are text rows with a glyph, not icon items, so they line up with the session rows. On macOS an icon item sits in its own, wider column.

Caveats

  • Both endpoints are private and undocumented, and can change without notice.
  • On macOS, the first Keychain read may prompt; choose Always Allow.
  • Cursor and Antigravity are not included: they have no 5-hour or weekly windows.

Testing

  • cargo test --workspace passes (33 tests; new: usage::tests::parses_both, tray::tests::usage_text).
  • cargo clippy --workspace --all-targets -- -D warnings and cargo fmt --check are clean.
  • Both endpoints were called with real credentials and returned 200 in the parsed shape.
  • Checked in pnpm tauri dev: separate sections, aligned headers, live countdowns.

Includes a minor changeset.

🤖 Generated with Claude Code

Adds a section per provider to the tray menu with the 5-hour and weekly
windows left and reset countdowns, plus "C 46% · X 100%" beside the icon.
Reads each tool's stored login and asks its usage endpoint every 5 minutes
through the system curl (token on stdin), with a 15-minute back-off on 429.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@itsmbaqer
itsmbaqer merged commit 2a285bf into main Sep 24, 2026
3 checks passed
@github-actions github-actions Bot mentioned this pull request Sep 24, 2026
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