← 返回 CLI 目录 抓取的
ccusage
$ ccusage 社区开源 低风险 ccusage · Agent 桥接与元工具 · MIT · macos / linux / windows
ccusage 读取本地 AI 编码 CLI(Claude Code、Codex、OpenCode 等)会话日志,生成 daily、weekly、monthly、session 与 blocks 用量及费用报表。支持 --json、--compact、--no-cost、--instances 与 --timezone。
FCRS-1.0 综合评分
92 /100
极佳 (Excellent)
高置信度 (实测)
零摩擦安装命令
brew install ccusage CLI vs MCP 选型建议 CLI + MCP 搭配
ccusage 作为只读 CLI(ccusage daily --json)进行费用审计与脚本统计最为快捷;生态中也提供可选的 @ccusage/mcp 服务。
Agent 友好度体检单
本地探针实测证据 ✓ 原生 JSON 输出
✓ 字段裁剪
✓ 无头非交互
— 支持 Dry-Run
— 只读模式开关
— 支持 NO_COLOR
✓ 自省/Schema 发现
— 官方 SKILL.md
实测版本
16.1.2
冷启动耗时
134 ms
退出码 (help / 非法参数)
0 / 1
NO_COLOR 无色码污染 / 无 TTY 不挂起
Yes / Safe
抓取的 --help 摘要
USAGE: ccusage [daily] <OPTIONS> ccusage <COMMANDS> COMMANDS: daily Show usage report grouped by date monthly Show usage report grouped by month weekly Show usage report grouped by week session Show usage report grouped by conversation session blocks Show usage report grouped by session billing blocks mcp Start MCP server with usage reporting tools statusline Display compact status line for Claude Code hooks with hybrid time+file caching (Beta) For more info, run any command with the `--help` flag: ccusage daily --help ccusage monthly --help ccusage weekly --help ccusage session --help ccusage blocks --help ccusage mcp --help ccusage statusline --help OPTIONS: -s, --since <since> Filter from date (YYYYMMDD format) -u, --until <until> Filter until date (YYYYMMDD format) -j, --json Output in JSON format (default: false) -m, --mode [mode] Cost calculation mode: auto (use costUSD if exists, otherwise calculate), calculate (always calculate), display (always use costUSD) (default: auto, choices: auto | calculate | display) -d, --debug Show pricing mismatch information for debugging (default: false) --debug-samples [debug-samples] Number of sample discrepancies to show in debug output (default: 5) (default: 5) -o, --order [order] Sort order: desc (newest first) or asc (oldest first) (default: asc, choices: desc | asc) -b, --breakdown Show per-model cost breakdown (default: false) -O, --offline Use cached pricing data for Claude models instead of fetching from API (default: false) --no-offline Negatable of -O, --offline --color Enable colored output (default: auto). FORCE_COLOR=1 has the same effect. --no-color Disable colored output (default: auto). NO_COLOR=1 has the same effect. -z, --timezone <timezone> Timezone for date grouping (e.g., UTC, America/New_York, Asia/Tokyo). Default: system timezone -l, --locale [locale] Locale for date/time formatting (e.g., en-US, ja-JP, de-DE) (default: en-CA) -q, --jq <jq>
FCRS-1.0 六维评分拆解
Agent 友好度 24 / 25
支持无交互报表查询(daily、weekly、monthly、session)及 --json、--no-cost、--instances、--timezone 参数。
--json,--compact,--no-cost,--instances, and--timezoneacross report subcommands
安全与权限边界 24 / 25
严格只读解析本地 JSONL 日志文件,不涉及任何网络写入或凭据存储。
- Read-only local JSONL log parsing (cached LiteLLM pricing optional/offline fallback)
安装与运行摩擦 14 / 15
可通过 npx ccusage@latest、npm install -g ccusage 或 brew install ccusage 在全平台运行。
- Available on Homebrew, npm, and
npx ccusage@latest
能力覆盖与边际价值 14 / 15
直观统计缓存命中率、分模型 Token 消耗与 5 小时计费窗口。
- Covers input/output/cache-read/cache-create tokens and multi-CLI subcommands
维护与来源背书 8 / 10
维护活跃的 MIT 开源社区项目(ccusage/ccusage),配有独立文档与扩展包。
- Active
ccusage/ccusagerepository under MIT
文档与可验证性 8 / 10
ccusage.com/guide/ 详尽说明了 JSON 输出结构、CLI 参数与子命令。
- Official docs at
ccusage.com/guide/
安全边界、鉴权与放权指南
鉴权方式
无需鉴权
凭证存储位置
仅读取本地会话 JSONL 日志(如 ~/.claude/projects/),无需任何 API Key 或登录态。
潜在副作用
只读查询
费用与配额提示
100% 免费且基于 MIT 协议开源。
可复制到 CLAUDE.md / AGENTS.md 的安全护栏
# ccusage Agent Rules - Always pass `--json` when querying usage reports from agents or scripts. - Use `daily`, `weekly`, `monthly`, or `session` (avoid live `blocks --live` watch loops in non-interactive runs).
Agent 高频安全命令配方
只读查询(安全推荐)
以 JSON 导出每日 Token 与费用明细
ccusage daily --json --timezone UTC
解析本地 JSONL 会话日志,按 JSON 输出每日输入/输出/缓存 Token 汇总与估算美元费用。
查看各项目实例统计(不含费用字段)
ccusage session --instances --no-cost --json
按项目实例拆分会话 Token 用量并以 JSON 返回,同时省略金额字段。
核心优势
- + 零配置只读审计本地 AI 编码 CLI 的 Token 与缓存开销。
- +
daily、weekly、monthly与session均提供干净的--json输出。 - + 支持
--no-cost、--instances与--timezone精细化统计。
注意事项与踩坑点
- ! 估算美元金额依赖上游 LiteLLM 定价表,可能与账单略有差异。
- !
blocks --live会启动持续刷新的终端监控,非交互流程应避免调用。
已验证兼容的 Agent 宿主
Claude Code Codex CLI Gemini CLI