Preface¶
When running agents in DSH, the conversation turns themselves are often not the main cause of context bloat. More commonly, it’s tool returns: read returning hundreds of lines at once, pwsh printing full-screen logs, tool definitions stuffed into the system prompt and repeated every turn. Once these contents are written into session history, subsequent turns can only rely on the compressor to trim them afterward; compression rewrites committed history, the server-side prefix cache then gets invalidated, and every later turn becomes more expensive.
The community plugin dsh-context-reclaim (maintainer xiamubumu) moves the governance point forward: it processes tool results before they are appended to history, and does not rewrite already-committed content, with the goal of keeping prefix caches unbroken by this plugin. The following covers what it is, which seams it hooks into, and how to install and configure it.
What Is This¶
dsh-context-reclaim is a client-side plugin for DeepSeek Harness (DSH); the current version in the repo’s package.json is 1.1.0, licensed under MIT. It only targets DSH 1.5 (>=0.1.5-rc.2 <0.2.0); the README states that future DSH versions will be supported.
Its positioning can be summarized in a line from the README: reclaim tool results before they enter history; prefix caches are not invalidated by this plugin. Additionally, starting from 1.0.0 it takes over the host’s writable request path for llm.streamWithRegistration at the plugin layer, so it no longer depends on file patching of the official @deepseek-ai/dsh-llm (after turning off takeover, that patch may still be required; see environment variables below).
It occupies 5 server-side Cordis seams and 0 client-side slots; the README states that when coexisting with plugins in the same category, the conflict probability is extremely low, and it does not occupy chain-type slots. The plugin directory can be viewed on the community site SkillHub; this directory has no official affiliation with DeepSeek / Hunyuan and belongs to the community ecosystem.
Core Features¶
The plugin works across five seams, all enabled by default:
| Seam | Purpose |
|---|---|
tools/post-execute |
Sanitize and bound tool results by type after they are produced, inserting a retrieval pointer at truncation points |
system-prompt/assemble |
Collapse the tool definition surface, stabilize the prefix section order, truncate overly long description lines |
tools/pre-execute |
Intercept a repeated identical edit to the same file segment on the second attempt |
session/event |
Audit compression summary integrity; emit a warning when sections are missing (does not modify the summary) |
llm/stream |
Per-request one-line cost attribution (route / prompt / cache hit / output) |
Tool Result Sanitization and Bounding¶
Every time a tool returns, it first performs lossless sanitization (folding ANSI, removing trailing whitespace, normalizing CR), then bounding. Sanitization only takes effect when the length is ≥ 32 characters and the reduction ratio after sanitization is ≥ 0.2%. Bounding classifies tools into three categories: read-only, side-effecting, and faithful; unrecognized tools are treated as faithful. At truncation points a retrieval pointer is inserted explaining the remaining content and how to retrieve it. Bounding only triggers when it can save more than 5%.
Results exceeding config.maxInlineBytes (default 50000) are handed to the spill mechanism to write to disk; a spill plugin must already be installed in the profile, otherwise this threshold has no effect.
Disable sanitization: config.noise = false or DSH_RECLAIM_NOISE=0. Disable bounding: config.bounded = false or DSH_RECLAIM_BOUNDED=0.
Tool Definition Surface Collapse and Prefix Stabilization¶
At session start, DSH writes all tool definitions into the system prompt. By default the plugin collapses the full schema of infrequently used tools while keeping full definitions for high-frequency tools; collapsed tools remain callable (the README explains they can still be used via paths such as search_tools + invoke_tool). Disable collapse: config.foldTools = false or DSH_RECLAIM_TOOL_FOLD=0.
Prefix stabilization flattens volatile numbers and orders stable sections first, helping the server hit prefix caches byte-for-byte. The log may show [reclaim/section-order]. Disable: DSH_RECLAIM_STABILIZE=0.
Overly long single-line descriptions in the system prompt are truncated at 120 characters by default; the threshold is controlled by the environment variable DSH_RECLAIM_PROMPT_LINE_MAX (not exposed in config).
Duplicate Edit Interception and Summary Audit¶
When two consecutive identical modifications are made to the same content in the same file, the second one is intercepted at tools/pre-execute, with log [reclaim/dedup-deny]. Disable: DSH_RECLAIM_DEDUP_DENY=0.
After compression completes, if the summary lacks expected structural sections, a warning like [reclaim/summary-audit] ⚠️ 摘要缺 3/8 段 is emitted. The README emphasizes: only warns, does not modify the summary; to reduce the summary being truncated by the output budget, the docs recommend installing it together with dsh-aux-degrade.
Writable Request Takeover and Patch Check¶
By default it makes a shallow copy of the frozen main request before llm/stream, so the plugin chain can modify options / messages. The startup log may show [reclaim/writable]; after sending a message there will also be [reclaim/wire], [reclaim/usage]. If takeover is disabled (DSH_RECLAIM_WRITABLE_REQUEST=0), options returns to frozen state, and the official dsh-llm patch may then be required.
At startup the plugin also performs a read-only “official patch check” ([reclaim/patch-check]) listing detected patch status; it will not automatically modify your local DSH installation directory. Use DSH_RECLAIM_PATCH_CHECK=0 to disable.
Installation and Enablement¶
Both the DSH 1.5 desktop version and web version are supported. Installation commands follow the README and installation guide.
Install from GitHub (documented as the recommended method, requiring git locally for pnpm to resolve the github: shorthand):
dsh plugin --profile web add github:xiamubumu/dsh-context-reclaim
For offline environments, download dsh-context-reclaim-1.1.0.tgz from Releases, then run:
dsh plugin --profile web add /path/to/dsh-context-reclaim-1.1.0.tgz
After installation, you need to restart DSH. Host-side plugins are only loaded at startup; DSH registers the plugin into the profile’s dsh.profile.bundles, and generally you do not need to manually edit cordis.patch.yml to enable the bundle.
The docs note: do not pass the GitHub Release tarball’s HTTPS URL directly to dsh plugin add; on DSH’s bundled pnpm 10.34.5 it may trigger ERR_PNPM_MISSING_TARBALL_INTEGRITY. Marketplace and npm installation methods are marked temporarily unavailable in the docs, awaiting community inclusion or npm publication.
After installation, confirm in the startup log: the presence of [reclaim/writable] and [reclaim/patch-check] indicates the plugin has loaded; after sending a message you should see [reclaim/wire] and [reclaim/usage].
Typical Usage¶
Profile Configuration Snippet¶
In the profile’s cordis.patch.yml, the plugin id is reclaim. The full configuration table is in the README; common fields are shown below:
- id: reclaim
config:
enabled: true
noise: true
bounded: true
stripLines: false
noOpGuardRatio: 0.05
maxInlineBytes: 50000
attribution: true
foldTools: true
activePlugins: []
The three tool name lists (readOnlyTools, sideEffectTools, faithfulTools), if present in the configuration, are full-table replacements, not merged with defaults; specifying only some fields will drop the remaining defaults.
Example of narrowing the read-only tool list as needed:
- id: reclaim
config:
readOnlyTools: ['read', 'grep', 'glob']
sideEffectTools: ['pwsh', 'bash']
faithfulTools: ['web_fetch', 'web_search']
Environment Variable Quick Reference¶
In addition to config, the README lists dozens of environment variables; common ones for daily debugging are:
| Variable | Default | Description |
|---|---|---|
DSH_RECLAIM_NOISE |
1 |
0 disables lossless sanitization |
DSH_RECLAIM_BOUNDED |
1 |
0 disables bounding |
DSH_RECLAIM_TOOL_FOLD |
1 |
0 disables tool definition collapse |
DSH_RECLAIM_WRITABLE_REQUEST |
1 |
0 stops writable request takeover |
DSH_RECLAIM_LOG |
1 |
0 disables this plugin’s logs |
DSH_RECLAIM_DUMP_SYSTEM |
0 |
1 dumps the assembled system prompt to a temp directory for troubleshooting |
Note: the trimSections config option itself does not open a gate; section folding requires DSH_RECLAIM_SECTION_TRIM=1 and a non-empty activePlugins.
Pairing with dsh-aux-degrade¶
The README calls dsh-context-reclaim and dsh-aux-degrade the “context governance duo”, strongly recommending installing both: the former governs content and prefix stabilization, the latter governs degradation and token fallback for auxiliary calls (such as compression and titles); their sources do not import each other, so they can be installed separately, but together they provide more complete coverage. The installation command is given alongside reclaim in the installation guide:
dsh plugin --profile web add github:xiamubumu/dsh-aux-degrade
For more detailed official patch notes, browser extensions, and other plugins in the same series, see tutorial-install-and-official-patches.zh-CN.md in the repository.
Use Cases and Notes¶
Who it’s for: Developers running tools for long periods on DSH 1.5, with many plugins installed causing large system prompts and tool returns, who also want to reduce frequent prefix cache invalidations. If you mainly do short conversations and rarely call tools, the benefit may not be obvious, but you can still rely on the cost attribution lines to observe cache hits.
Version and platform: Only supports the specified DSH 1.5 version range; before switching DSH major versions, check the compatibility notes in the repo README.
Permissions and security: The plugin runs with the current DSH process permissions and processes tool output and session events. Before installing, read the GitHub source and the MIT license yourself to confirm it meets your security policy. The docs state zero runtime third-party dependencies, with peerDependencies declaring only the official @deepseek-ai/schemastery and @deepseek-ai/dsh-tools.
Depends on spill: Writing oversized results to disk depends on a spill plugin in the profile; without it, maxInlineBytes has no effect.
Closing¶
dsh-context-reclaim places context governance before tool results are committed: sanitization, bounding, tool surface collapse, and prefix stabilization, plus duplicate edit interception, summary audit, and per-request cost attribution; at the same time it takes over the writable request path, reducing reliance on dsh-llm file patches.
- Community directory: https://www.skillhub.cn/plugins/xiamubumu/dsh-context-reclaim
- Source and docs: https://github.com/xiamubumu/dsh-context-reclaim