claude-usage-analyst
Analyze Claude Code and Claude Desktop Code token usage, cost, quota burn, model mix, cache read/write, and 5-hour block consumption using ccusage evidence. Use when the user asks why Claude quota was exhausted, whether a model such as fable/opus/sonnet is unusually expensive, how many tokens were spent today or historically, or needs a human-friendly explanation of local Claude Code CLI/Desktop usage.
1How It Works & Mechanism
Data source is local ccusage: analyze_claude_usage.py does not parse logs itself; instead, it uses subprocess to call `ccusage claude daily/blocks --json` to fetch JSON and extract metrics—the skill's value lies in 'interpreting ccusage figures into plain human language'.
proc = subprocess.run( ["ccusage", "claude", *args, "--json"],
Window semantics: by default, --since/--until targets today in the selected timezone (default: Asia/Shanghai); historical comparison requires an explicit --since, otherwise rank/median only reflects a single day.
Default `--since/--until` is today in the selected timezone.
Model comparison supports aliases: --model-a/--model-b performs substring matching against target day modelBreakdowns (default fable vs opus-4-8), outputting token ratio vs cost ratio to correct the misconception that 'more tokens always means more expensive'.
python3 scripts/analyze_claude_usage.py --model-a fable --model-b opus-4-8
5-hour blocks are provided by the ccusage blocks command (approximate quota window grouping); the script skips isGap, retains only target-day blocks, and outputs start/end times, model counts, entries, tokens, cost, and cache ratio.
4. 5-hour block table when quota exhaustion is discussed.
Separation of explanation and evidence layers: the SKILL mandates that numerical conclusions must be grounded in ccusage/analyzer outputs. Cache must be explained (reads also exert usage pressure). When plan rules are unknown, phrasing such as 'quota-like pressure/ccusage estimated' must be used, with final answers structured according to explanation-guide.md.
Explain cache clearly: cache read tokens are still usage/quota pressure even though the user did not type those words.
2Core Capabilities
3External Dependencies
| Kind | Dependency / Endpoint |
|---|---|
| cli | ccusage(第三方 npm CLI,用量统计) |
| package | ccusage@latest(npm 全局安装) |
| cli | python3(zoneinfo 需系统 tz 数据) |
4Recommended Governance & Evidence
- scripts/: Execute local scripts or commands: scripts/analyze_claude_usage.py
- 网络端点: Declared external network access: (Only when ccusage is missing) npm install -g ccusage@latest / npx ccusage@latest —— from npm
5Second-Pass Verification
- [ok] 无网络外发(脚本自身) — 无 urllib/requests/socket;唯一外部动作是 npm install ccusage 的安装提示(用户/agent 执行)
- [ok] 无凭证读取 — 无 environ/getenv/settings/.claude.json 读取;ccusage 侧读取范围不可在本仓审计(已在 reason 注明)
- [ok] 无写文件 — 脚本只 print(stdout),无文件写入
- [ok] 数字字段映射准确 — cacheCreationTokens/cacheReadTokens/cost 等字段名与 ccusage JSON 语义一致;model_total 明确含 cache 系 token
- [ok] ‘ccusage 不是官方账单’边界 — SKILL evidence rules 与 explanation-guide caveats 双重声明 estimated/quota-like 措辞要求
6Verdict & Scenarios
009defcb5a1b30df…