1实现原理 · 为什么它能做到
数据源是本地 ccusage:analyze_claude_usage.py 不自己解析日志,而是 subprocess 调 `ccusage claude daily/blocks --json` 取 JSON 再提炼——技能的价值在‘读 ccusage 数字并用人话解释’。
proc = subprocess.run( ["ccusage", "claude", *args, "--json"],
窗口语义:默认 --since/--until 为所选时区(默认 Asia/Shanghai)的今天;历史对比需显式给 --since,否则 rank/median 只描述单日。
Default `--since/--until` is today in the selected timezone.
模型对比支持别名:--model-a/--model-b 在目标日 modelBreakdowns 里做子串匹配(默认 fable vs opus-4-8),输出 token 比与成本比,纠正‘token 多≠贵’。
python3 scripts/analyze_claude_usage.py --model-a fable --model-b opus-4-8
5 小时 block 由 ccusage blocks 命令提供(近似配额窗口分组),脚本跳过 isGap、只留目标日 block,输出起止/模型数/entries/token/成本/cache 占比。
4. 5-hour block table when quota exhaustion is discussed.
解释层与证据层分离:SKILL 规定数字结论必须基于 ccusage/analyzer 输出,cache 要解释(read 也算用量压力),不知计划规则时用‘quota-like pressure/ccusage estimated’措辞,最终答案按 explanation-guide.md 的结构写。
Explain cache clearly: cache read tokens are still usage/quota pressure even though the user did not type those words.
2核心能力
3外部依赖
| Kind | Dependency / Endpoint |
|---|---|
| cli | ccusage(第三方 npm CLI,用量统计) |
| package | ccusage@latest(npm 全局安装) |
| cli | python3(zoneinfo 需系统 tz 数据) |
4管控建议与判定依据
- scripts/: 执行本地脚本或命令: scripts/analyze_claude_usage.py
- 网络端点: 声明外部网络访问: (仅当 ccusage 缺失时)npm install -g ccusage@latest / npx ccusage@latest —— 从 npm
5第二遍独立确认
- [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 措辞要求
6结论
009defcb5a1b30df…