Skip to content

Commit 59e3fdc

Browse files
unhappychoiceclaude
andcommitted
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

File tree

‎src/fetcher/claude/mod.rs‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,26 @@
22
//!
33
//! - [`code_usage::ClaudeCodeUsage`] aggregates the local JSONL files Claude Code writes for
44
//! every session, with zero configuration and no network.
5+
//! - [`subscription::ClaudeSubscription`] reads the OAuth token Claude Code stores in
6+
//! `~/.claude/.credentials.json` and reports Max-plan utilisation against an undocumented
7+
//! `api.anthropic.com` endpoint.
58
//!
6-
//! `Safety::Safe` — local-only reads under `$HOME/.claude/`.
9+
//! Both are `Safety::Safe` — `code_usage` is local-only, `subscription` only ever talks to the
10+
//! hardcoded `api.anthropic.com` host (same model as the `github_*` / `lastfm_*` families).
711
812
mod code_usage;
913
mod common;
14+
mod subscription;
1015

1116
use std::sync::Arc;
1217

1318
use crate::fetcher::Fetcher;
1419

1520
pub fn fetchers() -> Vec<Arc<dyn Fetcher>> {
16-
vec![Arc::new(code_usage::ClaudeCodeUsage)]
21+
vec![
22+
Arc::new(code_usage::ClaudeCodeUsage),
23+
Arc::new(subscription::ClaudeSubscription),
24+
]
1725
}
1826

1927
#[cfg(test)]
@@ -30,5 +38,6 @@ mod tests {
3038
);
3139
}
3240
assert!(names.contains(&"claude_code_usage".to_string()));
41+
assert!(names.contains(&"claude_subscription".to_string()));
3342
}
3443
}

0 commit comments

Comments
 (0)