Skip to content

feat(quota): show Claude plan limits in the expanded panel - #338

Merged
wxtsky merged 3 commits into
wxtsky:mainfrom
mutoe:feat/claude-quota
Sep 23, 2026
Merged

wxtsky merged 3 commits into
wxtsky:mainfrom
mutoe:feat/claude-quota

Conversation

@mutoe

@mutoe mutoe commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

Problem

Claude Code's /usage shows 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.json as fallback, sent to GET /api/oauth/usage with the oauth-2025-04-20 beta header — the same call /usage makes. The response's limits[] (session / weekly_all / weekly_scoped with percent, resets_at, severity, the scoped model's display name) is parsed with a fallback to the legacy five_hour / seven_day shape. 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" -w rather than SecItemCopyMatching. Claude Code writes the item through security, 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 Stop hooks 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 injected UserDefaults suite so no test touches the real setting (a monitor on standard defaults would make every other test's AppState do 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

nguyenvanduocit pushed a commit to nguyenvanduocit/CodeIsland that referenced this pull request Sep 4, 2026
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
mutoe and others added 3 commits September 23, 2026 11:28
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]>
@wxtsky wxtsky changed the title feat(quota): show Claude plan limits (5h / weekly / weekly per model) in the island feat(quota): show Claude plan limits in the expanded panel Sep 23, 2026
@wxtsky
wxtsky merged commit b4bc98a into wxtsky:main Sep 23, 2026
@wxtsky

wxtsky commented Sep 23, 2026

Copy link
Copy Markdown
Owner

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:

  • the security timeout now covers the whole run (before, it only started after readDataToEndOfFile() returned, so a keychain dialog could block the fetch forever);
  • the request uses an ephemeral session (no cache or cookies) that refuses redirects, so the token only ever goes to api.anthropic.com, and a result that arrives after the toggle is switched off is dropped.

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 alignment bug is real. .frame(maxWidth: 120) on the tool name lets the left wing grow to ~97–117pt, while the notch starts ~64–74pt in (14"). So tool names longer than ~5 characters slide under the cutout. Capping the left wing at its reserve, so the name truncates before the notch, may be enough on its own.
  • The hover area doesn't follow the bar. .offset(x: collapsedShift) sits inside .contentShape(Rectangle()).onHover, which moves what's drawn but not the hover region. With a long tool name, hovering over the mascot doesn't expand the panel. Apply the offset after onHover.
  • Non-notch screens get 4pt wider. The empty ZStack still takes an HStack spacing, so the left wing measures 45pt against a 41pt reserve, all the time; badges add more.
  • Width animations ignore the speed setting. They use fixed durations (easeOut 0.25 / easeInOut 0.3) and ignore the island animation speed setting from Add configurable island open/close speed #337.
  • The bar becomes asymmetric. Trimming the right wing makes it 23–33pt narrower and shifted 11–16pt left. If you want that, please make the case for it separately.
  • Screenshots, please: before/after on 14" and 16" notched displays, an external display, width scale 50/100/150, tool status on and off, a long MCP tool name, and hovering at both edges.

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.

@mutoe
mutoe deleted the feat/claude-quota branch September 23, 2026 19:53
mutoe added a commit to mutoe/CodeIsland that referenced this pull request Sep 25, 2026
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]>
nguyenvanduocit pushed a commit to nguyenvanduocit/CodeIsland that referenced this pull request Oct 1, 2026
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
wxtsky pushed a commit to mutoe/CodeIsland that referenced this pull request Oct 9, 2026
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]>
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.

2 participants