feely0208/dsh-token-cost: View token spending and budget progress in the DSH sidebar.

Preface

DSH writes the usage of every model call into session logs. The logs are session.v4.jsonl.zstd, located in ~/Library/Application Support/DeepWhale Desktop/dsh-home/sessions, organized by workspace and session directories. To figure out how much money was spent during this period, the traditional way is to manually construct a pipeline: zstd -dc to decompress, then jq to extract the usage, aggregate by time window, and apply the pricing table for conversion. With many logs, hardly anyone actually does this step.

The feely0208/dsh-token-cost introduced below does this for you: the plugin reads local logs, creates a sidebar panel for token usage and costs, and allows you to see current spending, cache savings, rankings by model and session, and budget progress directly. First, a clarification: The amounts are local estimates, not the official bill—calculated based on the usage of each call in local logs and the snapshot of the DeepSeek official pricing page, excluding platform gift credits, discounts, and exchange rate fluctuations.

What is this

The plugin name is @deepwhale-cn/dsh-token-cost, repository feely0208/dsh-token-cost, maintainer feely0208, author attribution is Wenzhou Deepwhale Intelligent Technology Co., Ltd., license MIT. Current version 0.1.1, package declared host range is dsh >=0.1.0-rc.6 <0.3.0, node >=18.

One-sentence positioning: Turns token usage from DSH session logs into a spending view in the sidebar, reading only local data, no internet connection, no upload. It also provides rankings by model and by session, giving a traceable answer to the question “where is the money going?” rather than just looking at the total bill.

What’s in the Panel

Block Content
Four Windows Today / Last 7 Days / Last 30 Days / This Month (based on local natural days, This Month starts from local 1st)
Overview Cost (USD + CNY), Cache Hit Savings, Cache Hit Rate, Calls / Total Tokens
Budget Progress This month’s cost compared to budget, progress bar + remaining; budget only exists in local browser localStorage
Daily Trend Last 30 days daily cost bar chart (hover to see daily amount / count / tokens)
By Model Sorted by amount, includes provider; third-party models marked “Unknown Price” are not included in the amount
By Session Top 20 most expensive sessions, with workspace directory, token count, and whether it is a sub-agent
Export CSV (by day / session / model) and JSON (including summary and details), only local statistics

The budget item is worth mentioning separately: the budget number only exists in the browser localStorage, does not modify any config files, and will not sync elsewhere. To set a default budget, use the environment variable DSH_TOKEN_COST_BUDGET.

Installation and Enablement

The installation command is from the original README:

dsh plugin --profile web add @deepwhale-cn/dsh-token-cost

After installation, a “Token Cost” icon will appear in the sidebar. Clicking it opens the panel above.

There is only one prerequisite: the system has the zstd executable file. Without it, .zstd logs cannot be read. macOS can do brew install zstd; the plugin defaults to looking for /opt/homebrew/bin/zstd, /usr/local/bin/zstd, and follows PATH, without adding any new npm dependencies.

Where does data come from

Below is the default path and directory structure, read-only, does not modify, delete, or move any logs:

~/Library/Application Support/DeepWhale Desktop/dsh-home/sessions/--<workspace>--/<sessionId>/session.v4.jsonl.zstd

Logs are zstd multi-frame, append-only. The plugin reads two types of events from them (README verified with real logs on 2026-10-29):

  1. assistant/message: Takes data.usage { inputTokens, outputTokens, cacheReadTokens, cacheWriteTokens, totalTokens }, model and provider in data.message.source.
  2. compaction/summary: Takes data.usage, provider and model in data.provider / data.model.

Parsing is completed entirely within the local process, no internet connection, no upload; exported files will not leave the local machine. Available environment variables:

Variable Purpose
DSH_SESSIONS_DIR Override session log root directory
DSH_ZSTD_BIN Specify zstd executable path
DSH_TOKEN_COST_USD_CNY USD to CNY exchange rate (default 7.2)
DSH_TOKEN_COST_BUDGET Default monthly budget; ≤1000 is treated as USD, otherwise treated as CNY

Pricing Basis

Pricing snapshot is taken from the DeepSeek official pricing page on 2026-10-29, unit is USD / Million tokens:

Model Input (Cache Hit) Input (Cache Miss) Output
deepseek-flash (V4.1-Flash-1017) Peak $0.006 $0.30 $1.20
deepseek-flash Off-Peak $0.003 $0.15 $0.60
deepseek-v4-pro Peak $0.044 $1.32 $3.96
deepseek-v4-pro Off-Peak $0.022 $0.66 $1.98

Calculation Rules:

  1. Off-peak pricing is half of peak pricing; Peak = Weekdays 01:00–04:00, 06:00–10:00 UTC, the rest (including weekends) is Off-Peak.
  2. Each call is judged peak / off-peak based on its occurrence time, then accumulated by the three tiers.
  3. Cache Savings = Hit tokens × (Miss Price - Hit Price).
  4. Old names deepseek-v4-flash / deepseek-v4-flash-vision-exp are classified under Flash pricing according to official comments.
  5. Only the two providers deepseek-official / deepseek-account are calculated at official prices; other gateways (e.g., agnes) are marked “Unknown Price”, only token statistics are counted, amount is not calculated, and a separate warning is shown.
  6. Chinese statutory holidays are not deducted (official holidays are treated as Off-Peak all day), so statutory holidays will be calculated at Peak rates, which is a conservative estimate.
  7. DeepSeek reserves the right to change prices; the plugin is just a snapshot at a certain moment and does not constitute a bill.

Verification and Pre-release Checks

Verification commands given in README:

node --check lib/index.js          # as well as lib/*.js, tests/*.mjs
node scripts/preflight-client.mjs . # client bundle preflight (simulating host load/activate/render)
node tests/smoke.mjs                # pricing + zstd multi-frame holiday logs end-to-end
node tests/http.mjs                 # HTTP export
node tests/client-render.mjs        # rendering the report panel with real shapes, catching rendering exceptions

preflight-client.mjs is a mandatory gate after a white screen crash: if any client plugin entry fails to activate, the host page will display “Failed to load plugins”. prepublishOnly in package.json also points to this script, so it must be run before publishing.

Use Cases and Notes

Suitable for these types of people: DSH users who want to know “exactly how much was spent these past two days, and on which model and session”; those who want to monitor monthly budgets; those who want to verify how much caching actually saved. For those who only want to see the official bill, the amounts in the panel are not precise enough, and directly using the DeepSeek backend bill is more suitable.

Notes:

  1. The plugin runs with the permissions of the current dsh process and will read the local session log directory. You should check the source code and license (MIT) before installing.
  2. The log format is DSH’s internal format; if the structure changes in future versions, the plugin will display “No data” rather than guessing.
  3. Known blind spots: Calls that do not appear in session log usage, such as session title generation and Search & Fetch, will not be counted; platform gift balance, limited-time discounts, and exchange rate fluctuations are also not included.

Conclusion

The value of this plugin lies not in making billing more precise, but in producing a view that can be glanced at daily from the logs already available locally: how much was spent this period, how much was saved by caching, and where the money went. Data stays local the whole time; whether to export is up to the user.

Directory Page: https://www.skillhub.cn/plugins/feely0208/dsh-token-cost
GitHub: https://github.com/feely0208/dsh-token-cost

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

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

Xiaoye