dsh-token-usage: Viewing Token Usage by Model and Day in DSH Settings

# Preface

DeepSeek Harness (DSH) writes session logs into `~/.dsh/sessions`, and account balances are visible on the account page. However, aggregating "how much input/output/cache was consumed per model per day" directly from JSONL files is a high-cost effort. Below, we introduce the community plugin **dsh-token-usage** (maintainer: GIN0076, GitHub: [GIN0076/dsh-token-usage](https://github.com/GIN0076/dsh-token-usage)). It provides daily, weekly, and monthly statistics and charts using local data within **Settings → Token Usage**, supports optional cost estimation via a price list, and keeps all data local without leaving the machine.

# What Is This

**dsh-token-usage** is a **client-side** plugin for DSH (Cordis bundle name `@local/token-usage`, current documentation version **1.3.0**, MIT License). It adds a Token usage dashboard to the settings panel: it aggregates tokens by **provider/model**, supports switching between **Day / Week / Month** and custom time ranges, and provides line charts, horizontal ranking bars, and summary cards. The charts are **pure SVG with zero additional dependencies**. The statistical data comes from read-only scanning of session logs. It operates on a local-first principle and does not have any built-in unit prices.

# Core Features

## Time Granularity & Range

- **Day / Week / Month**: Weeks start on Monday, and months are calendar months. The underlying storage uses only "per-day" buckets, allowing instant switching between granularities without re-scanning the disk.
- Preset ranges (e.g., last 7/30 days, 12 weeks, 12 months, All) and custom start/end dates.
- Summary cards and leaderboards reflect the **entire currently selected interval**; what changes with granularity are the line chart grouping and the **Buckets** cards.

## Charts & Rankings

- **Line Chart**: A thick line represents the total, while thin lines represent individual models. Hovering with a crosshair reveals daily details, and the legend allows toggling model visibility.
- **Horizontal Bar Chart**: Displays model share and (when configured) cost. It can switch between **By model / By provider** views, and rankings can be sorted by cost.

## Metric Cards

Totals, input, output, cache read, cache write, reasoning, **cache hit rate**, call count, and model count, etc. When a price list and budget are configured, **Cost**, **Today**, **This month**, and **Budget** cards also appear (the Budget card turns red when the budget is exceeded).

## Cost Estimation (Optional)

The plugin **does not have built-in unit prices**. Prices are edited in the panel's **Prices** section and written to `~/.dsh/token-usage-prices.json` (atomic write). The unit is price **per million tokens**; `currency` defaults to ¥; model keys are the `provider/model` strings as they appear in the panel.

Example structure (from README):
```json
{
  "currency": "$",
  "models": {
    "deepseek-account/deepseek-flash": { "input": 1, "output": 2, "cacheRead": 0.1, "cacheWrite": 1 }
  },
  "default": { "input": 1, "output": 2 }
}

Models without a set price are tallied separately and flagged in the panel; they are not silently recorded as 0. Clearing and saving hides the costs again. Costs are only estimates; refer to provider bills for actual charges.

Configuration, Export & Refresh

  • Settings (corresponds to ~/.dsh/token-usage-config.json): For refresh intervals, budgets, data retention, etc.
  • Export: Exports the current range as CSV or JSON (including bucket × model rows, subtotals, and totals). Supports copying and downloading.
  • Silent refresh every 60s when the tab is visible; refreshes immediately when returning to the tab; no requests are made when the tab is hidden.
  • Rebuild: Performs a full rescan in one click. It uses a watermark to avoid double counting. If the local store still contains history corresponding to deleted sessions, it will prompt for confirmation first (that portion cannot be rebuilt).

Statistics Methodology (Documentation Summary)

The host side performs live folding and startup backfilling from session logs. Dirty counts fail closed. Compaction summaries are attributed to their respective provider/model. Fork inheritance avoids double counting.

Installation & Enabling

The standard channel for DSH is installation from GitHub (Desktop users must use the desktop profile; do not use the outdated --profile web):

# desktop app (the profile actually loaded by the packaged client)
dsh plugin --profile desktop add github:GIN0076/dsh-token-usage
# or omit --profile to act on the current default profile
dsh plugin add github:GIN0076/dsh-token-usage

After installation, hard refresh the page (Ctrl+Shift+R) and open Settings → Token Usage.

To uninstall (as per README): plugin_manager remove_bundle → @local/token-usage. There are no host-side remnants, but the data directory can be kept or deleted manually.

Typical Usage

  1. Install using the command above and hard refresh, then go to Settings → Token Usage.
  2. Use the top Day | Week | Month toggle and time range presets (or custom dates) to view line charts and Buckets.
  3. For costs and Budget: Click Prices to fill in token-usage-prices.json; set a budget in Settings (optional).
  4. To compare model consumption: Switch between By model / By provider in the ranking area. If unit prices are set, By cost is available.
  5. For offline analysis: Select the desired range and Export as CSV/JSON.
  6. If logs have changed but numbers seem off: Click Rebuild. If prompted that historical session files no longer exist, confirm as instructed before rebuilding.

Use Cases & Caveats

Suitable for: Developers who run multiple models and providers on DSH long-term and want a quick local view of token structure and cache share, with optional cost estimation and budget control based on their own pricing.

Note:

  • The plugin reads ~/.dsh/sessions and writes configs/cache under ~/.dsh with the permissions of the current DSH process. Please review the repository source code and the MIT license before installing.
  • The community directory skillhub plugin page and GitHub are independent sources of information and have no official affiliation with DeepSeek / High-Flyer. Metadata such as star counts are subject to what is displayed on each site at the time (GitHub stars were 0 in the provided documentation).

Conclusion

dsh-token-usage transforms DSH session logs into an interactive local dashboard: daily storage with instant weekly/monthly aggregation, pure SVG charts, and optional pricing and budgets. Directory and source code:

  • https://www.skillhub.cn/plugins/GIN0076/dsh-token-usage
  • https://github.com/GIN0076/dsh-token-usage
    ```
羽毛球分组比赛记分
小程序二维码

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

Xiaoye