codeburn-claude-cost-dashboard
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseCodeBurn
CodeBurn
Skill by ara.so — Daily 2026 Skills collection.
CodeBurn is an interactive TUI dashboard that reads Claude Code session transcripts directly from disk () and visualizes token usage, costs, and task breakdowns by project, model, activity type, MCP server, and tool. No API keys, no proxy — pure local file analysis.
~/.claude/projects/由ara.so开发的Skill — 2026每日技能合集。
CodeBurn是一个交互式TUI仪表板,直接从磁盘()读取Claude Code会话记录,可视化令牌使用量、成本以及按项目、模型、活动类型、MCP服务器和工具划分的任务明细。无需API密钥,无需代理——纯本地文件分析。
~/.claude/projects/Install
安装
bash
npm install -g codeburnbash
npm install -g codeburnor run without installing
或无需安装直接运行
npx codeburn
**Requirements:** Node.js 20+, Claude Code installed (session data at `~/.claude/projects/`)npx codeburn
**要求:** Node.js 20+,已安装Claude Code(会话数据存储在`~/.claude/projects/`)Key Commands
核心命令
bash
undefinedbash
undefinedInteractive TUI dashboard (default: last 7 days)
交互式TUI仪表板(默认:最近7天)
codeburn
codeburn
Time period shortcuts
时间周期快捷命令
codeburn today
codeburn month
codeburn report -p month # explicit period flag
codeburn today
codeburn month
codeburn report -p month # 显式周期参数
Compact one-liner summary
简洁单行摘要
codeburn status
codeburn status --format json
codeburn status
codeburn status --format json
Export data
导出数据
codeburn export # CSV: today, 7d, 30d
codeburn export -f json # JSON export
codeburn export # CSV格式:今日、7天、30天
codeburn export -f json # JSON格式导出
macOS menu bar widget (requires SwiftBar)
macOS菜单栏组件(需要SwiftBar)
codeburn install-menubar
codeburn uninstall-menubar
undefinedcodeburn install-menubar
codeburn uninstall-menubar
undefinedTUI Keyboard Navigation
TUI键盘导航
| Key | Action |
|---|---|
| Switch between Today / 7 Days / Month |
| Period shortcuts |
| Quit |
| 按键 | 操作 |
|---|---|
| 切换今日/7天/月视图 |
| 时间周期快捷按键 |
| 退出 |
What CodeBurn Tracks
CodeBurn追踪内容
13 Task Categories (deterministic, no LLM calls)
13种任务分类(确定性分类,无需调用LLM)
| Category | Trigger Pattern |
|---|---|
| Coding | Edit, Write tools |
| Debugging | Error/fix keywords + tool usage |
| Feature Dev | "add", "create", "implement" keywords |
| Refactoring | "refactor", "rename", "simplify" |
| Testing | pytest, vitest, jest in Bash |
| Exploration | Read, Grep, WebSearch without edits |
| Planning | EnterPlanMode, TaskCreate tools |
| Delegation | Agent tool spawns |
| Git Ops | git push/commit/merge in Bash |
| Build/Deploy | npm build, docker, pm2 |
| Brainstorming | "brainstorm", "what if", "design" |
| Conversation | No tools, pure text exchange |
| General | Skill tool, uncategorized |
| 分类 | 触发模式 |
|---|---|
| 编码 | 编辑、写入工具 |
| 调试 | 错误/修复关键词 + 工具使用 |
| 功能开发 | "add"、"create"、"implement"关键词 |
| 重构 | "refactor"、"rename"、"simplify"关键词 |
| 测试 | Bash中调用pytest、vitest、jest |
| 探索 | 读取、Grep、网页搜索且无编辑操作 |
| 规划 | EnterPlanMode、TaskCreate工具 |
| 委托 | Agent工具调用 |
| Git操作 | Bash中执行git push/commit/merge |
| 构建/部署 | npm build、docker、pm2 |
| 头脑风暴 | "brainstorm"、"what if"、"design"关键词 |
| 对话 | 无工具调用,纯文本交互 |
| 通用 | Skill工具、未分类操作 |
One-Shot Rate
单次成功率
For edit-heavy categories, CodeBurn detects Edit → Bash → Edit retry cycles. The 1-shot rate shows what percentage of edit turns succeeded without retries. 90% means the AI got it right first try 9/10 times.
对于编辑密集型分类,CodeBurn可以检测编辑→Bash→编辑的重试循环。单次成功率表示编辑回合无需重试即成功的百分比。90%意味着AI每10次尝试中有9次一次就做对了。
Pricing
定价
Fetched from LiteLLM model prices, auto-cached 24h at . Covers input, output, cache write, cache read, and web search costs. Falls back to hardcoded prices if fetch fails.
~/.cache/codeburn/从LiteLLM模型价格获取,在自动缓存24小时。涵盖输入、输出、缓存写入、缓存读取和网页搜索成本。如果获取失败,将回退到硬编码价格。
~/.cache/codeburn/Data Source
数据源
Claude Code stores session transcripts as JSONL:
~/.claude/projects/<sanitized-path>/<session-id>.jsonlEach assistant entry contains: model name, token usage (input/output/cache_read/cache_write), tool_use blocks, timestamps. CodeBurn deduplicates by API message ID to prevent double-counting across sessions.
Claude Code将会话记录存储为JSONL格式:
~/.claude/projects/<sanitized-path>/<session-id>.jsonl每个助手条目包含:模型名称、令牌使用量(输入/输出/缓存读取/缓存写入)、tool_use块、时间戳。CodeBurn通过API消息ID进行去重,防止跨会话重复统计。
macOS Menu Bar Setup
macOS菜单栏设置
bash
undefinedbash
undefined1. Install SwiftBar
1. 安装SwiftBar
brew install --cask swiftbar
brew install --cask swiftbar
2. Install the CodeBurn plugin
2. 安装CodeBurn插件
codeburn install-menubar
codeburn install-menubar
3. Launch SwiftBar — CodeBurn flame icon appears in menu bar
3. 启动SwiftBar — CodeBurn火焰图标将出现在菜单栏中
Refreshes every 5 minutes, shows today's cost + breakdown dropdown
每5分钟刷新一次,显示今日成本 + 明细下拉菜单
To remove:
```bash
codeburn uninstall-menubar
卸载方式:
```bash
codeburn uninstall-menubarExport Examples
导出示例
bash
undefinedbash
undefinedExport CSV (three sheets: today, 7d, 30d)
导出CSV(三个工作表:今日、7天、30天)
codeburn export
codeburn export
Output: codeburn-export-2026-04-14.csv
输出:codeburn-export-2026-04-14.csv
Export JSON
导出JSON
codeburn export -f json
codeburn export -f json
Output: codeburn-export-2026-04-14.json
输出:codeburn-export-2026-04-14.json
undefinedundefinedJSON Export Structure
JSON导出结构
json
{
"exported_at": "2026-04-14T10:00:00Z",
"periods": {
"today": {
"total_cost": 1.42,
"total_tokens": 284000,
"by_project": { "my-app": 0.89, "other-project": 0.53 },
"by_model": { "claude-sonnet-4-5": 1.10, "claude-opus-4-5": 0.32 },
"by_activity": {
"Coding": { "cost": 0.65, "turns": 34, "one_shot_rate": 0.88 },
"Debugging": { "cost": 0.41, "turns": 18, "one_shot_rate": 0.72 }
}
},
"7d": { ... },
"30d": { ... }
}
}json
{
"exported_at": "2026-04-14T10:00:00Z",
"periods": {
"today": {
"total_cost": 1.42,
"total_tokens": 284000,
"by_project": { "my-app": 0.89, "other-project": 0.53 },
"by_model": { "claude-sonnet-4-5": 1.10, "claude-opus-4-5": 0.32 },
"by_activity": {
"Coding": { "cost": 0.65, "turns": 34, "one_shot_rate": 0.88 },
"Debugging": { "cost": 0.41, "turns": 18, "one_shot_rate": 0.72 }
}
},
"7d": { ... },
"30d": { ... }
}
}Project Structure
项目结构
src/
cli.ts # Commander.js entry point
dashboard.tsx # Ink TUI (React for terminals)
parser.ts # JSONL reader, dedup, date filter
models.ts # LiteLLM pricing, cost calculation
classifier.ts # 13-category task classifier
types.ts # Type definitions
format.ts # Text rendering (status bar)
menubar.ts # SwiftBar plugin generator
export.ts # CSV/JSON multi-period exportsrc/
cli.ts # Commander.js入口文件
dashboard.tsx # Ink TUI(终端版React)
parser.ts # JSONL读取器、去重、日期过滤器
models.ts # LiteLLM定价、成本计算
classifier.ts # 13类任务分类器
types.ts # Type定义
format.ts # 文本渲染(状态栏)
menubar.ts # SwiftBar插件生成器
export.ts # CSV/JSON多周期导出Programmatic Usage (TypeScript)
程序化使用(TypeScript)
If you want to integrate CodeBurn's parsing logic into your own scripts:
typescript
import { parseSessions } from 'codeburn/parser';
import { calculateCost } from 'codeburn/models';
import { classifyTurn } from 'codeburn/classifier';
// Parse all sessions for a date range
const sessions = await parseSessions({
startDate: new Date('2026-04-01'),
endDate: new Date('2026-04-14'),
});
// Sessions are deduplicated by API message ID
for (const turn of sessions.turns) {
const category = classifyTurn(turn);
const cost = await calculateCost(turn.model, turn.usage);
console.log(`${category}: $${cost.toFixed(4)}`);
}typescript
// Get a status summary programmatically
import { getStatus } from 'codeburn/format';
const status = await getStatus();
console.log(status);
// → "🔥 Today: $1.42 (284k tokens) | Month: $18.30 (3.6M tokens)"
// JSON format for scripting
const statusJson = await getStatus({ format: 'json' });
const data = JSON.parse(statusJson);
// { today: { cost: 1.42, tokens: 284000 }, month: { cost: 18.30, tokens: 3600000 } }如果你想将CodeBurn的解析逻辑集成到自己的脚本中:
typescript
import { parseSessions } from 'codeburn/parser';
import { calculateCost } from 'codeburn/models';
import { classifyTurn } from 'codeburn/classifier';
// 解析指定日期范围内的所有会话
const sessions = await parseSessions({
startDate: new Date('2026-04-01'),
endDate: new Date('2026-04-14'),
});
// 会话已通过API消息ID去重
for (const turn of sessions.turns) {
const category = classifyTurn(turn);
const cost = await calculateCost(turn.model, turn.usage);
console.log(`${category}: $${cost.toFixed(4)}`);
}typescript
// 以编程方式获取状态摘要
import { getStatus } from 'codeburn/format';
const status = await getStatus();
console.log(status);
// → "🔥 今日: $1.42 (284k令牌) | 本月: $18.30 (3.6M令牌)"
// 用于脚本的JSON格式
const statusJson = await getStatus({ format: 'json' });
const data = JSON.parse(statusJson);
// { today: { cost: 1.42, tokens: 284000 }, month: { cost: 18.30, tokens: 3600000 } }Common Patterns
常见用法模式
Daily Cost Check in CI/Shell Scripts
CI/Shell脚本中的每日成本检查
bash
#!/bin/bashbash
#!/bin/bashAdd to .zshrc or run in CI to log daily AI spend
添加到.zshrc或在CI中运行以记录每日AI支出
SPEND=$(codeburn status --format json | jq '.today.cost')
echo "Today's Claude spend: $$SPEND"
SPEND=$(codeburn status --format json | jq '.today.cost')
echo "今日Claude支出: $$SPEND"
Alert if over threshold
超过阈值时发出警报
if (( $(echo "$SPEND > 5.00" | bc -l) )); then
echo "⚠️ High AI spend today: $$SPEND"
fi
undefinedif (( $(echo "$SPEND > 5.00" | bc -l) )); then
echo "⚠️ 今日AI支出过高: $$SPEND"
fi
undefinedExport and Analyze with jq
使用jq导出并分析
bash
undefinedbash
undefinedExport JSON and analyze by model
导出JSON并按模型分析
codeburn export -f json | jq '.periods["7d"].by_model'
codeburn export -f json | jq '.periods["7d"].by_model'
Find most expensive project this month
查找本月成本最高的项目
codeburn export -f json | jq '
.periods["30d"].by_project
| to_entries
| sort_by(-.value)
| .[0]
'
undefinedcodeburn export -f json | jq '
.periods["30d"].by_project
| to_entries
| sort_by(-.value)
| .[0]
'
undefinedAutomate Weekly Reports
自动生成周报
bash
#!/bin/bashbash
#!/bin/bashweekly-ai-report.sh — run via cron on Mondays
weekly-ai-report.sh — 通过cron在周一运行
OUTPUT_DIR="$HOME/ai-cost-reports"
mkdir -p "$OUTPUT_DIR"
DATE=$(date +%Y-%m-%d)
codeburn export -f json > "$OUTPUT_DIR/week-$DATE.json"
codeburn status >> "$OUTPUT_DIR/history.log"
echo "[$DATE] Report saved to $OUTPUT_DIR/week-$DATE.json"
undefinedOUTPUT_DIR="$HOME/ai-cost-reports"
mkdir -p "$OUTPUT_DIR"
DATE=$(date +%Y-%m-%d)
codeburn export -f json > "$OUTPUT_DIR/week-$DATE.json"
codeburn status >> "$OUTPUT_DIR/history.log"
echo "[$DATE] 报告已保存至 $OUTPUT_DIR/week-$DATE.json"
undefinedTroubleshooting
故障排除
No data shown / "No sessions found"
无数据显示 / "未找到会话"
bash
undefinedbash
undefinedVerify Claude Code session files exist
验证Claude Code会话文件是否存在
ls ~/.claude/projects/
ls ~/.claude/projects/
Check a specific project's sessions
检查特定项目的会话
ls ~/.claude/projects/<project-name>/
ls ~/.claude/projects/<project-name>/
Should see *.jsonl files
应看到*.jsonl文件
Confirm Node version is 20+
确认Node版本为20+
node --version
undefinednode --version
undefinedPricing fetch fails / shows $0.00
定价获取失败 / 显示$0.00
bash
undefinedbash
undefinedClear the price cache and retry
清除价格缓存并重试
rm -rf ~/.cache/codeburn/
rm -rf ~/.cache/codeburn/
CodeBurn falls back to hardcoded prices automatically
CodeBurn会自动回退到硬编码价格
Run again — it will re-fetch from LiteLLM
重新运行——将从LiteLLM重新获取价格
codeburn today
undefinedcodeburn today
undefinedMenu bar widget not updating
菜单栏组件不更新
bash
undefinedbash
undefinedReinstall the plugin
重新安装插件
codeburn uninstall-menubar
codeburn install-menubar
codeburn uninstall-menubar
codeburn install-menubar
Ensure SwiftBar is running and plugin directory is set
确保SwiftBar正在运行且插件目录已正确设置
SwiftBar → Preferences → Plugin folder should point to ~/Library/Application Support/SwiftBar/Plugins/
SwiftBar → 偏好设置 → 插件文件夹应指向~/Library/Application Support/SwiftBar/Plugins/
undefinedundefinedDouble-counted costs
成本重复统计
CodeBurn deduplicates by API message ID automatically. If you see unexpectedly high numbers, check for duplicate JSONL files:
bash
undefinedCodeBurn会自动通过API消息ID去重。如果看到异常高的数值,请检查是否存在重复的JSONL文件:
bash
undefinedList all session files sorted by size
按大小排序列出所有会话文件
find ~/.claude/projects/ -name "*.jsonl" | xargs wc -l | sort -rn | head -20
undefinedfind ~/.claude/projects/ -name "*.jsonl" | xargs wc -l | sort -rn | head -20
undefinedTUI rendering issues
TUI渲染问题
bash
undefinedbash
undefinedEnsure terminal supports 256 colors
确保终端支持256色
echo $TERM
echo $TERM
Should be xterm-256color or similar
应为xterm-256color或类似值
Force color mode
强制色彩模式
COLORTERM=truecolor codeburn
undefinedCOLORTERM=truecolor codeburn
undefined