Claude Code Usage Report
Uses bunx ccusage to report token consumption and costs from Claude Code sessions.
IMPORTANT: The ONLY valid subcommands are daily, weekly, monthly. Do NOT use today, this_week, this_month, or any other subcommand — they will crash.
Workflow
1. Determine the subcommand
Map the user's intent to one of the three valid subcommands:
| User intent | Subcommand | Extra flags |
|---|
| "today" / "how much today" / default | INLINECODE7 | INLINECODE8 |
| "this week" / "weekly" |
weekly | (none) |
| "this month" / "monthly" |
monthly | (none) |
| "last 7 days" |
daily |
--since $(date -d '7 days ago' +%Y%m%d) |
| "in February" / specific month |
daily |
--since 20260201 --until 20260228 |
2. Run ccusage
CODEBLOCK0
Replace daily with weekly or monthly as needed. Add --breakdown if the user asks for per-model details.
3. Format the output
CODEBLOCK1
For multi-row output (e.g. last 7 days), summarize totals and list each row briefly.
4. Deliver
- - Chat: Send the formatted message directly
- Telegram (cron context): Reply with ONLY the formatted message in a code block — no extra commentary
5. Error handling
- - If
bunx ccusage fails → check if bun/bunx is installed, report the error - If no data for the requested period → inform the user clearly ("No usage data found for this period")
- If the output is empty → suggest checking a broader date range
Examples
| User says | Period | Flags |
|---|
| "Show my claude code usage" | daily | (none) |
| "How much did I spend this week?" |
weekly | (none) |
| "Monthly report with model breakdown" | monthly |
--breakdown |
| "Usage for the last 7 days" | daily |
--since $(date -d '7 days ago' +%Y%m%d) |
Claude Code 使用报告
使用 bunx ccusage 报告 Claude Code 会话中的令牌消耗和成本。
重要提示:唯一有效的子命令是 daily、weekly、monthly。请勿使用 today、thisweek、thismonth 或任何其他子命令——它们会导致崩溃。
工作流程
1. 确定子命令
将用户的意图映射到三个有效子命令之一:
| 用户意图 | 子命令 | 额外参数 |
|---|
| 今天 / 今天用了多少 / 默认 | daily | --since $(date +%Y%m%d) --until $(date +%Y%m%d) |
| 本周 / 每周 |
weekly | (无) |
| 本月 / 每月 | monthly | (无) |
| 过去7天 | daily | --since $(date -d 7 days ago +%Y%m%d) |
| 二月份 / 特定月份 | daily | --since 20260201 --until 20260228 |
2. 运行 ccusage
json
{ tool: exec, command: bunx ccusage daily --no-color -z Europe/Paris -o desc --since $(date +%Y%m%d) --until $(date +%Y%m%d) }
根据需要将 daily 替换为 weekly 或 monthly。如果用户要求查看每个模型的详细信息,请添加 --breakdown。
3. 格式化输出
📊 Claude Code 使用报告 — <时间段>
日期/时间段 : <值>
模型 : <逗号分隔列表>
输入 : 个令牌
输出 : 个令牌
缓存读取 : 个令牌
总计 : 个令牌
成本 : $<金额> USD
对于多行输出(例如过去7天),汇总总数并简要列出每一行。
4. 交付
- - 聊天:直接发送格式化消息
- Telegram(定时任务上下文):仅回复代码块中的格式化消息——不加任何额外评论
5. 错误处理
- - 如果 bunx ccusage 失败 → 检查是否安装了 bun/bunx,报告错误
- 如果请求的时间段没有数据 → 明确告知用户(未找到该时间段的使用数据)
- 如果输出为空 → 建议检查更广的日期范围
示例
| 用户说 | 时间段 | 参数 |
|---|
| 显示我的 Claude Code 使用情况 | daily | (无) |
| 这周我花了多少钱? |
weekly | (无) |
| 按月报告并附带模型细分 | monthly | --breakdown |
| 过去7天的使用情况 | daily | --since $(date -d 7 days ago +%Y%m%d) |