Introduction¶
When using DeepSeek Harness (DSH) for agent development or daily conversations, two common issues are often encountered: a lack of visibility into Token consumption or costs per conversation, and the potential for cost overrun due to long conversations or large model calls. Existing solutions either only allow after-the-fact statistics review or require manual maintenance of limits across multiple sessions. This article introduces a budget management plugin designed for DSH, adding real-time control to each session—much like a data usage meter.
What Is This¶
dsh-token-budget is a DSH plugin maintained by tfcheng80808080, categorized under model inference. It sets budget limits per Token or monetary amount for each DeepSeek Harness session, displays real-time usage below the input box, and blocks input when the limit is exceeded.
Core Features¶
Compact Capsule Display¶
Below the input box, there is only a progress bar. It turns amber when usage exceeds 80% and red when the limit is reached. The capsule blends with the background and shows a base color on hover.
Two-Level Popover Controls¶
Click the capsule to expand a popover where you can switch the metric and scope, view used vs. limit amounts, set a new limit, restore defaults, and toggle the blocking feature on or off.
Two Metrics¶
- Token: supports 1 / thousand / million / billion / trillion units
- Money: supports yuan / jiao / fen units
Three Scopes¶
- Session: statistics for the current session only
- Task: limit resets each turn
- Project: loaded sessions in the same workspace share the limit
Per-Model Pricing¶
The plugin reads the prices[model] configuration item and calculates costs using that model’s unit price. When no match is found, it falls back to defaultPrice. Billing distinguishes between uncached input, cache read, cache write, and output.
Hard Block Mechanism¶
When the budget is exhausted, the plugin aborts the current turn at the agent/pre-step stage, does not issue a model request, and displays in the session: “Budget Manager: Budget exhausted, current task terminated.”
Optional Statistics¶
When blocking is turned off, the plugin still tracks usage but does not intercept input.
Installation & Enablement¶
Install from npm:
dsh plugin --profile desktop add @tfcheng80808080/dsh-token-budget
Or install from a local directory (for development and debugging):
dsh plugin --profile desktop add /path/to/token-budget/plugin
After installation, enable it in DSH under “Settings → Plugins”, then refresh the page.
Typical Usage¶
Via Popover¶
Click the capsule below the input box, then in the popover:
| Action | Description |
|---|---|
| Token / Money | Switch the metric |
| Session / Task / Project | Switch the scope |
| Input field + unit + Apply | Set the limit for the current scope |
| Restore Default | Revert to the global default limit |
| On / Off | Track only, or block when exceeded |
Via Commands¶
The following commands are supported:
budget: view the current budget statusbudget on|off: enable or disable blockingbudget mode token|money: switch the metricbudget scope session|task|project: switch the scopebudget limit <n>: set the limit for the current scopebudget reset: restore the default limit
Configuration Example¶
enabled: true
scope: session # session | task | project
mode: token # token | money
tokenLimit: 50000
moneyLimit: 10
currency: '¥'
defaultPrice:
input: 2
output: 8
cacheRead: 0.5
cacheWrite: 2
prices:
deepseek-v4-pro: { input: 4, output: 16, cacheRead: 1, cacheWrite: 4 }
blockOnExceed: true
The cost formula is: (uncached_input × input + cache_read × cacheRead + cache_write × cacheWrite + output × output) / 1,000,000. DSH’s inputTokens is already the input that missed the cache, while cache hits are tracked separately in cacheReadTokens, so there is no double billing.
Compatibility & Testing¶
- Requires DSH
>= 0.2.2-rc.5 - The client needs the
conversation.composer.dockandconversation.chat.nodeslots - The host must provide
sessionProjections(stateVersion 5),agent/pre-step, andcommands
Run tests:
cd token-budget && ./run-tests.sh # 46 unit + 7 real UI end-to-end
./run-tests.sh --send # additionally verify over-limit blocking
Each run generates a TEST-RESULT.md.
Use Cases & Notes¶
This plugin is suitable for scenarios requiring fine-grained control over Token consumption or costs in DSH, such as concurrent multi-session work, per-project budget allocation, or setting daily/per-task limits.
The plugin runs with the current DSH process privileges. It is recommended to review the source code and license before installing. The plugin is released under the MIT License and may be freely used and modified.
Summary¶
dsh-token-budget provides session-level budget management for DeepSeek Harness. Through a real-time progress bar and hard block mechanism, it helps developers manage Token usage and costs more intuitively. Combined with the command-line interface, you can flexibly adjust the scope and pricing model, making it well-suited for cost-sensitive agent development and usage scenarios.
- Plugin directory page: https://www.skillhub.cn/plugins/tfcheng80808080/dsh-token-budget
- GitHub repository: https://github.com/tfcheng80808080/dsh-token-budget