跨 Agent 的 token 用量看板:聚合 Claude Code、OpenCode、Cursor、DSH、OpenClaw、CodeWhale、Hermes 等本地对话日志,台账持久化(删除聊天记录后历史仍留存),提供缓存命中率、成本估算、环比对比与当日下钻分析的侧边栏面板。
安装
# GitHub 源码(首次需按提示配置 allowBuilds 构建授权后重试)
dsh plugin --profile web add github:skyzhao1223/dsh-agent-token-stats
装任何插件都等于在你的机器上跑第三方代码,权限和你本人一样大——能读你的文件、用你的凭据、访问网络,工具审批管不到它。GitHub 来源的插件还会在安装时执行构建脚本——pnpm 默认拦截,所以安装可能停在 ERR_PNPM_GIT_DEP_PREPARE_NOT_ALLOWED 或 ERR_PNPM_IGNORED_BUILDS;dsh 会打印出需要添加的确切键名,把它加进该 profile 的 pnpm-workspace.yaml 的 allowBuilds 下,重跑一次即可装上。放行构建本身就是一次信任判断:请只安装可信来源,并尽量锁定 commit(github:owner/repo#sha)。
README
Cross-agent local LLM token usage dashboard for DeepSeek Harness (web profile). 跨 Agent 的本地 token 用量看板。
Aggregates local conversation logs from Claude Code, WPS Claude, OpenCode, DSH, OpenClaw, QClaw, CodeWhale, WorkBuddy, Cursor IDE and Hermes (with Codex CLI, Gemini CLI, Cline/Roo and Pi parsers on standby, plus detection-only probes for Trae / Lingma / CodeGeeX / Comate / Ollama / AionUi / Copilot) into a persistent ratchet ledger, and renders a full analytics panel in the DSH web GUI sidebar.
聚合本机 10+ 个 AI 工具的对话日志到持久化台账(源日志删除后历史仍保留),在 DSH web 侧边栏提供完整分析面板。
Install
dsh plugin --profile web add github:skyzhao1223/dsh-agent-token-stats
# npm publishing planned: dsh plugin --profile web add dsh-agent-token-stats
# then restart: dsh web
Requires system sqlite3, jq, and zstd (macOS: brew install zstd). Host: DSH >= 0.1.5-rc.
Screenshots



Features
- Metrics: input / output / reasoning / cache read / cache write split, cache-hit rate, request counts, reported cost vs. estimated cost (built-in reference price list, never mixed)
- Views: overview cards with period-over-period deltas, vendor & prompt-composition donuts (hover + click-to-filter), stacked trend chart (hover tooltip + click day drill-down), activity heatmap (click drill-down), model detail table (sort / search / expand daily sparkline / totals footer), period comparison, agent comparison, session explorer, source status with schema-drift sentinel
- Persistence:
~/.agent-token-stats/ledger.json— ratchet-merged per source × model × day; rescans never double-count; history survives source-log deletion - Reports: weekly / monthly Markdown download; CSV export
- Sticky toolbar: source chips, time range, vendor select, model search, active-filter summary with one-click clear; on the Sessions/Sources tabs it explains that filters do not apply there instead of showing dead controls
- Loading & freshness: real skeleton first paint, a scanning strip that says the ledger snapshot is showing, and a relative "updated N minutes ago" clock (auto-refresh is silent, so the button never flickers)
- Keyboard:
/focuses model search (Cmd/Ctrl/Alt + /stays with the browser),Escdismisses the toast → clears search → closes the day drill-down, and it only touches the model filter when this plugin's own search box has focus; tabs are a realtablist/tabpanelpair with ←/→/Home/End and:focus-visiblerings;prefers-reduced-motionis honoured. Heatmap cells, bar rows, legend entries and table rows/headers stay mouse-only by design — making ~180 heat cells tabbable would be worse than leaving them out. - i18n: 中文 / English toggle
- Auto-refresh every 2 minutes; instant open — the panel is answered from the host's in-memory result (or the ledger on a cold start) in milliseconds, while rescans run in the background with per-source cooldowns
Configuration (all optional, all in ~/.agent-token-stats/)
| File | Purpose |
|---|---|
config.json |
{"budgets":{"dailyTokens":0,"monthlyTokens":0,"dailyCost":0,"monthlyCost":0}} — budget alert thresholds;cost 阈值按展示币种解读(即 pricing.json 的 display) |
pricing.json |
价目与展示币种,见下方「Pricing & currency」 |
quota.json |
{"deepseek":{"apiKey":"sk-..."},"kimi":{"apiKey":"..."}} — balance queries (env DEEPSEEK_API_KEY / MOONSHOT_API_KEY also work) |
export-*.csv |
CSV exports land here |
Pricing & currency
~/.agent-token-stats/pricing.json(全部可选):
{
"display": "CNY", // 面板/报告/CSV 的展示币种;省略 = 跟 unit
"unit": "USD", // 你写的 rules 数字用的币种;省略 = USD
"fx": 7.2, // 1 USD = 7.2 display,仅在两者不同时用于换算;缺 fx 时原样展示并在面板提示
"rules": [ // 可选:优先于内置表匹配,细分 pattern 要先写
{ "pat": "deepseek-v4.1-flash", "i": 0.28, "o": 0.42, "cr": 0.028, "cw": 0.28, "rt": 0.42 },
{ "pat": "wps-gateway/model", "i": 2, "o": 8, "cr": 0.2, "unit": "CNY" } // 单条规则可自带币种
]
}
- 单价字段:
i输入(缓存未命中)、o输出、cr缓存读(命中)、cw缓存写、rt推理(省略或 ≤0 时按输出价)。 - 估算 =
(输入×i + 输出×o + 缓存读×cr + 缓存写×cw + 推理×rt) / 1e6,再按需要换算到display。 - 匹配是小写子串 + 先命中先用,所以
claude-opus必须写在claude之前、细分模型行写在兜底行之前。 - 上报费用(OpenCode 的 cost、CodeWhale 的
*_usd、Cursor 的 API 价折算)按定义是美元,展示时同样按fx换算;上报与估算永远分列、不混算。 - 未命中任何规则 = 0(不猜),面板显示 0/—。
- 内置表默认是 USD 参考价,DeepSeek 有分档行(
deepseek-v4.1-flash/deepseek-v4-flash/deepseek-reasoner/ 兜底deepseek),网关转售价请用上面的rules覆盖。
Architecture
One bundle row, two halves:
- Host (
lib/index.js, injectsshell+webServer): signature-based incremental scanners, ledger, pricing, and routesGET /agent-token-stats/{data,export,sessions,report,quota}(loopback, Origin-checked) - Client (
lib/client.js,dsh.clientweb bundle): sidebar panel + main-slot dashboard, plainReact.createElement, no build step needed for edits
Development
node --check lib/index.js && node --check lib/client.js
node scripts/smoke.mjs
node scripts/verify-cold-snapshot.mjs # 秒级:冷启动首屏必须来自磁盘台账且字段同构
node scripts/verify-instant-open.mjs # 真实 HOME:冷/热/手动刷新都必须瞬时返回(后台扫描约 2 分钟)
node scripts/verify-cooldown.mjs # fixture HOME:冷却期内不重扫、冷却后补扫不丢数(~90s)
node scripts/verify-pricing.mjs # 秒级:币种/fx 换算、规则币种、细分优先、推理计费、缺 fx 告警
node scripts/verify-ux.mjs # 秒级:客户端结构级回归(骨架/筛选器适用范围/下钻/toast/键盘/a11y/token 白名单)
verify-ux.mjs用自带的最小 React 垫片把 Dashboard 真渲染一遍再断言结构,所以它验证的是结构与交互,不是视觉效果——配色、间距、真实对比度仍需在浏览器里人工确认。可用LTS_CLIENT=./some-copy.js node scripts/verify-ux.mjs指向变异副本,确认「把功能删掉断言真的会挂」。
Maintenance: edit source → dsh plugin --profile web update dsh-agent-token-stats → restart dsh web.
MIT © skyzhao1223
链接
同类插件
bowenliang123/dsh-context★ 4440
DSH 上下文洞察面板:Context 仪表盘 + /context命令 + Context 浏览器,查看 Context的分类组成、内容详情、演进趋势、压缩/注入事件、统计等一站式 Context 全生命周期管理。
Han-1413141/dsh-cost-meter★ 642
会话与当日 API 费用统计、预算图框(已用%)、官方余额、历史看板,支持峰谷计价与官方价格一键同步。
wssfk12138/dsh-damage-pulse★ 288
在 DSH Web 界面追踪 DeepSeek Token 用量、单次与会话费用及账户余额,并显示缓存感知的扣费动画。
zh667/TokenLedger★ 201
侧边栏用量面板:把 Token 归属到实际服务该请求的中转站,站点从已有的 provider 配置中读出,无需额外配置;含今日/本月/累计三窗口、按站点与模型下钻、一年活跃度热力图,以及 New API / Sub2API / DeepSeek 余额。
Ychris12138/dsh-usage-stats★ 188
多供应商用量看板:按供应商/模型统计 Token 与日期下钻,统一展示账户余额,并追踪 OpenCode Go / Z.ai 订阅额度。
PolinniZhong/dsh-personal-center★ 115
DeepSeek Harness 个人中心:跨会话用量统计(按供应商/模型分别统计,自动读取已配置模型)、按模型成本估算、全局自定义指令、数据驱动的桌面宠物(位图/矢量皮肤)与会话状态概览,纯本地离线运行。
社区评论
评论公开保存在 GitHub Discussions。加载评论会连接 GitHub 和 Giscus;发表内容需要 GitHub 账号。