toll — Token Usage Tracker
INLINECODE0 is a CLI tool that aggregates token usage logs from Claude Code and Codex CLI and displays session counts, token totals, cache hit rates, and estimated USD costs.
Installation
If toll is not installed, install it first:
CODEBLOCK0
Usage
When the user invokes /toll, run the appropriate toll command based on their intent:
| User Intent | Command |
|---|
| All-time summary (default) | INLINECODE4 |
| Today's usage only |
toll --today |
| Last N days |
toll --days <N> |
| Daily breakdown |
toll --by-day |
| Claude Code only |
toll --claude |
| Codex CLI only |
toll --codex |
| Full token counts |
toll --detail |
| JSON output |
toll --json |
| CSV output |
toll --csv |
| List model prices |
toll --list-prices |
Flags can be combined, e.g. toll --by-day --days 7 --claude.
Behavior
- 1. Check if
toll is installed by running toll --version. If it fails, prompt the user to install it using the command above. - Parse the user's request to determine which flags to pass.
- Run
toll with the appropriate flags and present the output to the user. - Explain the output if the user seems unfamiliar with the metrics:
-
Sessions: number of AI coding sessions tracked
-
Input: total input tokens sent to the model
-
Cached: tokens served from the prompt cache (cheaper)
-
Hit Rate: percentage of input tokens that were cached
-
Net Input: non-cached input tokens (full price)
-
Output: tokens generated by the model
-
Cost: estimated USD cost based on per-model pricing
Example Interactions
User: /toll
→ Run toll and show all-time summary
User: /toll today
→ Run INLINECODE21
User: /toll last 7 days
→ Run INLINECODE23
User: /toll daily breakdown this week
→ Run INLINECODE25
User: /toll how much have I spent on Claude?
→ Run toll --claude and highlight the Cost column
User: /toll export csv
→ Run toll --csv and offer to save the output to a file
Notes
- - Cost estimates marked with
* include models whose pricing is approximate or inferred by prefix matching. - Token counts use compact notation:
1.2m = 1,200,000 tokens, 45.6k = 45,600 tokens. - Logs are read from
~/.claude/projects/**/*.jsonl (Claude Code) and ~/.codex/sessions/ (Codex CLI).
技能名称: toll
详细描述:
toll — Token使用追踪器
toll 是一个命令行工具,用于聚合来自 Claude Code 和 Codex CLI 的Token使用日志,并显示会话数量、Token总数、缓存命中率以及预估的美元成本。
安装
如果尚未安装 toll,请先安装:
bash
快速安装(Linux/macOS)
curl -fsSL https://raw.githubusercontent.com/Fullstop000/toll/refs/heads/master/install.sh | sh
或通过 cargo 安装
cargo install toll
使用方法
当用户调用 /toll 时,根据其意图运行相应的 toll 命令:
| 用户意图 | 命令 |
|---|
| 全部时间汇总(默认) | toll |
| 仅今日使用情况 |
toll --today |
| 最近N天 | toll --days
|
| 每日明细 | toll --by-day |
| 仅Claude Code | toll --claude |
| 仅Codex CLI | toll --codex |
| 完整Token计数 | toll --detail |
| JSON输出 | toll --json |
| CSV输出 | toll --csv |
| 列出模型价格 | toll --list-prices |
标志可以组合使用,例如 toll --by-day --days 7 --claude。
行为
- 1. 检查 toll 是否已安装,通过运行 toll --version。如果失败,提示用户使用上述命令进行安装。
- 解析用户的请求,确定需要传递哪些标志。
- 使用适当的标志运行 toll,并将输出呈现给用户。
- 解释输出内容,如果用户对指标不熟悉:
- Sessions(会话):追踪的AI编码会话数量
- Input(输入):发送给模型的输入Token总数
- Cached(缓存):从提示缓存中提供的Token(更便宜)
- Hit Rate(命中率):输入Token中被缓存的百分比
- Net Input(净输入):未缓存的输入Token(全价)
- Output(输出):模型生成的Token
- Cost(成本):基于各模型定价的预估美元成本
交互示例
用户: /toll
→ 运行 toll 并显示全部时间汇总
用户: /toll today
→ 运行 toll --today
用户: /toll last 7 days
→ 运行 toll --days 7
用户: /toll daily breakdown this week
→ 运行 toll --by-day --days 7
用户: /toll how much have I spent on Claude?
→ 运行 toll --claude 并高亮显示成本列
用户: /toll export csv
→ 运行 toll --csv 并提供将输出保存到文件的选项
注意事项
- - 标有 的成本估算包括定价为近似值或通过前缀匹配推断的模型。
- Token计数使用紧凑表示法:1.2m = 1,200,000 个Token,45.6k = 45,600 个Token。
- 日志从 ~/.claude/projects//.jsonl(Claude Code)和 ~/.codex/sessions/(Codex CLI)读取。