Skip to content

Fix Claude adapter: parse the real claude.ai usage response - #2

Merged
devudilip merged 1 commit into
mainfrom
claude/ration-quota-tracker-g3uwc6
Aug 28, 2026
Merged

devudilip merged 1 commit into
mainfrom
claude/ration-quota-tracker-g3uwc6

Conversation

@devudilip

Copy link
Copy Markdown
Owner

What happened

First live test of v0.1 showed the Claude card failing with endpoint_not_verified. A DevTools capture from a real account revealed two things:

  1. The endpoint was right all alongGET /api/organizations/<org>/usage (the first probe candidate). Validation failed because unused windows come back as explicit nulls ("seven_day_opus": null) where the schema only allowed the key to be absent. The honest-failure design worked exactly as intended — no wrong number was ever shown — but the schema was too strict.
  2. The response carries a limits[] array that is clearly the canonical list the usage page itself renders: session, weekly_all, and model-scoped weekly_scoped entries with percent used, reset timestamps, and the scoped model's display name.

The fix

  • limits[] is now the primary schema variant (org_usage_limits): each entry becomes a lane, with model-scoped weeklies labeled Weekly (<model>).
  • The top-level windows shape stays as a null-tolerant fallback variant (org_usage_windows) in case older/other accounts serve it without limits.
  • Adapter version bumped to 2. The live capture (no identifiers present in the body) is recorded as tests/fixtures/claude/usage.limits.json, plus a null-window regression case in the windows fixture.

Verification

  • npm run ci green: typecheck + 55 tests + build.
  • Fixture test asserts the live shape parses to Session (5h) 87%, Weekly (all models) 95%, Weekly (Fable) 93% — matching the capturing account's actual usage page.
  • After merge: rebuild, reload the unpacked extension, re-enable Claude — lanes should appear.

🤖 Generated with Claude Code

https://claude.ai/code/session_015gwwHsEgVxtmfRn3dEkBif


Generated by Claude Code

Verified against a live capture: the usage endpoint is the first probe
candidate after all, but validation failed because unused windows arrive
as explicit nulls (seven_day_opus: null) where the schema only allowed
absence — exactly the honest endpoint_not_verified failure by design,
just for the wrong reason.

The response also carries a limits[] array — the canonical list the
usage page itself renders, including model-scoped weekly limits — so
that is now the primary schema variant (session / weekly_all /
weekly_scoped lanes with the model display name in the label). The
top-level windows shape remains as a null-tolerant fallback variant.
Adapter version bumped to 2; the live shape is a recorded fixture.
@devudilip
devudilip merged commit 9774c10 into main Aug 28, 2026
1 check passed
@devudilip
devudilip deleted the claude/ration-quota-tracker-g3uwc6 branch August 28, 2026 20:28
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