dsh-context-fold: Folding Completed Context in Long Conversations

Introduction

In long conversations, the most expensive thing isn’t the history itself—it’s the already-consumed tool outputs being re-sent at every single step. The DeepSeek Harness (DSH) plugin dsh-context-fold folds up tool outputs and thinking traces at stage boundaries once their results have been established and the full text is no longer needed downstream: conclusions stay in the window, original text is spilled to a file, and it can be retrieved at any time.

Plugin Overview

dsh-context-fold is a DSH plugin developed by maintainer niechao136. It addresses the high cost of redundant context transmission in long conversations by folding completed content in a deterministic, replayable manner.

Core Features

Tool Result Folding

At stage boundaries, the plugin detects tool outputs (e.g., ops_grep). If the full output is no longer needed in subsequent steps, it gets folded. The folded output looks like this:

[context-fold] [tool: ops_grep] 12,480 chars folded at turn 3, step 7.
Conclusion: Found 3 call sites, all in src/routes.ts.
Full result: C:\Users\...\dsh-spill\xxx-tool-42.txt

The original text isn’t lost—it’s just no longer re-sent (and paid for) at every step.

Foldable Content Types

The plugin folds three categories of content:

  • Tool results: Large file reads, long logs, bulk search results, etc.
  • Thinking traces: Thinking blocks from historical tool-call turns, with a default threshold of 900 characters
  • Tool call arguments: When the same path is repeatedly written or edited, only the latest full argument set is retained; earlier ones are collapsed into a [fold:args] marker

Turn Archiving

Turns exceeding the “keep recent turns” threshold (default 5) are archived wholesale into a flat file turn-NN.md under the spill root. Only the conclusion text remains in the window. Archiving is not subject to batch-size thresholds.

Installation & Activation

Search for dsh-context-fold in the DSH plugin marketplace to install it, or add it directly to your profile:

# profile's cordis.patch.yml
- id: context-fold
  name: dsh-context-fold

Restart DeepSeek Harness after installation.

Conversation View

After installation, you’ll see a “Context Fold” tab on the right side or in the conversation area of any chat. The tab is divided into two sections:

Token Comparison — six metric cards

  • Current (post-fold): How many tokens the window actually carries
  • If never folded: How many there would be without folding (counterfactual estimate)
  • Per-step savings: How many fewer tokens are sent per request
  • Total benefit: Per-step savings × remaining steps
  • Invalidation cost: Folding busts the prefix cache, incurring a one-time recomputation cost
  • Net benefit: Total benefit − Invalidation cost

Fold Details — one row per record, newest first

  • Filterable by “Tool / Thinking / Arguments / Turn”
  • Jumpable by turn (T1, T2…)
  • Searchable by conclusion text, tool name, or spill path
  • Expanding a record loads the full original text on demand

Settings Panel

Settings → Plugins → Context Fold exposes 13 adjustable options. Changes take effect at the next fold evaluation after saving—no restart needed (config is re-read at most once per minute).

Key configuration items:

Setting Default Description
Enable folding On Toggle off temporarily to compare
Dry-run Off Strongly recommended to enable before adjusting thresholds; previews effects without modifying the session
Min tool result length 1000 Lower for more aggressive folding, but don’t go below 300
Min batch length 16000 Lowering triggers folding more frequently
Keep recent steps 6 Higher = more conservative; recent steps are left untouched
Staleness threshold (steps) 12 How many steps before content is considered “used up” within a long turn
Batch span 20 Splits ultra-long turns into batches
Fold thinking traces On Folds thinking from historical tool-call turns
Min thinking length 900 Shorter thinking blocks aren’t worth folding and are skipped
Min argument-fold length 400 Threshold for folding old arguments when the same path is repeatedly written
Fold plain-text turn thinking Off Only needed when routing would re-send it
Keep recent turns 5 Older turns are archived wholesale; lower = more savings but more recall dependency
Turn archiving On Master toggle for turn archiving

Usage

Viewing Fold Effects

Open any conversation, find the “Context Fold” tab on the right or in the conversation area, and see how many folds were applied and how many tokens were saved. Every fold record includes a spill path—expand it in the panel to read the original.

Adjusting as Needed

You can tune each threshold in the Settings panel. It’s recommended to enable “Dry-run” mode first, verify the effects, and then let changes take effect for real.

Retrieving Originals

Every fold record carries a spill path; expand it in the panel to read the full text. If a record shows “Irrecoverable,” it means the original exists only in the conversation log and no tool can retrieve it.

Applicable Scenarios

The plugin is well-suited for:

  • Large individual tool outputs (reading big files, running long logs, bulk search results)
  • Many subsequent steps that still reference the same context
  • Long conversations with multiple tool calls

The plugin is not suitable for:

  • Very short conversations
  • Cases where folding happens near the end of the conversation
  • Situations where folding busts the prefix cache and the savings don’t cover the recomputation cost

How to decide: Open the tab and check “Net benefit.” A negative number means this particular fold lost money—consider raising “Min batch length” so folding only triggers on truly large content.

Caveats

  • Folding affects model perception: the model sees “conclusion + spill path” rather than the full text
  • Archiving significantly reduces the model’s visibility into early tool calls. Lower keepRecentTurns = more savings, but more recall operations needed
  • These are estimates, not invoices. The plugin explicitly labels two modes: billing based on actual usage vs. heuristic estimate only
  • The plugin never calls the model—all decisions are pure functions of the conversation log and configuration
  • The plugin does not modify history. Fold records are independent events; the original log remains unchanged

Version Info

  • Version: 0.5.2
  • License: MIT
  • Node version requirement: ^22.19.0 || >=24.0.0
  • DSH version requirement: >=0.2.1-rc.2 || >=0.2.2-rc.1

Development

pnpm typecheck   # tsc --noEmit
pnpm test        # vitest run
pnpm build       # tsdown -> lib/
pnpm check       # runs all three in sequence

Design document: docs/specs/2026-11-12-context-fold-design.md.

羽毛球分组比赛记分
小程序二维码

欢迎使用《羽毛球分组比赛记分》微信小程序

Xiaoye