Repository navigation
Commit 59e3fdc
feat(fetcher): add claude_subscription — Max-plan utilisation via oauth/usage
Queries the **undocumented** `GET https://api.anthropic.com/api/oauth/usage`
endpoint with the OAuth token Claude Code stores in
`~/.claude/.credentials.json` (`.claudeAiOauth.accessToken`), plus the
`anthropic-beta: oauth-2025-04-20` header. Surfaces every non-null usage
window the response carries — `five_hour`, `seven_day`, `seven_day_sonnet`,
`seven_day_opus`, `seven_day_omelette` (= the "Claude Design" pool in the
claude.ai UI), and any internal codenames the server returns.
Generic walker: deserialize as `serde_json::Value`, iterate keys, skip
`extra_usage` (different schema). Known keys map to the claude.ai UI label
(`seven_day_omelette` → "Claude Design"); unknown keys fall through a
`humanize_key` helper so a future window auto-surfaces with a readable label.
Utilisation arrives on a 0..100 percent scale (`7.0` = 7%) — normalise to 0..1
internally and clamp at 1.5 for over-quota so a blown window still renders
distinctly.
8 shapes:
- Ratio (default) — single window selected by `window` option, label includes
the relative reset ETA (`5h · resets 2h`)
- Text — one-line summary across every present window
- TextBlock / MarkdownTextBlock / Entries — per-window rows
- Bars — value=basis points (so chart_bar ranks correctly),
value_label=`"7%"`
- Badge — `5h 7%` plus a tone (Ok < 60% / Warn < 85% / Error ≥ 85%)
- Timeline — one event per reset, sorted chronologically
`window` option accepts friendly aliases (`5h` → `five_hour`, `7d_sonnet`,
`claude_design` → `seven_day_omelette`, …) plus any raw response key.
Refresh interval 15 minutes. `Safety::Safe` — host fixed, token never leaves
`api.anthropic.com`.
Undocumented endpoint: every failure path short-circuits to `FetchError` so
the splash renders a placeholder rather than panicking if Anthropic moves the
endpoint or shifts the response shape.
Catalog: #64 AI / LLM — subscription seat / rate-limit headroom.
Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>1 parent 9a0111d commit 59e3fdc
2 files changed
Lines changed: 892 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
5 | 8 | | |
6 | | - | |
| 9 | + | |
| 10 | + | |
7 | 11 | | |
8 | 12 | | |
9 | 13 | | |
| 14 | + | |
10 | 15 | | |
11 | 16 | | |
12 | 17 | | |
13 | 18 | | |
14 | 19 | | |
15 | 20 | | |
16 | | - | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
17 | 25 | | |
18 | 26 | | |
19 | 27 | | |
| |||
30 | 38 | | |
31 | 39 | | |
32 | 40 | | |
| 41 | + | |
33 | 42 | | |
34 | 43 | | |
0 commit comments