cost-tracker
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseCost Tracker
成本跟踪器
Monitor and optimize Claude Code session costs.
监控并优化 Claude Code 会话成本。
Trigger
触发条件
Use when:
- Checking session costs
- Setting budget alerts
- Optimizing token spend
- Planning multi-session work
在以下情况下使用:
- 检查会话成本
- 设置预算提醒
- 优化 Token 支出
- 规划多会话工作
Cost Awareness
成本意识
Check Current Costs
检查当前成本
bash
undefinedbash
undefinedSession cost is shown at the end of each session
Session cost is shown at the end of each session
Mid-session: check the status bar or run /cost
Mid-session: check the status bar or run /cost
undefinedundefinedCost Drivers
成本驱动因素
| Operation | Relative Cost | Optimization |
|---|---|---|
| Large file reads | High | Use offset/limit params |
| Broad grep searches | Medium | Scope to specific dirs |
| Subagent spawning | High (new context) | Reuse agents via SendMessage |
| Repeated tool calls | Cumulative | Batch operations |
| MCP tool calls | Variable | Minimize round-trips |
| Model selection | 3-10x difference | Use haiku for simple tasks |
| 操作 | 相对成本 | 优化方式 |
|---|---|---|
| 大型文件读取 | 高 | 使用 offset/limit 参数 |
| 广泛 grep 搜索 | 中 | 限定到特定目录 |
| 启动 Subagent | 高(新上下文) | 通过 SendMessage 复用 Agent |
| 重复工具调用 | 累积 | 批处理操作 |
| MCP 工具调用 | 可变 | 尽量减少往返调用 |
| 模型选择 | 3–10 倍差异 | 简单任务使用 Haiku |
Token Budget by Task Type
按任务类型划分的 Token 预算
| Task | Typical Cost | Budget Alert |
|---|---|---|
| Bug fix | $0.10-0.50 | $1.00 |
| Feature (small) | $0.50-2.00 | $3.00 |
| Feature (large) | $2.00-8.00 | $10.00 |
| Refactor | $1.00-5.00 | $7.00 |
| Code review | $0.20-1.00 | $2.00 |
| 任务 | 典型成本 | 预算提醒 |
|---|---|---|
| Bug 修复 | $0.10–0.50 | $1.00 |
| 小型功能 | $0.50–2.00 | $3.00 |
| 大型功能 | $2.00–8.00 | $10.00 |
| 重构 | $1.00–5.00 | $7.00 |
| 代码审查 | $0.20–1.00 | $2.00 |
Tool-Call Budgets
工具调用预算
Set explicit budgets by task complexity:
| Task Type | Tool-Call Budget | Wrap-Up At |
|---|---|---|
| Quick fix / lookup | 20 calls | 15 |
| Bug fix | 30 calls | 25 |
| Feature (small) | 50 calls | 40 |
| Feature (large) | 80 calls | 65 |
| Refactor | 50 calls | 40 |
At the wrap-up threshold: commit progress, assess remaining work, decide whether to continue or start fresh.
根据任务复杂度设置明确的预算:
| 任务类型 | 工具调用预算 | 收尾阈值 |
|---|---|---|
| 快速修复/查询 | 20 次调用 | 15 |
| Bug 修复 | 30 次调用 | 25 |
| 小型功能 | 50 次调用 | 40 |
| 大型功能 | 80 次调用 | 65 |
| 重构 | 50 次调用 | 40 |
达到收尾阈值时:提交当前进度,评估剩余工作,并决定是继续当前会话还是开启新会话。
Optimization Strategies
优化策略
- Scope prompts tightly — "Fix the auth bug in src/auth/login.ts" vs "Fix the auth bug"
- Use the right model — Haiku for simple lookups, Sonnet for features, Opus for architecture
- Delegate to subagents — Search/explore operations in subagents keep main context lean
- Compact proactively — Don't wait for auto-compact; compact at task boundaries
- Read selectively — Use and
offsetparams for large fileslimit - Batch operations — Multiple independent tool calls in one message
- One-pass discipline — Write complete solution, test once, stop if green
- No re-reads — Don't re-read unchanged files; trust cached knowledge
- Read before write — Never write a file without reading it first
- Kill output bloat — No sycophantic openers, no closing fluff, no prompt restatement
- 精确限定提示范围 — 使用“修复 src/auth/login.ts 中的认证 Bug”,而不是“修复认证 Bug”
- 选择合适的模型 — 简单查询使用 Haiku,功能开发使用 Sonnet,架构设计使用 Opus
- 委派给 Subagent — 将搜索和探索任务交给 Subagent,保持主上下文精简
- 主动 compact — 不要等待自动 compact,在任务边界处执行 compact
- 选择性读取 — 对大型文件使用 和
offset参数limit - 批处理操作 — 在一条消息中执行多个相互独立的工具调用
- 坚持一次完成 — 写出完整解决方案,测试一次,通过后立即停止
- 避免重复读取 — 不要重新读取未发生变化的文件;信任已缓存的信息
- 先读后写 — 未读取文件前绝不写入
- 减少输出冗余 — 不要使用奉承式开场、无意义结尾或复述提示词
Budget Alerts
预算提醒
Set mental checkpoints:
- 50% budget — Are you on track? Should you compact?
- 80% budget — Wrap up current task, avoid new exploration
- 100% budget — Commit what you have, start fresh session
设置心理检查点:
- 预算的 50% — 当前进度是否符合预期?是否应该 compact?
- 预算的 80% — 收尾当前任务,避免开展新的探索
- 预算的 100% — 提交已有成果,开启新会话
Output
输出
text
COST TRACKER
Session cost: $X.XX
Token usage: [input]K in / [output]K out
Cache hit rate: ~XX%
Top cost drivers:
1. [operation] — $X.XX
2. [operation] — $X.XX
Optimization tips:
- [specific suggestion]text
COST TRACKER
Session cost: $X.XX
Token usage: [input]K in / [output]K out
Cache hit rate: ~XX%
Top cost drivers:
1. [operation] — $X.XX
2. [operation] — $X.XX
Optimization tips:
- [specific suggestion]Rules
规则
- Track costs as awareness, not hard limits
- Never sacrifice code quality to save tokens
- Compact at task boundaries, not mid-task
- Use subagents for exploration-heavy work
- 将成本跟踪作为意识提醒,而非硬性限制
- 绝不牺牲代码质量来节省 Token
- 在任务边界处 compact,而不是在任务执行中途 compact
- 对探索密集型工作使用 Subagent