Preface¶
DeepSeek Harness (DSH) records token usage reported by the service provider under $DSH_HOME/sessions/ for each session. However, these are cumulative per-session fields and cannot directly answer questions like “how much was spent today” or “which models were used in the last week.” Furthermore, relying solely on on-the-fly scanning of session logs for aggregation presents other issues: clearing the sidebar, running dsh-session-cleanup, or manually deleting session directories essentially deletes logs. Historical usage figures drop accordingly, making the numbers unsuitable for accurate assessment.
dsh-usage-stats provides usage reports based on calendar windows within DSH settings and backs up the aggregated results of each session to a local ledger. After a session is deleted, its already-counted usage remains in the statistics. The following section covers its positioning, installation methods, and the boundaries of the metrics you should accept when using it.
What is this¶
- Package Name:
dsh-usage-stats(Current documentation version0.4.1) - Maintenance & Distribution: Community directory entry is DPH-1121; The source code and
github:installation spec in the README point to the repositorygithub.com/HaydenSmith1121/dsh-usage-stats. - Category: Memory (SkillHub Directory)
- Summary: Read-only access to this session’s JSONL logs, folding out reports consistent with DSH’s
tokenUsageprojection, and using an append-only per-session ledger to ensure “usage is not deleted when sessions are deleted.”
The plugin does not hold API Keys, does not contact providers, and does not modify model routing. Except for the ledger under $DSH_HOME/storages/dsh-usage-stats/, it does not write to any other DSH data.
Core Features¶
What to see in the interface¶
After opening the usage page in Harness settings, you can view data by Today / Last 7 days / Last 30 days / All:
- Total token count, along with the four buckets reported by the service provider: Uncached Input, Output, Cache Read, Cache Write.
- Cache read ratio (to avoid misjudgment when looking only at totals).
- Number of model calls within the range.
The footer states: how many session logs were read, how many read failures occurred, how much usage from deleted sessions came from the ledger, and the format generation of the session logs read (e.g., v4 × 12; marked as “Version Untagged” if the header generation cannot be recognized). The range is a local calendar window with inclusive endpoints ending today, so the 7-day figure includes 7 days.
Append-only Ledger (Since 0.3.0)¶
Every scan backs up the per-session aggregated results to:
$DSH_HOME/storages/dsh-usage-stats/usage-ledger.json
The rules are briefly as follows:
| Rule | Meaning |
|---|---|
| Append-only | For the same session and same (Day, Provider, Model) cell, take the maximum value between the ledger and the current log; logs being compressed, truncated, or rewritten cannot lower the billed figures. |
| Never Delete | Once written, it only updates upwards; no TTL, no upper limit. To clear statistics, you must manually delete the directory; the next scan will use the currently present logs as the baseline. |
The background patrol runs approximately every 30 seconds, re-folding only logs where mtime/size has changed. It records to the ledger even if the settings page is not open. If the ledger is corrupted, the original file may be moved to usage-ledger.json.corrupt.json; the page will explain whether “usage is retained after session deletion” based on the ledger status, or describe behavior when the ledger is unavailable.
Compatibility with DSH Versions¶
Declared compatible with dsh 0.1.6-alpha.1 to 0.2.1-rc.2 (including desktop version 0.2.1-rc.2). Session logs are identified on disk by generation (e.g., 0.1.6 writes v3, 0.1.7 writes v4). After an upgrade, multiple generations of files may coexist; the generation with the highest read values is selected, consistent with the harness’s own selection. See docs/compatibility.md in the repository for detailed tests.
The folding algorithm deliberately aligns with the projection of @deepseek-ai/dsh-token-meter (the last usage sample wins within the same step, retries open a new slot, handling both assistant/message and assistant/attempt simultaneously, etc.) to avoid inconsistencies with the framework’s metrics.
Installation and Activation¶
Method A (Recommended): Install the plugin market panel dsh-plugins-market, and install this entry in the left-hand “Plugin Market” (the market spec is the github: source of this repository, without going through intermediate artifact repositories).
Method B (Manual): Execute according to the profile you are using (web and desktop profiles are different; installing to the wrong one will result in it not being loaded):
dsh plugin --profile web add github:HaydenSmith1121/dsh-usage-stats # dsh web
dsh plugin --profile desktop add github:HaydenSmith1121/dsh-usage-stats # Desktop
If unsure about the profile, check which directories exist under $DSH_HOME/profiles/. The repository has committed the lib/ build artifacts, so git installation requires no local build; you can also use npm run pack to create a tarball and replace the add parameter with the absolute path to the .tgz.
Restart after installation (dsh web, or quit and reopen the desktop version): The settings page is on the client side (half-loaded); the routes for reading logs and maintaining the ledger are registered on the host side during startup. The page will explain this before a restart.
Uninstallation (does not delete ledger files):
dsh plugin --profile web remove dsh-usage-stats
dsh plugin --profile desktop remove dsh-usage-stats
To clear statistics: Delete $DSH_HOME/storages/dsh-usage-stats/ and restart the scanning logic.
Do not install simultaneously with the old package
dsh-workbuddy-quota, otherwise two Token Usage settings pages may appear; this package is its successor (renamed and retaining only usage statistics).
Typical Usage¶
This plugin has no configuration options (no API Key, no environment variables, no settings form). If $DSH_HOME is not set, it defaults to ~/.dsh, consistent with DSH.
Typical workflow:
- Install into the correct
webordesktopprofile as described above and restart the Harness. - Open the Token usage related page in settings, switching between Today / 7 days / 30 days / All to view summaries and the four buckets.
- When verifying reliability, check the footer: session read counts, number of deleted sessions retained by the ledger, log generation, and ledger status (
ok/rebuilt/unavailable). - If you frequently clean up sessions, you can rely on the ledger; if you wish to start statistics from scratch, delete the
storages/dsh-usage-stats/directory with the understanding that historical ledger data will be lost.
Use Cases and Notes¶
Suitable for: Long-term observation of token spending on local Harness, comparing models and cache read/write ratios, and retaining historical usage trends after cleaning up sessions.
Permissions & Security: The plugin reads $DSH_HOME/sessions/ and writes to the ledger directory with the permissions of the current dsh process. It is recommended to review the repository source code and MIT license before installation to ensure compliance with your environment policies.
Honest Boundaries (Registered in README), please be aware when using:
- Title generation (
session/title-llm-request) consumes tokens but has no usage samples. It is invisible to any folding logic, same as DSH’s own projection. - Sessions deleted before the ledger was enabled (first run in 0.3.0) cannot be recovered; usage within the last ~≤30 seconds after deletion that has not yet been folded by the patrol may be missed (patrol interval is 30 seconds).
- Fork session inheritance prefixes are not billed (cut point logic aligned with harness since 0.4.0); if the same session ID appears in two workspace directories, the ledger merges by ID and reports sum them, which may be inconsistent if coexisting with layouts dsh considers corrupted.
- If a session directory is temporarily unreadable, the page will state that the numbers come entirely from the backup and will not mislabel present sessions as “deleted.”
The Community Plugin Directory (SkillHub) is an independent site and has no official affiliation with DeepSeek / Hithink. Star ratings and other metadata are subject to the directory page (current clue is 1 star).
Links¶
- Directory Page: https://www.skillhub.cn/plugins/DPH-1121/dsh-usage-stats
- GitHub: https://github.com/DPH-1121/dsh-usage-stats (The
github:installation and source code instructions in the README usegithub.com/HaydenSmith1121/dsh-usage-stats)