Repository navigation
feat(quota): show Claude plan limits in the expanded panel - #338
Conversation
Upstream PR wxtsky#338 (open) adds live Claude rate-limit quota display to the island: 5h / weekly / weekly-per-model windows with progress bars, reset countdowns, and a collapsed chip showing the pressing window. Tracked as T-089 (medium priority, M effort, gate: merge). Also notes PR wxtsky#337 (configurable animation speed, watch alongside T-084). Co-Authored-By: Claude Sonnet 4.6 <[email protected]> Claude-Session: https://claude.ai/code/session_01AEPtxTR2PTGXUhaXt1VEPj
Opt-in setting (off by default) that reads the Claude Code OAuth login and fetches Anthropic's subscription windows — the numbers /usage shows — from GET /api/oauth/usage (beta oauth-2025-04-20). The response's limits[] (session / weekly_all / weekly_scoped) is parsed with a fallback to the legacy five_hour / seven_day shape. The login is read through /usr/bin/security (the tool Claude Code stores it with, so no Keychain prompt), falling back to ~/.claude/.credentials.json. The token is only ever read, never refreshed: an expired token surfaces as "run Claude Code once". The expanded session list gets a footer line with every window: mini bar, percent, reset countdown, coloured by severity. Refresh policy is a pure struct (ClaudeQuotaScheduler): fetch on expand when the snapshot is over a minute old; while the footer is on screen, Stop hooks from local Claude sessions drive refreshes (15s coalesce, at most one a minute, trailing fetch), with exponential backoff on errors and polling stopped on 401/403. Nothing is scheduled while the island is collapsed or the setting is off, and nothing runs while the machine sleeps. Landed from wxtsky#338 without the collapsed-island chip and the collapsed-bar layout rework, which will follow separately. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…isk and redirects - readKeychain read stdout to EOF before starting its timeout, so a security(1) blocked on a keychain unlock/access dialog pinned the fetch (and the monitor's in-flight flag) until the user answered. A watchdog now kills the child at the deadline (SIGTERM, then SIGKILL), which ends the read; only a normal exit with status 0 yields data. - The bearer request used URLSession.shared: the app's on-disk URL cache and cookie jar, and default redirect following. It now goes through an ephemeral session with no cache/cookies, and redirects are refused so the Authorization header can only reach api.anthropic.com. - A credential whose expiresAt is already past is not sent at all (fetch(using:) holds the network half so tests skip the utility-QoS hop). Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…d off settingsChanged clears the snapshot when the toggle goes off, but a request already in flight would write it straight back when it completed, leaving a stale snapshot to reappear on the next enable. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
3589bb5 to
d766c7d
Compare
|
Thanks @mutoe! Merged as b4bc98a, with you as the author. This is a feature we've wanted for a while, and the scheduler and parsing work is really careful. What landed: the client, parser, scheduler, monitor, settings toggle and the expanded-panel footer. With no collapsed chip, the monitor only runs while the panel is expanded; a Stop that arrives while the island is collapsed is fetched on the next expand. Two small hardening commits sit on top:
What we left out: the collapsed chip and the collapsed-bar rework, because the rework changes the bar for every notched user even with the setting off. We'd love a follow-up PR for both. What we found:
The chip is welcome in that PR too, as long as the collapsed bar with the setting off stays exactly as it is on main. |
Follow-up to wxtsky#338, which landed the expanded footer. With "Show Claude plan limits" on, a chip — window label, 9pt ring, percent, every window in the tooltip — takes the left wing's tool slot while no tool is running. A new picker chooses what it shows: Auto, 5-hour, weekly, weekly (current model), or nothing. Auto shows a weekly budget by default. A pressing weekly (ahead of pace, or past 80%) comes first, the one further ahead of pace if both are; else one in surplus late in the week (at least half elapsed, 25+ points behind pace), with its ring in green, since that budget expires unused; else the tighter one. The 5-hour window takes over only when it is genuinely blocking: past 50% used and more than 10 points ahead of pace. While the chip is visible the monitor also refreshes with the island collapsed (Stop hooks as before, plus the 10-minute idle tick to catch resets); with the chip off the footer is the only surface and a collapsed island schedules nothing, as on main. With the setting off nothing is resolved, so the collapsed bar is exactly as on main. The collapsed-bar layout rework is not part of this change. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Scouted wxtsky/CodeIsland v1.0.34 (Sep 23) and v1.0.35 (Sep 24). Nine actionable changes confirmed in our fork: - T-089: quota display gate cleared (PR wxtsky#338 merged) - T-090: NSAppleScript → osascript subprocess (thread-safety, high) - T-091: QuestionBarView focus stealing fix (high) - T-092: slash command detection in UserPromptSubmit (high) - T-093: drain agent scoping by agent_id (high) - T-094: configurable animation speed 0.5×–2.0× (low) - T-095: four markdown rendering bugs in ChatMessageTextFormatter (medium) - T-096: question answer state keying fix (high) - T-097: compact bar/tooltip/completion card display fixes (low) - T-098: model tracking from PostToolUse events (medium) Co-Authored-By: Claude Sonnet 4.6 <[email protected]> Claude-Session: https://claude.ai/code/session_01GUiVpZVkzE6q8zXCWdgX97
Follow-up to wxtsky#338, which landed the expanded footer. With "Show Claude plan limits" on, a chip — window label, 9pt ring, percent, every window in the tooltip — takes the left wing's tool slot while no tool is running. A new picker chooses what it shows: Auto, 5-hour, weekly, weekly (current model), or nothing. Auto shows a weekly budget by default. A pressing weekly (ahead of pace, or past 80%) comes first, the one further ahead of pace if both are; else one in surplus late in the week (at least half elapsed, 25+ points behind pace), with its ring in green, since that budget expires unused; else the tighter one. The 5-hour window takes over only when it is genuinely blocking: past 50% used and more than 10 points ahead of pace. While the chip is visible the monitor also refreshes with the island collapsed (Stop hooks as before, plus the 10-minute idle tick to catch resets); with the chip off the footer is the only surface and a collapsed island schedules nothing, as on main. With the setting off nothing is resolved, so the collapsed bar is exactly as on main. The collapsed-bar layout rework is not part of this change. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Problem
Claude Code's
/usageshows three rate-limit windows — 5-hour, weekly (all models), weekly (current model) — and they are the thing that actually stops a long session. Nothing in the island tells you how close you are until the CLI refuses to continue. The existing token-usage stats are a different question (how much did I spend), not this one (how much is left before I'm cut off).Change
An opt-in Show Claude plan limits setting, off by default because it reads the Claude Code login.
Data. The Claude Code OAuth token from Keychain (
Claude Code-credentials), with~/.claude/.credentials.jsonas fallback, sent toGET /api/oauth/usagewith theoauth-2025-04-20beta header — the same call/usagemakes. The response'slimits[](session/weekly_all/weekly_scopedwithpercent,resets_at,severity, the scoped model's display name) is parsed with a fallback to the legacyfive_hour/seven_dayshape. The token is only ever read; refreshing it would invalidate the one Claude Code holds, so an expired token surfaces as "run Claude Code once".The Keychain item is read by running
security find-generic-password -s "Claude Code-credentials" -wrather thanSecItemCopyMatching. Claude Code writes the item throughsecurity, so that binary is on the item's ACL and the read is silent; an in-process read from an ad-hoc-signed build prompts on every rebuild because the designated requirement changes. (The ccusage Raycast extension does the same thing.)Expanded panel. A footer line with every window: mini bar, percent, reset countdown (
↻1h56m/↻6h06m), coloured by severity, refreshed each minute.Collapsed island. A chip in the left wing next to the mascot — window label, 9pt ring, percent (
Fable ◑58%). If the tool-name display is on and a tool is running, the tool name has priority; the chip stays laid out as an invisible placeholder so the bar doesn't change width when they swap. The chip mode is a picker: off / auto / 5h / weekly / weekly (current model).Auto mode. A window is pressing when its used share exceeds the elapsed share of the window (ahead of pace) or it is at ≥80%. The 5-hour window takes the chip while pressing; otherwise a weekly window — if either weekly is pressing, the one further ahead of pace, else the one with more used. No weekly reported → 5-hour.
Refresh policy. Event-driven on
Stophooks from local Claude sessions: 15s coalesce, at most one fetch a minute, a trailing fetch for stops that landed during the throttle. A 10-minute tick while the setting is on, a fetch on expand if the snapshot is over a minute old, exponential backoff (60s → 15m) on errors, polling stops entirely on 401/403, and nothing runs while the mascot gate says the machine is asleep. The policy is a pure struct (ClaudeQuotaScheduler) so it's tested without timers.Collapsed-bar layout fix
Putting a ~67pt chip in the left wing exposed a pre-existing layout flaw on notched screens. The collapsed bar was a flexible row centred on the notch with a
Spacer(minLength: notchW)between the wings. That guarantees a gap at least as wide as the notch, not that the gap lines up with the cutout — whichever wing is wider pushes the gap sideways and its tail ends up under the physical notch. Screenshots show those pixels; the display doesn't. A long tool name already did this; the chip made it obvious.Now each wing reports its ideal content width (rigid via
fixedSize, the tool name still truncating at its 120pt cap), the row between them is exactly the notch, and the whole bar is offset by half the wing difference so the gap sits on the cutout. The left wing keeps the classic reserve or its content; the right wing is trimmed to its content (count plus badges) so the bar stays clear of menu-bar icons. Width changes ease in and only shrink back after 5s, so a tool name that comes and goes doesn't make the bar breathe. Non-notch screens keep the flexible row and just add the measured overflow. A geometry test pins the shift (it caught the sign inverted on the first attempt).Tests
ClaudeQuotaTests: parse of a real response, legacy fallback, garbage rejection, elapsed/pace maths, auto-mode rules (weekly default, 5h takeover at pace/80%, weekly ranked by pace), fixed modes, countdown formats, severity levels, credential parse, request headers, HTTP status mapping.ClaudeQuotaSchedulerTests: coalescing, trailing fetch, remembered stops, backoff cap, rejected token, expand staleness.ClaudeQuotaMonitorTests: expand fetch, disabled never fetches, burst coalesces, unauthorized stops polling — with an injectedUserDefaultssuite so no test touches the real setting (a monitor on standard defaults would make every other test'sAppStatedo real credential reads).NotchPanelViewTests: wing slot and notch-shift geometry.Full suite green locally on macOS 26.4 (arm64): 960 tests, 2 skipped, 0 failures. Verified on a 14" notched display by measuring the rendered bar against
NSScreen.auxiliaryTopLeftArea: chip right edge 6pt clear of the cutout, bar extent identical across chip ↔ tool-name swaps, no Keychain prompt on a fresh ad-hoc build.🤖 Generated with Claude Code