Introduction

In long DSH sessions, context pressure increases with turns. DSH has a built-in compaction-basic with a default pressure threshold of 80%. If you only want to set a lower or higher compression point for the current session, dsh-auto-compact provides session-level thresholds. After exceeding the threshold, compact is executed automatically, and the session continues naturally after the summary is injected into the context.

What is this

dsh-auto-compact is a session-level automatic context compression plugin for DeepSeek Harness (DSH), maintained by JohnathonYe, licensed under MIT. It monitors the context usage of the current session and automatically executes compact when the session threshold is exceeded, without sending any “continue” messages.

Core Features

  • Session-level threshold: Set independently for each session, persisted by sessionId.
  • Real-time usage: Displays the current session’s context usage, sourced from the built-in ContextMeter, reading useProjection("contextPressure").
  • Threshold adjustment: Supports 1%–90%, step 1%; defaults to 50% when not set.
  • Auto-detection: Checked before every step in a turn and at the end of the turn; executes compact automatically if the threshold is exceeded.
  • Session continuation: The session continues naturally after the summary is injected into the context, without sending any “continue” messages.
  • Threshold persistence: Saved in the dsh-auto-compact namespace in settings.yaml, persists across restarts.
  • Coexistence with built-in mechanisms: DSH’s built-in compaction-basic (default 80% pressure threshold) remains active and does not interfere.

Installation & Enablement

First, confirm the prerequisites: DSH is installed and dsh web runs normally; Node.js ≥ 20 and pnpm ≥ 10. Also, DSH’s compaction-basic (@deepseek-ai/dsh-compaction-basic) must be enabled; default presets standard / code / cordis are built-in, except the minimal preset.

If you previously installed the old package name auto-compact, uninstall it first, then install the new package name dsh-auto-compact to avoid double mounting:

npx -y --package @deepseek-ai/dsh dsh plugin --profile web remove auto-compact

Recommended one-click installation command:

curl -fsSL https://raw.githubusercontent.com/JohnathonYe/auto-compact/main/scripts/install.sh | bash

After installing or updating, restart DSH and force refresh the browser: macOS uses Cmd+Shift+R, Windows / Linux uses Ctrl+Shift+R. Run the one-click installation command again when updating, then restart DSH and force refresh the browser as well.

Uninstall using the following command:

npx -y --package @deepseek-ai/dsh dsh plugin --profile web remove dsh-auto-compact

Typical Usage

  1. Click the ring on the right side of the input area to open the panel.
  2. The panel displays the current session’s real-time context usage (percentage).
  3. Drag the slider to set the threshold (1%–90%, session-level independent; new sessions not dragged before default to 50%, only effective for the current session).
  4. Thereafter, whenever the usage exceeds the threshold (before a step in a turn, or at the end of a turn), the plugin automatically executes compact and continues.

Implementation Details & Notes

  • Checkpoints: All checks are executed in agent/pre-step (waterfall middleware) and agent/turn-stopping (serial events), wrapped in try/catch at all times, never throwing.
  • Threshold storage: Thresholds are saved in the dsh-auto-compact namespace in settings.yaml.
  • Settings channel: The plugin uses a custom webServer route /dsh-auto-compact/api, where the host side writes directly to the settings service, bypassing DSH’s official namespace whitelist for api.settings.
  • Permissions and audit: The plugin runs with the permissions of the current dsh process. Source code, dependencies, and the MIT license should be checked before installation; if the preset does not enable compaction-basic, the plugin cannot meet the prerequisite for automatic compact.

Conclusion

dsh-auto-compact changes the context compression threshold from a global default to a current session adjustable setting, suitable for DSH sessions requiring fine-grained control of context pressure.

GitHub repository:

https://github.com/JohnathonYe/auto-compact