Persistent provider-reported token usage totals with per-session, per-model, and daily activity statistics.
Install
# from npm (prebuilt)
dsh plugin --profile web add dsh-token-usage-counter
# from GitHub (first run asks for allowBuilds approval — follow the hint, retry)
dsh plugin --profile web add github:Mu-scorpio/token-usage-counter
Any plugin you install runs third-party code with your own permissions — it can read your files, use your credentials, and reach the network, and tool approvals don’t sandbox it. GitHub-sourced plugins also run build scripts at install time — pnpm blocks those until you allow them, so an install can stop with ERR_PNPM_GIT_DEP_PREPARE_NOT_ALLOWED or ERR_PNPM_IGNORED_BUILDS; dsh prints the exact key to add under allowBuilds in your profile’s pnpm-workspace.yaml, and the install works on the next run. Allowing a build is a trust decision: only install sources you trust, and pin a commit (github:owner/repo#sha).
README
Persistent provider-reported token usage statistics for DeepSeek Harness. The plugin keeps uncached input, cache read, cache write, and output usage in separate buckets, and exposes cumulative, daily, per-session, and per-model views.
Features
| Capability | Description |
|---|---|
| Accurate buckets | Keeps the four provider-reported usage buckets separate. |
| Persistent totals | Stores data in the plugin-owned dsh-token-usage-counter settings namespace. |
| Multiple views | Provides global, session, and provider/model summaries. |
| Daily activity | Tracks local-day token totals and call counts. |
| Built-in settings page | Ships its own Web settings view and heatmap. |
| Safe commits | Counts usage only after a successful completion anchor. |
| Interactive command | Registers /tokens when the commands service is mounted. |
Install
Install the published DSH Bundle into the web profile:
dsh plugin --profile web add -w dsh-token-usage-counter
dsh web
The Bundle is additive: it mounts only the plugin-owned token-usage-counter entry and leaves the built-in usage accumulator and page enabled.
Version 0.4.0 moves persistence from the shared usage-stats namespace to the plugin-owned dsh-token-usage-counter namespace. Existing 0.3.x totals are not silently migrated because the shared namespace belongs to the built-in plugin; the new counter starts with an independent snapshot after the upgrade.
Local development
From this checkout:
dsh web --patch ./cordis.yml
The local overlay mounts src/index.ts without replacing built-in components. For a manual composition, add only the plugin-owned entry:
- insert:
- id: token-usage-counter
name: './src/index.ts'
Compatibility
- Node.js: 22.13.0 or newer.
- DSH: 0.1.2-alpha.3–0.1.2-alpha.5, 0.1.5-alpha.2, and 0.1.6-alpha.1 have profile or UI checks; intervening releases are explicitly unknown.
- Profile: web.
- Exact per-release results and disposable-profile evidence are recorded in docs/VERIFICATION.md.
Store listing migration details: docs/STORE-REMEDIATION.md.
Build
npm install --ignore-scripts --legacy-peer-deps --no-package-lock
npm run build
npm run verify
The generated host and client bundles are committed under lib.
Counting rules
The plugin listens to the durable session event stream:
- assistant/message.usage is counted once.
- compaction/summary.usage is counted as one provider call.
- A usage-only assistant/chunk is held until its matching assistant/message.
- When a chunk and final message describe the same turn and step, the final value replaces the early sample.
- Failed requests, retries, and fork seed history are not counted twice.
API
The plugin provides ctx.tokenUsageCounter:
ctx.tokenUsageCounter.getSummary()
ctx.tokenUsageCounter.getSession(sessionId)
ctx.tokenUsageCounter.getModel(provider, model)
ctx.tokenUsageCounter.formatSummary()
Links
- npm: https://www.npmjs.com/package/dsh-token-usage-counter
- GitHub: https://github.com/Mu-scorpio/token-usage-counter
- DSH Bundle documentation: https://github.com/deepseek-ai/deepseek-harness/blob/master/docs/user/develop/basic/publish.md
License
MIT
Links
More in this category
bowenliang123/dsh-context★ 1573
DSH context insight panel: Context dashboard + /context command + Context browser — one-stop context lifecycle management with categorized composition, content details, evolution trends, compaction/injection events, and stats.
Han-1413141/dsh-cost-meter★ 349
Per-session and daily API cost, budget with usage %, official balance, history dashboard, and one-click official price sync with peak/off-peak pricing.
wssfk12138/dsh-damage-pulse★ 224
Tracks DeepSeek token usage, per-call and session costs, and account balance with cache-aware charge animations in the DSH Web UI.
zh667/TokenLedger★ 202
Sidebar usage panel that attributes tokens to the relay site that served each request, read from your existing provider config: today/month/all-time totals, per-site and per-model breakdowns, a year activity heatmap, and New API / Sub2API / DeepSeek balances.
Ychris12138/dsh-usage-stats★ 169
Multi-provider usage dashboard with provider/model token breakdowns, calendar drill-downs, account balances, and OpenCode Go / Z.ai subscription quota tracking.
PolinniZhong/dsh-personal-center★ 120
Personal center for DeepSeek Harness: cross-session usage statistics, per-model cost estimation, global custom instructions, a global font-size adjuster, a data-driven desktop pet with bitmap & vector skins, and a conversation status overview, all local and offline.
Community comments
Comments are public GitHub Discussions. Loading them connects to GitHub and Giscus; a GitHub account is required to post.