Skip to main content
S

dsh-usage-stats

slaslin/dsh-usage-stats

Adds a Usage tab that merges DeepSeek Harness, Codex CLI and Claude Code logs into per-request tokens, cache hit, estimated cost, speed and first-token time, with provider quota, range/provider/model filters and a daily models.dev price sync. Its HTTP routes have no DSH access check, so a web page open in your browser could call them.

Install

dsh plugin --profile web add github:slaslin/dsh-usage-stats

README

dsh-usage-stats

npm license

Usage statistics for DeepSeek Harness — a 用量 / Usage tab beside the conversation views that puts Harness, Codex CLI and Claude Code in one ledger: per-request tokens, cache hit, estimated cost, output speed, first-token time, provider quota, and a trend you can filter by range, provider and model.

中文说明见下方「中文」一节。

overview

What you get

  • Six KPI cards — today's spend, last 24 hours, the selected range's cost, requests, tokens and cache-hit rate.
  • Provider quota — the same windows CC Switch shows (5 h / week / month with reset countdowns), read from each provider's own usage endpoint.
  • Smooth trend chart — tokens / requests / cost, hourly when the range is a day or less, daily otherwise, with a hover readout.
  • Filters — 今天 / 近 24 小时 / 近 7 天 / 近 30 天 / 全部, a custom date range, source (Harness / Codex / Claude Code), provider and model.
  • Request log — time, app, model, provider, new input, output, cache read, hit rate, cost, speed, first token, total time.

Where the data comes from

SourcePathUsage surface
DeepSeek Harness~/.dsh/sessions (session-persistence seam)assistant/message.usage
Codex CLI~/.codex/sessions/**/*.jsonl[.zst]token_usage_record.usage / event_msg:token_count
Claude Code~/.claude/projects/**/*.jsonlassistant.message.usage

The provider column is the route a call actually went through, not the model vendor: the Harness route id (opencode-go), the Codex base_url host (127.0.0.1:15721 → 本地代理), the Claude ANTHROPIC_BASE_URL host (linkai.pics → LinkAI). Label them in providers[].routes / providerHosts; a call with no route shows as 未标注 instead of being credited to the model vendor. Prices sync from models.dev once a day, and an explicit pricing entry overrides list price for the route that charges something else.

Everything is read-only. Parsed per-file digests are cached by size + mtime in ~/.dsh/usage-stats/ledger.json, so rescans only touch changed files; the cold scan of this machine's ~0.9 GB of logs takes a few seconds.

Install

dsh plugin add @tian12317/dsh-usage-stats

Or from the repository, which links the checkout so a git pull is enough:

Plugins → Add plugin → pick the repository directory

The bundle registers one Host row (webServer + sessionPersistence + credentials) and one Web tab; no restart is needed after the page reloads.

Configuration

cordis.patch.yml in the profile (survives upgrades):

- id: dsh-usage-stats
  config:
    refreshSeconds: 180      # minimum interval between scans
    maxSteps: 400            # rows sent to the browser
    pricing:                 # CNY per 1M tokens: miss input / cached input / output
      deepseek: { in: 2, cacheRead: 0.2, out: 8 }
    providers:               # quota probes, one per upstream
      - id: opencode-go
        label: OpenCode Go
        endpoint: https://opencode.ai/zen/go/v1/usage
        apiKeyRef: OPENCODE_GO_API_KEY

Any provider that answers { usage: { rolling, weekly, monthly } } with { percent, resetsAt } works — point endpoint at a relay's usage route and give it a credential reference, and its quota joins the strip.

Cost is an estimate

Prices default to a small family table (DeepSeek, Claude, GPT, o-series) in CNY per 1M tokens; override any family through pricing. The Claude rows were fitted from Claude Code's own cost-state snapshots. Subscription plans are still priced per token here, so treat the number as a comparison, not a bill.

中文

在会话视图里新增「用量」标签页:把 Harness、Codex CLI、Claude Code 三家的 每次请求合成一张账——token、缓存命中、估算成本、输出速度、首字耗时,外加供应商额度 和可按时间/供应商/模型筛选的趋势图。

  • 卡片:今日消耗、近 24 小时、区间总成本、请求数、Tokens、缓存命中率
  • 额度:5 小时 / 本周 / 本月剩余百分比与重置倒计时(读供应商自己的 usage 接口)
  • 趋势:Tokens / 请求 / 成本三种口径,一天内按小时、更长按天,悬停看数值
  • 筛选:今天 / 近 24 小时 / 近 7 天 / 近 30 天 / 全部、自定义日期、来源、供应商、模型
  • 请求日志:时间、应用、模型、供应商、新增输入、输出、缓存命中、命中率、成本、速度、首字、总耗时

安装:dsh plugin add dsh-usage-stats,或在「插件 → 添加插件」里选本仓库目录。

License

MIT

Related plugins