# claude-usage Claude API usage monitor with dual-path authentication. ## Two API Paths ### 1. Web API (Primary) โ€” curl_cffi + sessionKey cookie - Endpoint: `claude.ai/api/organizations/{org_id}/usage` - Uses curl_cffi `impersonate="chrome"` to bypass Cloudflare TLS fingerprint (JA3/JA4) detection - Returns extra_usage, prepaid/credits balance - sessionKey needs manual refresh from browser devtools ### 2. OAuth API (Fallback) โ€” stdlib urllib + Bearer token - Endpoint: `api.anthropic.com/api/oauth/usage` - Standard Python TLS (no fingerprint needed) - Token auto-refreshes via refresh_token - No extra_usage/prepaid data ## Setup 1. Install dependency: `pip install curl_cffi` (or use `uv run`) 2. Set `WEB_TOKEN` to your claude.ai sessionKey cookie 3. Set org ID in the API URLs 4. Place OAuth credentials at `~/.claude/.credentials.json` ## Usage ```bash # Show usage uv run claude-usage.py # Mark daily baseline (run at 00:00) uv run claude-usage.py --mark # Log snapshot to history uv run claude-usage.py --log # Force OAuth API (skip Web API) uv run claude-usage.py --oauth ``` ## Output ``` ๐Ÿ“Š Token Usage (claude.ai web @ 07:04:49) Session โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘ 1% used ๐ŸŸข โ†ป4h55m Weekly โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–Šโ–‘โ–‘ 78% used ๐ŸŸข โ†ป1d3h +20% Sonnet โ–โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘ 2% used ๐ŸŸข โ†ป1d5h --- ็‡ƒ็‡’้€Ÿ็އ --- ๅฎŒ็พŽ้€Ÿ็އ: 14.3%/ๅคฉ ็•ถๅ‰้€Ÿ็އ: 13.4%/ๅคฉ๏ผˆ93% ratio๏ผ‰ ๅฏไปฅ่ถ…้€Ÿ 141%ๅ–”! ๐ŸŽ๏ธ ``` ## Credits Original: ๆ‹ๆ‹ ๐Ÿฆ… (Eagle) Bash reference: ่ธ่ธ ๐Ÿพ (Tata)