dsh-token-usage: Making Token Consumption a Visible Block Wall in DSH

Preface

When running agents in DSH (DeepSeek Harness), model calls happen constantly, but the session interface usually only cares about the current round of reply. To answer questions like “how many tokens were burned in total this month” or “which workspace and which model cost the most”, you typically have to dig through logs or rely on external bookkeeping, and the figures often don’t line up with the provider dashboard.

Below is the community plugin dsh-token-usage (maintainer: ChinRinhan, category: model inference). It reads the usage of each call from DSH session logs, aggregates them per day in the local timezone, and provides a block wall, a desktop pet, and a settings-page summary in the Web interface. Once installed, it can also backfill from historical sessions rather than starting from zero.

What Is This

dsh-token-usage is a Cordis bundle plugin for the DSH Web profile: a Token usage dashboard. Data comes from persisted session logs (usage on events such as assistant/message). The total is calculated as inputTokens + cacheReadTokens + cacheWriteTokens + outputTokens, which is a different definition from the totalTokens field reported by the provider; the plugin computes it itself using the formula above.

Core Features

Block Wall (Main Panel)

A block icon entry is added to the sidebar. Every 10M tokens fills one cell, with 100 cells per page (corresponding to 1 billion tokens per page); the cumulative count only grows. It supports a “Cumulative / Today” toggle (Today resets at midnight in the local timezone). Cells are distinguishable in three states: filled, currently filling, and empty; every 10 cells there is a milestone vertical line (100M tokens).

Desktop Pet

A small persistent panel in the bottom-right corner: the charging progress of the current block plus the number of full blocks accumulated (the pool). The title bar can be dragged to reposition, and the position is stored in localStorage. Clicking the title bar collapses it; the desktop pet is hidden when the viewport width is ≤768px. A subtle breathing animation appears when charging exceeds 90%, and it is disabled when the system has “Reduce Motion” enabled.

Usage Distribution

The same area can switch between three levels: workspace / model / vendor. The “model” view merges different spellings of the same model (e.g., with channel prefixes or -free suffixes), but different generations (e.g., deepseek-flash vs deepseek-v4.1-flash) are not merged. Unrecognized vendors are grouped as “other” and can be manually declared via the modelAliases config.

Settings Page and History

The “Token Usage” section of the settings page provides: three runtime toggles for the desktop pet, the block-wall panel, and the banner above the input box (applied immediately after changing); today and cumulative cards; range summary tables grouped by day / week / month / workspace / channel / model; and a diagnostics area (tracked session count, backfill status, storage paths, etc.).

On first launch, backfillOnStart is enabled by default: it scans the session logs under $DSH_HOME/sessions and backfills usage from before installation. Afterwards, every model call is recorded in real time.

HTTP API

Once enabled, the host registers four routes (by default on the same port as the Web GUI), for example:

Path Description
GET /dsh-token-usage/today Today, yesterday, cumulative, rate, current workspace/model, diagnostics, etc.
GET /dsh-token-usage/summary Range summary, supports various groupBy options
GET /dsh-token-usage/workspaces Workspace distribution
GET / PUT /dsh-token-usage/prefs Runtime toggles (the only writable endpoint)

Installation and Enabling

This plugin is distributed as a Cordis bundle for the DSH Web profile host. The official README provides two methods; do not invent dsh plugin add-style commands that do not appear in the documentation.

Method 1: Place it into the profile’s dependency directory

# <profile> is usually ~/.dsh/profiles/<name>
# Windows: %USERPROFILE%\.dsh\profiles\<name>
cd ~/.dsh/profiles/<profile>/node_modules
git clone https://github.com/ChinRinhan/dsh-token-usage.git

Then insert this bundle into the profile’s cordis.patch.yml (or use Method 2 and let DSH write it).

Method 2: Use DSH’s plugin management

Run the following in a DSH session:

plugin_manager  install_bundle  target=<local path or package name>
plugin_manager  set_bundle      target=dsh-token-usage  enabled=true

Verification

Replace <port> with your Web GUI port:

curl http://127.0.0.1:<port>/dsh-token-usage/today

A response shaped like {"ok":true,"totals":{...},"allTime":{...},...} indicates the routes are registered. In the interface you should see: the block icon in the sidebar, the desktop pet in the bottom-right corner, and the “Token Usage” section on the settings page.

Configuration Essentials

Override the plugin config in the profile’s cordis.patch.yml (upgrading the plugin will not wipe the config in the profile), for example:

- id: dsh-token-usage
  name: 'dsh-token-usage'
  config:
    keepDays: 400              # retention days (drop older daily keys on write)
    includeSubagents: true     # include subagent / team / workflow sub-sessions
    includeAuxiliary: true     # include auxiliary calls such as compression
    statusBarEnabled: true     # whether to show the banner above the input box
    statusBarRefreshMs: 1000   # polling interval, minimum 1000
    backfillOnStart: true      # backfill history on startup

    modelAliases:
      dfmodel:
        vendor: deepseek
        model: deepseek-v4.1-flash

Note the two layers of switches: config.statusBarEnabled lives in the Cordis config and requires a DSH restart after changing; the three toggles on the settings page are written to $DSH_HOME/token-usage/prefs.json and take effect immediately. Daily aggregated data lives in $DSH_HOME/token-usage/daily.json.

Typical Usage and Data Scope

  1. After installing and enabling via set_bundle, wait for the first backfill to complete (this may take a few seconds when there is a lot of data), then open the block wall to view the cumulative and today figures.
  2. Switch between workspace / model / vendor in the usage distribution to locate where usage concentrates; the current workspace and model are highlighted.
  3. For scripting or monitoring, poll GET /dsh-token-usage/today, or /summary with from / to / groupBy.
  4. On a dev machine you can use the repo’s node tools/usage-cli.mjs --sessions "$DSH_HOME/sessions" --group-by provider etc. to view grouped usage in the terminal (see the “Auxiliary tools” section of the README).

Known limitations (documented in the README): session/title-llm-request does not carry usage, so the cost of title generation cannot be recovered from logs; failed or interrupted calls without usage are not bucketed, and coverage can be seen in the settings-page diagnostics; two processes densely writing the daily aggregate concurrently may cause overwrites, though the impact is limited in the desktop single-process scenario.

Use Cases and Cautions

This suits developers who work long-term in the DSH Web, need to review token costs by project and by model, and want the numbers to share the same scope as the session logs. The block wall helps you perceive “how many 10M blocks have been accumulated”; the range table helps with reconciliation and weekly reports.

Before installing, please read the GitHub repository source code and MIT license yourself. The plugin runs with the current DSH process and profile and can read $DSH_HOME/sessions and session-related paths; Method 1 uses git clone into the profile’s node_modules, so please confirm the source is trusted. The DSH community plugin directory (e.g., SkillHub) is an independent ecosystem site and is not officially affiliated with DeepSeek / High-Flyer.

Conclusion

dsh-token-usage turns the usage in session logs into a daily-aggregated dashboard: a block wall, a desktop pet, distribution views, and a settings-page summary, with support for historical backfill and four HTTP routes. For installation steps and configuration fields, refer to the repository README.

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

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

Xiaoye