DeepSeek Harness Plugin

xchannel1987/dsh-token-usage-xc

Stars ★ 0 Downloads (30d) 149 Category Usage & Billing Added 2026-08-30 npm dsh-token-usage-xc

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

中文 | English

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 use sessionQuery to 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

  1. Open DSH Settings
  2. Find "Today's Token Usage" section
  3. View per-model breakdown

View 7-Day Trend

  1. Click "Trend" tab in usage panel
  2. View stacked bar chart
  3. Click dates for details

Enable Header Badge

  1. Enable "Show today's total tokens in conversation header" in settings
  2. Today's total appears in conversation header
  3. 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

MIT

🔗 Links

Content from the project README on GitHub ↗

Links

More in this category

View the whole category →

Community comments

Comments are public GitHub Discussions. Loading them connects to GitHub and Giscus; a GitHub account is required to post.