Scan local Claude Code logs (~/.claude/projects/), by date × model dimension, tally token consumption and API equivalent cost.
Pure Python 3 script, no dependencies to install, cross-platform (Mac / Linux / Windows).
Trigger words
- "/cc-usage"
- "check usage"
- "token consumption"
- "usage statistics"
Execution steps
- Determine parameters based on user needs (number of days, project, output format)
- Run the analysis script
- Organize the results intoa readable Markdown tableand return to the user
Script location
.claude/skills/cc-usage/scripts/analyzer.py
Usage
# 默认:全部历史,所有项目
python3 .claude/skills/cc-usage/scripts/analyzer.py
# 最近 N 天
python3 .claude/skills/cc-usage/scripts/analyzer.py --days 7
# 只看某项目(模糊匹配目录名)
python3 .claude/skills/cc-usage/scripts/analyzer.py --project mylife
# 输出 CSV(可导入 Excel)
python3 .claude/skills/cc-usage/scripts/analyzer.py --csv
# 只看模型汇总
python3 .claude/skills/cc-usage/scripts/analyzer.py --summary
Default behavior
When the user does not specify a number of days, run --days 7(last 7 days) by default.
Output requirements
After the script finishes, the AI should:
- Organize the key data into a Markdown table (by day × model)
- Provide daily subtotals and grand total
- Attach a model summary (which model costs the most)
- If there are anomalies (a sudden spike on some day), proactively point them out
Cross-platform notes
- Path: use
os.path.expanduser('~')for automatic adaptation - Time zone: use
datetime.astimezone()to automatically detect the system local time zone - Dependencies: only Python 3 standard library, no pip install needed
Maintenance tips
When a new model goes live, you need to update the MODEL_SHORT and PRICING dictionaries in the script.