Introduction

DeepSeek Harness (DSH) uses a plugin-based architecture to build flexible agent workflows. In long conversations, context often bloats due to repeated information, outdated content, or erroneous results, wasting token budgets and even triggering context overflow. context-pruner is a session context triage plugin for DSH. It automatically identifies and processes stale, duplicated, failed, or oversized context content using heuristic rules to save token budget and control context bloat.

Core Features

The plugin’s core strengths lie in its deterministic processing mechanism and flexible configuration strategy.

  1. Deterministic, zero model dependency
    All judgments and rewrites are based on heuristic rules and do not rely on LLM calls or other external services. This means behavior is predictable and can be tested in offline environments.

  2. Five independently toggleable screeners
    The plugin includes five independent context screening mechanisms:

    • Stale output (staleOutput): For tool call pairs that are more than N turns older than the latest user message and whose results are still complete, rewrite them into an archival summary and remove the result blocks.
    • Repeated calls (repeatedCall): Detect calls with identical tool names and parameters (JSON key order does not affect matching), keep only the latest call, and remove older call pairs.
    • Failed calls (failedCall): For stale error results, replace input parameters with failure stubs (to prevent information leakage and save space) while preserving and pruning the error text.
    • Oversized blocks (oversizedBlock): When tool result text exceeds the character limit, keep the head and tail, and mark the number of omitted characters in the middle.
    • Stale reasoning (staleReasoning): For reasoning blocks beyond the retained turns, prune length only in reserved regions and remove them directly outside reserved regions.
  3. Reserved regions and exemption lists

    • Reserved region (reserve): Content from the most recent N user turns is never processed, avoiding interference with the context the model is currently using.
    • Exemption list (exempt): Protect stateful tools (such as task, skill, todowrite) from accidental deletion through two-dimensional configuration (tool names and file path wildcards).
  4. Audit reports and compaction integration
    Each triage run outputs a structured statistical report (including counts, savings, compaction scope, etc.). The plugin natively implements the ctx.compaction interface, integrating seamlessly with DSH’s compaction mechanism, and supports automatic pressure, context overflow, manual, and forced region compaction.

Installation and Enablement

The plugin is packaged and distributed via dsh.bundle.patch and supports multiple installation methods.

  1. Install from GitHub
    Use the official repository address to install:
    dsh plugin --profile demo add github:JohnXu22786/context-pruner
  1. Local mount
    Recommended method: mount a local directory to the target profile:
    dsh plugin --profile web add link:/absolute/path/context-pruner
  1. Git source installation
    Install from a Git repository with a specified branch:
    dsh plugin --profile web add "github:your-repo/context-pruner#main"

After installation, check whether the configuration is in effect with the following command:

dsh --profile web --dump-config

Typical Usage

The plugin provides two interaction methods: a model-visible tool and a human command.

  1. Via the /triage command
    This is the human command-line interface. It directly outputs the audit report and applies valuable processing.

  2. Via the triage_history tool
    This is a model-visible extension point. The model can invoke this tool to perform triage and obtain the audit report. If dryRun: false is set and there is content worth processing, processing is applied directly.

  3. Configuration example
    In cordis.patch.yml, you can override the default configuration to adjust retained turns or enable specific screeners:

    - insert:
        id: context-triage
        name: dsh-context-triage
        config:
          budget:
            contextTokens: 200000
            softRatio: 0.6
          screeners:
            staleOutput: { turns: 5 }
            staleReasoning: { enabled: false }
          exempt:
            tools: [task, skill, write, edit]

Use Cases and Cautions

  1. Use cases
    Suitable for scenarios that require maintaining long conversation context and are sensitive to token consumption. The plugin is especially well-suited for agent workflows involving logging, long-running batch tasks, or heavy file reading.

  2. Important limitations

    • Single compaction provider: ctx.compaction allows only one provider per context. If the current profile has already loaded another compaction implementation (such as the built-in basic compaction backend), one of them must be disabled via patch (disabled: true); they cannot coexist.
    • Permissions and source: The plugin runs with the permissions of the current DSH process. Before installation, it is recommended to review the GitHub source code and license.

Summary

context-pruner is a DSH plugin focused on context management. It implements zero-model-dependency context triage using heuristic rules. For developers who want to automatically manage context bloat in long sessions, it provides a reliable and auditable solution.

  • Plugin catalog: https://www.skillhub.cn/plugins/JohnXu22786/context-pruner
  • GitHub repository: https://github.com/JohnXu22786/context-pruner