Skip to content

fix(usage): handle accounts without a 5-hour session limit - #38

Open
codingogre wants to merge 1 commit into
eddmann:mainfrom
codingogre:fix/optional-five-hour-limit
Open

codingogre wants to merge 1 commit into
eddmann:mainfrom
codingogre:fix/optional-five-hour-limit

Conversation

@codingogre

Copy link
Copy Markdown

Problem

For accounts with no 5-hour session limit, GET /api/organizations/{id}/usage now returns "five_hour": null. UsageAPIResponse.fiveHour was non-optional, so decoding failed on every refresh. The popover showed "Failed to parse server response" above stale numbers from the last successful fetch.

I saw this on a Max account that was actively using Claude Code: five_hour stayed null, and the new limits array listed only weekly limits. Trimmed response:

{
  "five_hour": null,
  "seven_day": { "utilization": 4.0, "resets_at": "2026-11-05T01:00:00.343133+00:00", ... },
  "seven_day_sonnet": null,
  "limits": [
    { "kind": "weekly_all", "percent": 4, "resets_at": "2026-11-05T01:00:00.343133+00:00", ... },
    { "kind": "weekly_scoped", "percent": 0, "resets_at": "2026-11-05T01:00:00+00:00",
      "scope": { "model": { "display_name": "Fable" } }, ... }
  ]
}

The same response also contains a resets_at without fractional seconds, which the old .withFractionalSeconds-only parser would reject.

Changes

  • UsageAPIResponse.fiveHour and UsageData.sessionUsage are optional. The 5-hour card is hidden when there is no 5-hour limit.
  • New UsageData.primaryUsage (session, falling back to weekly) and primaryLimitName. The menu bar icon, status colour and threshold notifications use these, so accounts without a 5-hour limit still get a working meter and alerts. Notification text names the limit ("…of your weekly limit").
  • Dual Bar icon draws a single weekly bar when there is no session limit, rather than weekly twice, and its VoiceOver label says "Weekly: N percent". hasSessionLimit is part of the icon cache key.
  • NotificationState records which limit it tracks (tracked_limit; existing saved state decodes as the 5-hour session). When the limit changes, the warning/critical flags and last percentage reset. This stops a stale session flag from suppressing a weekly warning and stops a false "reset" notification.
  • Reset timestamps parse with or without fractional seconds.
  • usage.json omits session_usage when absent. The README now documents this, and the statusline example falls back to weekly_usage.
  • CHANGELOG entry under Unreleased.

Accounts that still have a 5-hour limit see no change.

Testing

  • New tests: decoding a fixture trimmed from the live response (five_hour: null), timestamps without fractional seconds, weekly-limit warning text, and the two notification-state switch cases.
  • xcodebuild test: 56 passed. The 8 MenuBarIconSnapshotTests fail on my machine (macOS 26 / Xcode 27.2) on unmodified main too, so it's a rendering-environment difference, not this change.
  • Ran the patched decoder against a live account: no error, 5-hour card hidden, weekly 5%.
  • Rendered the Dual Bar icon in both modes and checked it visually.

Possible follow-up (not in this PR)

The reset notification title and the "Notify on Session Reset" setting still say "Session". They're accurate for accounts with a 5-hour limit and slightly off for weekly-only accounts.

🤖 Generated with Claude Code

claude.ai's usage endpoint now returns `"five_hour": null` for accounts
that have no 5-hour session limit. `five_hour` was decoded as
non-optional, so every refresh failed with "Failed to parse server
response" and the popover kept showing stale numbers.

- Make the 5-hour limit optional; hide its popover card when absent
- Menu bar icon and notifications follow the weekly limit when there is
  no 5-hour limit, and notification text names the limit
- Dual Bar icon shows a single weekly bar instead of weekly twice
- Reset notification flags when the tracked limit changes, so a stale
  session flag can't suppress a weekly warning or trigger a false reset
- Accept reset timestamps without fractional seconds
- Omit `session_usage` from usage.json when absent; update README

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
smb0209 pushed a commit to smb0209/ClaudeMeter that referenced this pull request Nov 6, 2026
claude.ai's usage endpoint now returns `"five_hour": null` for accounts
that have no 5-hour session limit. `five_hour` was decoded as
non-optional, so every refresh failed with "Failed to parse server
response" and the popover kept showing stale numbers.

- Make the 5-hour limit optional; hide its popover card when absent
- Menu bar icon and notifications follow the weekly limit when there is
  no 5-hour limit, and notification text names the limit
- Dual Bar icon shows a single weekly bar instead of weekly twice
- Reset notification flags when the tracked limit changes, so a stale
  session flag can't suppress a weekly warning or trigger a false reset
- Accept reset timestamps without fractional seconds
- Omit `session_usage` from usage.json when absent; update README

Cherry-picked from eddmann#38.

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant