dsh-cost-guard: Attach a real-time cost tag to DSH tasks

Preface

While writing this, I can’t recall how many tokens this round of tasks consumed. It is a common problem among DSH users: the DSH interface displays tokens and cache reads, but most of the time you care about “how much it costs in RMB.” Re-opening the vendor pricing page to calculate manually, or estimating based on prompt length, results in large errors. Additionally, requests for caching hits, sub-agent calls, retries, and interruptions are usually not calculated.

dsh-cost-guard does something else: no guessing, but directly reading real usage from DSH session events, calculating a local estimate using your configured unit price, and placing it below the input box. The plugin comes from maintainer chenzhiyong1994, categorized under the admin-security category in the community plugin directory, open-sourced under the MIT license, current version v5.1.0. Below is an introduction to its functions, installation method, and precautions.

What is it

In short: dsh-cost-guard is a local Cordis plugin bundle that converts real token usage recorded by DSH into monetary amounts in real-time, displays them in a compact tag below the input box, and provides cumulative statistics by model and an editable price table.

Two common misunderstandings are clarified first:

  1. It does not intercept, rewrite, or route Agent execution; it simply observes via a side channel. There is no prediction gate, nor a confirmation mask.
  2. The amount it provides is a local estimate, not an authoritative bill. Official prices change, and the supplier’s invoice is the final word.

In package.json, it uses dsh.bundle.patch to declare the Host half and dsh.client to declare the browser half, so it is not a traditional single-file plugin, but installed as a DSH bundle.

Core Features

Organized item by item according to capabilities mentioned in the README.

  1. Based on real usage. Reads inputTokens, outputTokens, cacheReadTokens, cacheWriteTokens from DSH usage events, covering retry and interrupted requests, and does not estimate based on prompt size.
  2. Real-time visibility. Displays the ¥ amount for the current or last task below the input box. Clicking the tag pops up model, input/output/cache tokens, model call counts, peak-valley timing, and cumulative for this session.
  3. Supports sub-agents. Sub-agent usage accumulates into the root session’s current round and is priced according to the actual model served on each call.
  4. Recoverable on restart. If the plugin has restarted, viewing a session for the first time will backfill historical cumulative data from persistent event logs.
  5. Auditable pricing. All model unit prices and peak-valley periods are visible and editable in the settings page.
  6. Bilingual interface. Price tags and settings pages automatically switch following the DSH general settings language.
  7. Completely local. No telemetry, no external services, no account access, and does not collect API Keys.

Installation and Enabling

First, the runtime requirements: DeepSeek Harness 0.2.1+ (desktop or dsh web), profile needs to include the Web app bundle; the price tag and settings page require DSH Web UI. You only need Node.js when running npm run check during development.

The bundle is installed via a local directory, not pulled directly from GitHub. The steps are as follows:

  1. Put the repository in a fixed path, for example D:\plugins\dsh-cost-guard.
  2. Open DSH Settings → Plugins → Bundles, install from local directory; or use the equivalent command:
dsh plugin --profile <profile> add "D:\plugins\dsh-cost-guard"
  1. When the installer reports restart-required, restart DSH.

You can also let the DSH agent install it directly. The equivalent prompt:

Install the DSH bundle at D:\plugins\dsh-cost-guard to the current profile,
then confirm that the cost-guard line is activated in the plugin manifest.

After installation, Cost Monitor will appear in the plugin manifest, Settings → Cost Monitor will appear as a top-level page in settings, and a price tag will appear below the input box. Both halves are pure JavaScript with no build steps.

When modifying source code for local development, simply swap the above path for the checkout directory. The installer loads it as a link; changes take effect after reinstalling and restarting.

Upgrading is done by replacing the whole package: replace files or pull a new release, run the install command again, and restart. Both Host and browser sides will reload from the new files.

Configuration Items

Open Settings → Cost Monitor. Configurable content is divided into four blocks:

Block Content
Model Pricing Input cache miss, output, input cache hit unit prices; add custom models; restore defaults (requires two-step confirmation)
Peak-Valley Pricing Toggle, time periods, and multipliers
Current Run Cumulative Settled rounds, actual cumulative, editable exchange rate, statistics by model
Config Backup JSON export and import (import will validate before replacing current settings)

Pricing Model

The default unit prices for v5.1.0 are filled based on DeepSeek V4.1 Flash / V4 Pro official peak-valley pricing checked on 2026-10-28. The unit is RMB Yuan / 1M tokens. The table below shows off-peak prices:

Model Input (Cache Miss) Output Input (Cache Hit)
deepseek-flash ¥1.00 ¥4.00 ¥0.02
deepseek-v4-pro ¥4.50 ¥13.50 ¥0.15
default Fallback ¥1.00 ¥4.00 ¥0.02

Several side effects to note:

  1. Peak hours are Beijing Time Mon-Fri 09:00–12:00 and 14:00–18:00; the unit price is 2x the off-peak price. Weekends and statutory holidays are off-peak all day; the 2026 holiday schedule is built-in. Peak-valley pricing is enabled by default and can be turned off or changed in the settings page.
  2. Official pricing does not list cache write separately; cache write tokens are calculated using the input cache miss price.
  3. Old model names map to current billing lines: deepseek-v4-flash, deepseek-v4-flash-vision-exp → deepseek-flash, deepseek-reasoner → deepseek-v4-pro; the retired deepseek-chat also maps to Flash.
  4. Search / Fetch are billed separately by DeepSeek (¥5 / 1,000 successful requests starting 2026-11-01). The plugin only counts model tokens, excluding these request fees.

How it Works

The Host half (index.js) injects webServer, folds already logged session events, assigns rounds, aggregates sub-agents, backfills history on first view, and exposes two data routes (/cost-guard/live, /cost-guard/rpc) and one health check route. The Client half (client.js) registers the price tag in conversation.composer.dock and the settings page in settings.section, reading from the Host via fetch.

The data flow stays entirely within the current DSH process, routes go through local HTTP, and does not access the external network. Price state is persisted in ~/.dsh/cost-guard/config.json (recognizes $DSH_HOME) and remains after restart.

Suitable Scenarios and Notes

Suitable scenarios: running daily tasks with DSH and wanting to see the approximate cost of each task without interrupting the workflow; multi-turn tasks using sub-agents; teams with audit requirements for model unit prices and peak-valley rules.

Three things to note before installation:

  1. The plugin runs with the permissions of the current DSH process, so it can read session events and local config paths. Before installing, review index.js and client.js to confirm there is no unexpected behavior.
  2. It depends on DSH Slots like webServer, sessions, session/event, conversation.composer.dock, settings.section, etc. These are not stable public APIs. DSH plugin interfaces are evolving rapidly, and third-party plugin compatibility is your own responsibility. Providing the DSH version when reporting issues will help locate them faster.
  3. The amount is an estimate. Remember to update unit prices in the settings page after price adjustments, otherwise the estimate will deviate from the actual bill. The plugin does not connect to the internet to verify prices.

Conclusion

The value of dsh-cost-guard lies in turning “how much it costs approximately” from an estimate into a comparable number, and it only observes without intervening in execution. It is suitable for DSH users who want to know where their tokens are being spent and are unwilling to maintain a set of external monitoring scripts.

Directory Page: https://www.skillhub.cn/plugins/chenzhiyong1994/dsh-cost-guard

GitHub: https://github.com/chenzhiyong1994/dsh-cost-guard

It is worth noting that the community directory is an independent site and has no official affiliation with DeepSeek / HFZ. It is not an official app store. The plugin itself is open-sourced on GitHub under the MIT license, so you should still verify the source code and license yourself before installing.

羽毛球分组比赛记分
小程序二维码

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

Xiaoye