dsh-agent-token-stats: Cross-Agent Local Token Usage Dashboard

Introduction

When running Claude Code, OpenCode, Cursor, or DSH itself within DSH (DeepSeek Harness), each tool tends to maintain its own logs, with tokens and costs scattered across different directories. Answering questions like “how much was spent this Monday, what is the cache hit rate, which session was the most expensive” usually requires manually checking multiple applications or scripts to aggregate, and once source logs are deleted, aligning historical data becomes very difficult.

The community plugin dsh-agent-token-stats (maintainer skyzhao1223, category: client) addresses this: it scans conversation logs from multiple local AI tools into a persistent ledger and provides a unified analytics panel in the DSH web sidebar. The DeepSeek Harness ecosystem adopts an “everything is a plugin” philosophy; the plugin directory is showcased on community sites such as SkillHub, and has no official affiliation with DeepSeek / Hunyuan.

What Is This

dsh-agent-token-stats is a cross-Agent local LLM token usage dashboard for the DSH web profile. The Host side performs incremental scanning and ledger merging, while the Client side renders charts and tables in the web GUI sidebar (and main-slot dashboard); data is stored locally in ~/.agent-token-stats/.

The current npm package version is 1.2.0 (see package.json in the repository), licensed under MIT, requiring DSH >= 0.1.5-rc.

Core Features

Data Sources & Persistence

The plugin performs incremental scanning by signature, aggregating conversation logs into ~/.agent-token-stats/ledger.json: it performs ratchet merging by “source × model × day”, so rescanning does not double-count; history in the ledger is preserved even after source logs are deleted.

Primary sources listed in the README include: Claude Code, WPS Claude, OpenCode, DSH, OpenClaw, QClaw, CodeWhale, WorkBuddy, Cursor IDE, Hermes; additional parsers for Codex CLI, Gemini CLI, Cline/Roo, Pi, etc., as well as probes for Trae / Lingma / CodeGeeX / Comate / Ollama / AionUi / Copilot.

Metrics & Views

  • Metrics: breakdown of input / output / reasoning / cache read / cache write, cache hit rate, request count; reported cost and estimated cost are listed separately (with an internal reference price table, not mixed).
  • Views: overview cards with period-over-period comparison, vendor and prompt composition donut charts (hover, click to filter), stacked trend charts (hover, click to drill into a day), activity heatmap, model detail table (sort / search / daily sparkline / totals row), period comparison, Agent comparison, session browser, source status and schema drift alerts.
  • Export: weekly / monthly Markdown report downloads; CSV export to ~/.agent-token-stats/export-*.csv.
  • UX: skeleton first screen, scanning bar showing current snapshot from the ledger, “updated N minutes ago” relative time; auto-refresh every 2 minutes; cold start opens instantly (milliseconds) from Host memory or disk ledger first, then rescans in the background with per-source cooldowns.
  • i18n: Chinese / English switching; some keyboard shortcuts (e.g., / to focus model search, Esc to clear level-by-level) and accessible tab structure are documented in the README.

Optional Configuration

All configuration directories are ~/.agent-token-stats/, all optional:

File Purpose
config.json Budget alerts, e.g., dailyTokens / monthlyTokens / dailyCost / monthlyCost; cost thresholds are interpreted in the display currency from pricing.json
pricing.json Custom unit price rules and display currency (display, unit, fx, rules, etc., see README “Pricing & currency”)
quota.json API keys for DeepSeek / Kimi etc. balance queries (also can use environment variables DEEPSEEK_API_KEY / MOONSHOT_API_KEY)

Price matching uses lowercase substring matching, first match wins; when no rule matches, the estimate is 0, and the panel shows 0/— without guessing.

Architecture Overview

A single bundle with two entry points: Host (lib/index.js, injects shell + webServer, provides GET /agent-token-stats/{data,export,sessions,report,quota}, loopback with Origin verification) and Client (lib/client.js, dsh.client web bundle, pure React.createElement, no separate build step needed for UI changes).

Installation & Activation

The system must have sqlite3, jq, zstd installed (on macOS, brew install zstd). Run the official installation command under the DSH web profile:

dsh plugin --profile web add dsh-agent-token-stats   # from npm
# or: dsh plugin --profile web add github:skyzhao1223/dsh-agent-token-stats
# then restart: dsh web

After installation, restart dsh web, then open the token statistics panel from the web GUI sidebar. For maintenance upgrades: after modifying source code or pulling a new version, run dsh plugin --profile web update dsh-agent-token-stats, then restart dsh web.

Typical Usage

  1. Zero-config browsing: After installation and restart, the panel first shows an existing ledger snapshot, then scans logs from various sources in the background; check totals and cache hits on the overview, and narrow down using time range, source chip, vendor and model filters.
  2. Daily drill-down: Click a day on the trend chart or heatmap to view that day’s details; the session browser lets you browse sessions individually (the page notes that filters do not apply here, to avoid misuse).
  3. Cost comparison: Compare each model’s “reported cost” with the “estimated cost” computed from pricing.json / the internal table; for gateway resales or non-standard models, you can add detailed pat entries in the rules of pricing.json.
  4. Budget & balance: Set thresholds in config.json; configure keys in quota.json or environment variables to use quota-related features (see the Host route quota).
  5. Export & archive: Download weekly / monthly Markdown reports from the panel, or export CSV to the configuration directory.

For development self-testing, refer to scripts like node scripts/smoke.mjs, verify-instant-open.mjs in the repository (see the README Development section).

Use Cases & Notes

Suitable for: DSH web users who use multiple Agent IDE / CLI tools in parallel on the same development machine, want to view token, cache, and cost trends unified locally, and wish to retain historical ledgers even after source logs are deleted.

Notes:

  • The plugin reads local log paths with the current DSH process user and permissions; before installation, you should review the source code and MIT license on GitHub, and confirm you accept its scanning scope.
  • Estimated costs depend on price rules and the internal reference table, which may not match vendor bills; reported and estimated values are always listed separately.
  • The Host requires DSH >= 0.1.5-rc; dependencies sqlite3, jq, zstd must be available in PATH.
  • Community directory page metadata such as star counts may change; features and commands are based on the GitHub README.

Conclusion

dsh-agent-token-stats consolidates multiple local log sources such as Claude Code, OpenCode, Cursor, and DSH into a single ratchet ledger, providing cache, cost, and drill-down analytics in the DSH web sidebar, making it suitable for developers who need cross-Agent usage visualization.

羽毛球分组比赛记分
小程序二维码

欢迎使用《羽毛球分组比赛记分》微信小程序

Xiaoye