idianzi/dsh-context-handoff ↗★ 1

dsh-context-handoff

Token-aware context handoff for DeepSeek Harness: summarize a long session into a Markdown file, compare continue-versus-switch token costs, switch auto mode from the sidebar, and resume in a fresh session.

Package
dsh-context-handoff
Compatibility
Unverified
Harness peer range
>=0.2.1-rc.3 <0.3.0
Cordis peer range
>=4.0.5 <5
Version
0.3.4
License
MIT
Last updated
Nov 1, 2026

Other repositories with this package name

Install

$npx -p @deepseek-ai/dsh dsh plugin --profile web add dsh-context-handoff

Usage

CommandEffect
/handoffWrite a handoff and report the comparison.
/handoff plan [turns]Analyze only; no model call, no file. turns is the horizon (default horizonTurns).
/handoff now [tokens]Write now with an explicit digest budget (minimum 600).
/handoff statusCurrent pressure plus the latest file.
/handoff listNewest files in the output directory.
/handoff statsAggregate the local JSONL ledger.
/handoff auto [on|off]Show or set the per-workspace auto switch.
/handoff helpHelp.

Sidebar panel

Next to the session title there is a small chip — 上下文 545k, or 自动总结 545k while auto mode is on. Clicking it expands the right sidebar and opens the handoff panel, so you do not have to know where the sidebar is. You can also open it from the right sidebar's add menu: 上下文交接 / Context Handoff.

  • Condensation is automatic and has no switch. At the recommendation point the plugin condenses once with the same backend /compact uses (compactNow from dsh-compaction-basic), replacing older history with a single summary: up to maxCompactionsPerSession times per session (default 3), and it stops early when a condense frees less than 10% of the context.
  • That backend lives inside the session's preset group (isolate: { compaction: true }), so a host-plane plugin cannot reach ctx.compaction. The plugin therefore drives it through the official command — ctx.commands.execute(agent, '/compact') — whose handler runs inside that scope and calls the same backend. The panel's compaction row reports which route was used: agent, context, command, or none.
  • A handoff only runs when the context is still over the threshold after condensing. That step is what the switch controls: off means condense only, on means write the file and start a new session.
  • The switch controls the new-session step of auto mode. It is stored in .dsh/handoff/auto.json and survives restarts.
  • The panel shows current context, the recommendation point, a progress bar, and buttons for file-only or file-plus-new-session.
  • When auto mode fires, the host writes the file, creates a new root session in the same workspace, and queues Read @... as its first message. The panel switches to it when the source session is the one on screen; otherwise it offers an Open new session button.
  • autoNewSession: true by default; set it to false to write files only.

Auto mode is per workspace and performs at most one automatic handoff per source session.

Example plan:

Context: 118k / 128k (92%), 10.0k headroom
Composition: 11.0k fixed prefix + 107k messages
Digest: 3.0k tokens (budget 3.0k)
Per-turn saving: 57.2k tokens (cache factor 0.55) · break-even 1.2 turns
Over 8 turns: saves 388k tokens after paying for the summary

Recommended now: a handoff repays itself in 1.2 turns, and the context is already at 92% of the window.
Recommendation point: 70.4k tokens (55% of window)
Earliest efficient point: 17.2k tokens over 8 turns
Cache assumption: 50% hit, cache-read weight 0.1

The file goes to .dsh/handoff/ by default and starts with YAML frontmatter, a copy-paste resume line, and then the summary. The resume workflow is:

  1. /handoff plan 10 to check the economics.
  2. /handoff when you are ready to leave.
  3. Open a fresh session and paste Read @.dsh/handoff/.md and continue from the "Next steps" section.
  4. Continue from that section; keep the old session as evidence if useful.

The output directory also contains ledger.jsonl (token numbers, model, file name, session id; no conversation text). Set ledger: false to disable it.

Configuration

- id: context-handoff
  config:
    outputDir: .dsh/handoff
    targetDigestTokens: 3000
    recommendAtRatio: 0.55
    recommendMaxTokens: 256000
    horizonTurns: 8
    auto: false
    autoNewSession: true

A bundle install already inserts the row; use - id: context-handoff to override it. For a hand-composed profile without the bundle patch, insert it explicitly:

- insert:
    - id: context-handoff
      name: dsh-context-handoff
FieldDefaultMeaning
outputDir.dsh/handoffOutput directory, relative to the workspace or absolute.
targetDigestTokens3000Digest token budget.
minDigestTokens700Lower bound for small contexts.
maxDigestTokens8000Absolute cap.
digestRatio0.03Budget as a share of current context, then clamped.
recommendAtRatio0.55Quality threshold as a window fraction.
recommendMaxTokens256000Absolute cap for the recommendation point; 0 disables it.
horizonTurns8Cost-comparison horizon; at least 2.
cacheHitRatio0.5Assumed cache hit share.
cacheReadWeight0.1Relative cache-read cost.
switchOverheadTokens1500Re-orientation cost of a new session.
keepFiles20Files kept per directory; 0 disables pruning.
autofalseDefault for workspaces without an auto.json override.
autoNewSessiontrueAuto mode creates a new session and queues the resume prompt.
autoMinGrowthTokens8000Minimum growth between auto handoffs.
autoCooldownMinutes10Cooldown between auto handoffs.
maxCompactionsPerSession3How many automatic condensations one session may get; 0 disables automatic condensation.
provider / modelemptySummarization route; empty follows the routed request or agent options. Set both or neither.
maxOutputTokens0Summary output cap; 0 derives it from the budget.
languageautoauto, en, or zh.
includeToolDetailstrueInclude tool names/short arguments in the fallback.
transcriptBudgetRatio0.7Window share for the plain-text fallback transcript.
redactSecretstrueRedact common credentials before writing.
fallbackDigesttrueWrite a deterministic digest if the model fails.
ledgertrueAppend ledger.jsonl.

Auto mode writes only when the workspace switch is on, the agent is idle, the session is not a subagent, the plan is useful, the recommendation point is crossed, this source session has not already completed an automatic handoff, and no recent handoff exists. It runs through agent.runMaintenance(), never interrupts a live turn, then creates a new root session in the same workspace with the resume prompt queued. The file remains valid if session creation fails.