| summary | read_when | ||||
|---|---|---|---|---|---|
Claude provider data sources: OAuth API, web API (cookies), CLI PTY, and local cost usage. |
|
Claude supports three usage data paths plus local cost usage. Source selection is automatic unless debug override is set.
- OAuth API (if Claude CLI credentials include
user:profilescope). - Web API (browser cookies,
sessionKey), if OAuth missing. - CLI PTY (
claude), if no OAuth and no web session.
Usage source picker:
- Preferences → Providers → Claude → Usage source (Auto/OAuth/Web/CLI).
- The Debug pane can force OAuth / Web / CLI.
- Web extras are internal-only (not exposed in the Providers pane).
- Credentials:
- Keychain service:
Claude Code-credentials(primary on macOS). - File fallback:
~/.claude/.credentials.json.
- Keychain service:
- Requires
user:profilescope (CLI tokens with onlyuser:inferencecannot call usage). - Endpoint:
GET https://api.anthropic.com/api/oauth/usage
- Headers:
Authorization: Bearer <access_token>anthropic-beta: oauth-2025-04-20
- Mapping:
five_hour→ session window.seven_day→ weekly window.seven_day_sonnet/seven_day_opus→ model-specific weekly window.extra_usage→ Extra usage cost (monthly spend/limit).
- Plan inference:
rate_limit_tierfrom credentials maps to Max/Pro/Team/Enterprise.
- Preferences → Providers → Claude → Cookie source (Automatic or Manual).
- Manual mode accepts a
Cookie:header from a claude.ai request. - Multi-account manual tokens: add entries to
~/.codexbar/config.json(tokenAccounts) and set Claude cookies to Manual. The menu can show all accounts stacked or a switcher bar (Preferences → Advanced → Display). - Claude token accounts accept either
sessionKeycookies or OAuth access tokens (sk-ant-oat...). OAuth tokens use the Anthropic OAuth usage endpoint; to force cookie mode, pastesessionKey=<value>or a fullCookie:header. - Cookie source order:
- Safari:
~/Library/Cookies/Cookies.binarycookies - Chrome/Chromium forks:
~/Library/Application Support/Google/Chrome/*/Cookies - Firefox:
~/Library/Application Support/Firefox/Profiles/*/cookies.sqlite
- Safari:
- Domain:
claude.ai. - Cookie name required:
sessionKey(value prefixsk-ant-...).
- Cached cookies: Keychain cache
com.steipete.codexbar.cache(accountcookie.claude, source + timestamp). Reused before re-importing from browsers. - API calls (all include
Cookie: sessionKey=<value>):GET https://claude.ai/api/organizations→ org UUID.GET https://claude.ai/api/organizations/{orgId}/usage→ session/weekly/opus.GET https://claude.ai/api/organizations/{orgId}/overage_spend_limit→ Extra usage spend/limit.GET https://claude.ai/api/account→ email + plan hints.
- Outputs:
- Session + weekly + model-specific percent used.
- Extra usage spend/limit (if enabled).
- Account email + inferred plan.
- Runs
claudein a PTY session (ClaudeCLISession). - Default behavior: exit after each probe; Debug → "Keep CLI sessions alive" keeps it running between probes.
- Command flow:
- Start CLI with
--allowed-tools ""(no tools). - Auto-respond to first-run prompts (trust files, workspace, telemetry).
- Send
/usage, wait for rendered panel; send Enter retries if needed. - Optionally send
/statusto extract identity fields.
- Start CLI with
- Parsing (
ClaudeStatusProbe):- Strips ANSI, locates "Current session" + "Current week" headers.
- Extracts percent left/used and reset text near those headers.
- Parses
Account:andOrg:lines when present. - Surfaces CLI errors (e.g. token expired) directly.
- Source roots:
$CLAUDE_CONFIG_DIR(comma-separated), each root uses<root>/projects.- Fallback roots:
~/.config/claude/projects~/.claude/projects
- Files:
**/*.jsonlunder the project roots. - Parsing:
- Lines with
type: "assistant"andmessage.usage. - Uses per-model token counts (input, cache read/create, output).
- Deduplicates streaming chunks by
message.id + requestId(usage is cumulative per chunk).
- Lines with
- Cache:
~/Library/Caches/CodexBar/cost-usage/claude-v1.json
- OAuth:
Sources/CodexBarCore/Providers/Claude/ClaudeOAuth/* - Web API:
Sources/CodexBarCore/Providers/Claude/ClaudeWeb/ClaudeWebAPIFetcher.swift - CLI PTY:
Sources/CodexBarCore/Providers/Claude/ClaudeStatusProbe.swift,Sources/CodexBarCore/Providers/Claude/ClaudeCLISession.swift - Cost usage:
Sources/CodexBarCore/CostUsageFetcher.swift,Sources/CodexBarCore/Vendored/CostUsage/*