Token usage statistics plugin for DeepSeek Harness - today's token consumption by model, cache hit rate, 7-day trend chart, optional header badge, persistent storage with auto cleanup.
Install
# from npm (prebuilt)
dsh plugin --profile web add dsh-token-usage-xc
# from GitHub (first run asks for allowBuilds approval — follow the hint, retry)
dsh plugin --profile web add github:xchannel1987/dsh-token-usage-xc
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
DSH Token Usage Statistics Plugin — Real-time tracking of today's and last 7 days' token consumption, bucketed by model with cache hit rate analysis and trend charts.
✨ Core Features
📊 Today's Token Usage
New "Today's Token Usage" section in settings page showing:
- Per-Model Statistics: Input/Output/Cache Read/Cache Write tokens
- Cache Hit Rate:
cacheRead / (uncachedInput + cacheRead) × 100% - Request Count: API calls per model
- Daily Total: Aggregated data across all models
📈 7-Day Trend Chart
- Stacked Bar Chart: 7-day usage trend with model-colored segments
- Date Navigation: View any historical date
- Model Filter: Select specific models to display
🔔 Header Badge (Optional)
- Real-time Display: Shows today's total tokens in conversation header
- Click to Expand: Click badge for detailed breakdown
- Compact Format: K/M/B notation with hover for exact values
💾 Data Persistence
- Daily Storage:
~/.dsh/storages/dsh-token-usage-xc/<YYYY-MM-DD>.json - Restart Resilient: Data auto-recovers after restart
- Auto Cleanup: 7-day automatic cleanup of old data
- Startup Backfill: Backfills usage before plugin loaded today
🔧 Data Sources
| Source | Description |
|---|---|
| session/event | Listen to assistant/message event's usage field |
| Model Attribution | Read event's message.source.model directly |
| Session Watermark | Dedupe by seq to avoid double counting |
Why not parse session.jsonl.zstd directly?
The file is multi-zstd-frame concatenated, requiring frame boundary scanning like the persistence backend. Plugins usesessionQueryto avoid reimplementing this complex logic.
📦 Installation
# Using DSH CLI
dsh plugin --profile web add dsh-token-usage-xc
# Or using npm
npm install dsh-token-usage-xc
Restart DSH after installation. You'll see a new "Today's Token Usage" section in settings.
⚙️ Configuration
| Option | Default | Description |
|---|---|---|
| enabled | true | Enable statistics |
| refreshIntervalSec | 60 | Frontend refresh interval (10-3600s) |
| backfill | true | Backfill today's usage on startup |
| headerBadge | false | Show total token badge in conversation header |
🎮 Usage
View Today's Usage
- Open DSH Settings
- Find "Today's Token Usage" section
- View per-model breakdown
View 7-Day Trend
- Click "Trend" tab in usage panel
- View stacked bar chart
- Click dates for details
Enable Header Badge
- Enable "Show today's total tokens in conversation header" in settings
- Today's total appears in conversation header
- Click badge for quick details
🔌 Data Interface
RPC endpoints for other plugins:
// POST /dsh-token-usage-xc/today
{
available: boolean;
date: string; // 'YYYY-MM-DD'
totalTokens: number;
requests: number;
models: {
model: string;
modelName: string | null;
provider: string;
uncachedInputTokens: number;
outputTokens: number;
cacheReadTokens: number;
cacheWriteTokens: number;
totalTokens: number;
requests: number;
}[];
}
// POST /dsh-token-usage-xc/last7days
// Returns last 7 days' aggregated data
📐 Statistics Methodology
- Total Tokens = uncachedInput + cacheRead + cacheWrite + output
- Cache Hit Rate = cacheRead / (uncachedInput + cacheRead) × 100%
- Final Usage Only: Each assistant/message has exactly one usage, naturally deduped
- Event Time Bucketing: Bucketed to YYYY-MM-DD based on event.time
📄 License
🔗 Links
Links
More in this category
bowenliang123/dsh-context★ 1192
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★ 232
Per-session and daily API cost, budget with usage %, official balance, history dashboard, and one-click official price sync with peak/off-peak pricing.
zh667/TokenLedger★ 190
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.
wssfk12138/dsh-damage-pulse★ 145
Tracks DeepSeek token usage, per-call and session costs, and account balance with cache-aware charge animations in the DSH Web UI.
Ychris12138/dsh-usage-stats★ 132
Multi-provider usage dashboard with provider/model token breakdowns, calendar drill-downs, account balances, and OpenCode Go / Z.ai subscription quota tracking.
feibi-mochi/deepseek-harness-control-center★ 66
DeepSeek Harness control center for official balance monitoring, per-session costs and tokens, third-party token totals, completion alerts, official recharge, flexible layouts, and agent-assisted session controls.
Community comments
Comments are public GitHub Discussions. Loading them connects to GitHub and Giscus; a GitHub account is required to post.