Add usage limits section to settings for Codex and Claude Code#281
Merged
Merged
Conversation
Show live Codex and Claude Code subscription usage (5h session + weekly windows, plan label, reset times) in a unified Settings section. The host daemon reads each provider's own credentials (codex ~/.codex/auth.json; claude macOS Keychain / ~/.claude/.credentials.json) and queries their usage endpoints (backend-api/wham/usage, api/oauth/usage), normalizing both into one shape. Tokens are used as-is and never refreshed; unauthenticated/expired states are surfaced instead. Usage is exposed as a host-daemon online-RPC command (provider.usage) behind a server route (GET /api/v1/system/usage-limits) so the browser fetches it through the server. That works over non-loopback origins (e.g. Tailscale) where the daemon's loopback-only local API is unreachable. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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
Adds a Usage limits section to Settings showing live Codex and Claude Code subscription usage — plan label, a 5h "Current session" window and a "Weekly limit" window per provider, each with a % bar and reset time — in one consistent style.
How
apps/host-daemon/src/provider-usage.ts): Codex from~/.codex/auth.json→chatgpt.com/backend-api/wham/usage(reusing the existing ChatGPT token + Cloudflare-cookie handling); Claude from the macOS Keychain (Claude Code-credentials, fallback~/.claude/.credentials.json) →api.anthropic.com/api/oauth/usage. Both normalized into oneProviderUsageResponseshape.unauthenticated/expiredstates instead of errors (matches how codexbar treats CLI-owned creds).provider.usageis exposed viaGET /api/v1/system/usage-limits(resolves the connected primary host +callHostRetryableOnlineRpc). The browser only talks to the server, so it works over non-loopback origins (e.g. Tailscale) where the daemon's local API is unreachable. BumpedHOST_DAEMON_PROTOCOL_VERSION41→42.Graceful states
Each provider resolves independently. Not signed in → "Run
codex/claudeto sign in"; token expired → "session expired, run … then refresh"; no host connected → "couldn't load usage"; network/parse error → per-provider message. A brand-new user sees the section with sign-in prompts, no errors.Tests
typecheck+testgreen across host-daemon-contract, host-daemon, server-contract, server, app; lint + prettier clean.🤖 Generated with Claude Code