feat(quota): read Claude plan limits from the Claude Code login

Claude quota only worked when the user had signed into Anthropic through
OpenCode. Credentials are now discovered from Claude Code itself first: the
macOS Keychain entry, then the Linux/WSL credentials file (honouring
CLAUDE_CONFIG_DIR), then OpenCode auth.json, then CLAUDE_CODE_OAUTH_TOKEN.

All sources stay read-only and the OAuth token is never refreshed: Anthropic
allows one live refresh token per client_id, so refreshing here would sign the
user out of Claude Code. Credentials are re-read per request instead, and an
expired token reports that Claude Code needs a sign-in rather than a bare 401.

Usage is now read from the limits[] array, so model-scoped weekly limits work
again after Anthropic stopped populating seven_day_sonnet/seven_day_opus, and
new limit kinds no longer need a code change. Adds extra-usage spend and the
plan name, and holds the last good values through Anthropic's 429s with a
cooldown and an account-keyed cache.
This commit is contained in:
Bohdan Triapitsyn
2026-08-14 20:49:59 +03:00
parent 9761f5ff3c
commit b77a30cd88
37 changed files with 602 additions and 134 deletions
@@ -113,12 +113,16 @@ export function groupModelsByFamilyWithGetter<T>(
* For Google provider with gemini/ and antigravity/ prefixes:
* - Gemini 3.x models
* - All Claude models
* For the Claude provider: every model it reports a limit for.
*/
export function getDefaultModels(
providerId: QuotaProviderId,
availableModels: string[]
): string[] {
return availableModels.filter((model) => {
// Anthropic only reports a model here when that model has its own plan
// limit, so every one it names is worth showing by default.
if (providerId === 'claude') return true;
const lower = model.toLowerCase();
// Handle gemini/ and antigravity/ prefixes
const modelName = lower.includes('/') ? lower.split('/')[1] : lower;
+1 -2
View File
@@ -75,8 +75,7 @@ export const resolveUsageTone = (percent: number | null): 'safe' | 'warn' | 'cri
export const formatWindowLabel = (label: string): string => {
if (label === '5h') return t('quota.window.5h');
if (label === '7d') return t('quota.window.7d');
if (label === '7d-sonnet') return t('quota.window.7dSonnet');
if (label === '7d-opus') return t('quota.window.7dOpus');
if (label === 'extra_usage') return t('quota.window.extraUsage');
if (label === 'weekly') return t('quota.window.weekly');
if (label === 'daily') return t('quota.window.daily');
if (label === 'monthly') return t('quota.window.monthly');