Preface¶
When running long sessions in DeepSeek Harness (DSH), tool outputs often occupy a large portion of the context: pwsh logs, grep hits, cordis_inspect_* JSON bodies, MCP proxy outputs, etc., are frequently brought into subsequent requests within the same session. Common practices rely on context compaction or deleting history after the fact, but if the compaction threshold isn’t tuned well, either the bill remains high, or the model repeatedly re-reads the same file. dsh-token-trim (maintainer LISHUANGXI1412, category: workflow) is attached to tools/post-execute. It performs structured summarization, head/tail truncation, duplicate deltas, and product persistence before the result is written to the model context, accompanied by a Savings view. The README states this is not an agent requiring separate trust, is reproducible on every rewrite, the original text is on disk, and the model can backtrack via guard_query.
What is it¶
dsh-token-trim is a DSH plugin, current package version is 0.2.0, MIT license, requires Node >= 22. It solves the problem of “context inflation caused by overly long tool outputs”: applying rule-based rewriting to long text results from selected tools while preserving artifact ID and audit records. Community directory: https://www.skillhub.cn/plugins/LISHUANGXI1412/dsh-token-trim; Source code and documentation: https://github.com/LISHUANGXI1412/dsh-token-trim.
Core Capabilities¶
After installing and restarting DSH, you get three things: token-trim (host) rewrites tool results in tools/post-execute; token-trim-index (host) lists recent artifacts and involved paths in the system prompt; the UI adds a Savings tab next to Chat / Trajectory / Stats and provides a guard_query tool.
Four Rewrite Rules¶
The README summarizes the default strategy in a table (tools not listed are processed only if above minChars, default 1200 characters):
| Rule | Target | Behavior |
|---|---|---|
| structural summary | cordis_inspect_*, plugin_manager, grep, skill, list_agents, CUA window dump, etc. JSON results |
Retain structure (keys, counts, ids), replace verbose body with pointers |
| head/tail cap | pwsh, job_output, etc. long text |
Retain 72% of the beginning and 28% of the end within the cap, insert artifact pointers and line numbers |
| repeat delta | Tools in deltaTools |
When the same tool+args are executed again with a diff less than 60% of the full text, only send the diff |
| unchanged pointer | Same as above | Send [unchanged · same as #N · artifact <id>] |
Explicitly unchanged: edit, write, todo, sub-agent messages, images, multi-block results, reasoning, and results below minChars. The maintainer recorded on their test machine: 19-day sessions, 279 rewrites, resulting character reduction approx −74.9%; the README emphasizes this ratio applies only to “outputs rewritten by this plugin” and does not equal the total bill. Bill-level offline replay estimation (stacked with compaction) is approx −41.3% net (including suspected rework deductions); the Savings tab distinguishes gross, rework deductions, and net.
Safety & Reversibility¶
- Fail open: Exceptions, unexpected structures, or non-text results → pass through the original text, do not block the tool.
- Rewrite only single text blocks; images, structured values, and multi-block results are not rewritten.
- The original text is first written to
~/.dsh/token-trim/artifacts/<sha16>.txt, then the text with the artifact ID is replaced. guard_query(id, pattern)searches within the original text (substring or/regex/, can include context lines); the same artifact is fetched at most 2 times, the third time returns a capped full text of up to 12K characters (README notes the third time consumes more context).- Append a line to
~/.dsh/token-trim/manifest.jsonlfor every transformation (tool, mode, chars in/out, artifact id, session id). - Repeat delta and unchanged are grouped by session + tool + args to avoid sub-agents mistakenly receiving “unchanged” pointers.
Maintainer-recorded rejected schemes include: default truncation of read (easily triggers offset/limit re-reads), summarizing logs with LLM (insufficient recall), sending unchanged across agents (fixed), and a resident small model for pruning (not cost-effective for the bill). read defaults caps.read: 0 to disable the cap.
Installation & Enablement¶
Execute the official installation command in the DSH environment (from README, do not manually concatenate github:owner/repo form):
dsh plugin add dsh-token-trim
After execution, restart DSH. The plugin runs with the current DSH process permissions; before installation, verify the source code and MIT license on the GitHub repository. The SkillHub directory is a community site and has no official affiliation with DeepSeek / Hyperbolic.
Configuration¶
Patch the token-trim line in the DSH profile, example consistent with README:
- id: token-trim
name: dsh-token-trim
config:
enabled: true
dryRun: false # record what would happen, rewrite nothing
minChars: 1200
capsDefault: 6000 # any tool not listed below
maxFetches: 2
caps:
pwsh: 2500
cordis_inspect_query: 8000
job_output: 4000
grep: 6000
'mcp__local-proxy__proxy_run': 4000
read: 0 # 0 disables a cap (content tools stay untouched)
When doing an evaluation, you can set dryRun: true: Savings will accumulate statistics, and the context will not be rewritten. Version 0.2.0 defaults to overriding tools not listed separately via capsDefault: 6000 (README notes the previous long omission of MCP-like outputs from the whitelist was a major gap).
Typical Usage¶
Observe Savings¶
Restart and open the session interface, enter Savings next to Chat / Trajectory / Stats, view by window and session: net bill estimate (including rework deductions), and if dsh-context-kit is installed, also includes actual usage (hit ×1 / miss ×10 / output ×15), character reduction by tool and session, as well as recent transformations and artifact IDs.
Return to Original Text from Context Pointer¶
When the model sees an artifact ID in the rewritten output, call:
guard_query(<artifact_id>, <pattern>)
pattern can be a normal substring or /regex/. The first two times return matching context according to rules; after exceeding maxFetches (default 2), behavior is described in the README’s 12K cap note.
Integration with dsh-context-kit¶
The README states: dsh-token-trim is responsible for runtime trimming, context indexing, and the Savings view; dsh-context-kit is separately responsible for Settings → Context compaction threshold tuning. You can install only one, but installing both yields the complete stacked effect.
Scenarios & Notes¶
Suitable for: Long-term DSH sessions, frequent pwsh / grep / inspect / MCP proxy outputs, scenarios where you want to compress characters before entering the model while preserving disk originals and auditing.
Notes:
- The character reduction ratio is not equal to the invoice; system prompts, tool definitions, reasoning, and small results not matching rules are not inside the hook.
- It is not recommended to default-cap
readto save characters; the maintainer’s testing showed truncatingreadonce caused large-scale rework. - The third
guard_queryfor the same artifact may not be as cost-effective as running the tool directly again; you need to combine it with Savings to judge. - Depends on
@deepseek-ai/dsh-typert-protocol0.2.1-rc.2, environment requires Node 22+.
Conclusion¶
dsh-token-trim turns tool result trimming into a configurable rule layer: rewriting is reproducible, original text is in ~/.dsh/token-trim/artifacts/, and Savings distinguishes “rewrite magnitude” from “bill estimate”. Directory: https://www.skillhub.cn/plugins/LISHUANGXI1412/dsh-token-trim; Repository: https://github.com/LISHUANGXI1412/dsh-token-trim.