handoff-baton
well-weiluo/handoff-baton
上下文将满时,自动判断、归档并生成跨模型接棒码的 DeepSeek Harness 插件与通用技能。
安装
dsh plugin --profile web add github:well-weiluo/handoff-batonREADME
Task Handoff Baton · dsh-handoff-baton
English | 简体中文
Turn "one conversation that keeps growing" into "one document plus one marker".
A DeepSeek Harness plugin, a model-agnostic skill, and a zero-dependency CLI. When the context is about to run out, it turns the current work into a seven-section handoff document, files it in an index, and emits a continuation phrase a new session can act on directly.
Why a handoff at all
A long conversation is charged on every request: 300k tokens of history are replayed each turn. In a real 30-day bill, 57% of the spend went to cached context replay, at an average of 359k tokens per request.
Opening a new session has always been cheaper. The reason it rarely happens is the retelling — requirements, progress, constraints, and what not to touch. This plugin turns that retelling into one symbol.
What's in the box
| Piece | What it does |
|---|---|
Protocol baton:v1 | An HTML comment header plus seven sections. Plain Markdown, so any model that can read files can consume it. |
Skill baton-handoff | Decides when a handoff is due, checks your existing archive convention, asks before writing, then writes, verifies, files, and emits the phrase. |
| Plugin | Two tools, one /baton command, one pressure nudge. |
CLI baton | 15 subcommands, no dependencies, Node >= 20. Works without the plugin and without the host. |
The seven sections are: Goal / Status / Key files / Blockers / Next / Constraints / Evidence.
Install
# DSH plugin (profile: desktop or web; restart afterwards)
dsh plugin --profile desktop add dsh-handoff-baton
# or from a local directory
dsh plugin --profile desktop add "file:/absolute/path/dsh-handoff-baton"
After the restart: the plugin page reads "任务交接棒" (Task Handoff Baton), the skill is baton-handoff, the tools are baton_check and baton_handoff, and the command is /baton.
Pick up a handoff
In the new session, make this the first message:
⟦baton⟧ handoff/2026-11-29-0045-x.md
A bare ⟦baton⟧ continues from the single live entry in the global index, but only when exactly one entry is live. With several live, it lists the candidates and asks instead of guessing: picking the wrong task in a zero-context session is silent and expensive. If the one live entry points at a file that no longer exists, it reports that instead of hunting for a substitute.
Only the first non-empty line counts. Anything without the marker is ordinary chat, so the skill cannot misfire. ASCII fallbacks: <<baton>>, [[baton]].
For another model, or a host without the skill installed, use the long form:
⟦baton⟧ 读 handoff/2026-11-29-0045-x.md(交接棒 v1 协议),从「下一步」第 1 条继续。
- 只按「关键文件」读真正需要的文件,别全量加载
- 动文件前先跟我确认
Slash commands
| Command | Effect |
|---|---|
/baton | Write a handoff. Asks for confirmation before anything is written. |
/baton <名称> | Same, with a name: an optional short label (≤ 24 chars) shown first in lists. |
/baton pick [path or 名称] | Continue from a handoff. Without an argument it resolves the index; a name that matches several entries lists them and asks. |
/baton scan [dir] | Find unregistered handoff documents (report only, writes nothing). |
/baton doctor | Check the catalog, the index, every route, and the AGENTS.md rule block. |
/baton snippet | Print the AGENTS.md rule block. |
/baton status | Context usage plus an index summary. |
/baton list | List handoffs grouped by status, newest first. |
/baton find [term] | Filter by name / title / id / path. |
/baton show <term> | One handoff in detail: path, id, sections digest. |
/baton help | Usage. |
/baton and /baton pick only queue a sentence for the next turn; the model still writes the document. status and list answer immediately and cost no model call.
One index per machine
The index is a single file — default $DSH_HOME/baton/INDEX.md. Its location is recorded in $DSH_HOME/baton/location.json and mirrored in the baton:catalog block of your AGENTS.md (baton snippet prints it). Lookup order: --catalog → BATON_ROOT → location.json → the default. When none exists, commands say so instead of creating a second index next to your code. That was the failure mode: one index per working directory, invisible from the next session.
Documents may live anywhere. The row records where:
- [Audio pipeline](projects/audio/20261129-0939-audio.md) — 进行中 · 2026-11-29T09:39 · audio · #转录
- The trailing
· #名称is the optional name: a user-defined subtitle (≤ 24 characters, no·,[,],#,|or line breaks) thatbaton listshows before the title, so you recognise the handoff at a glance. No name means lists fall back to the title. Names may repeat;pickdisambiguates by asking. - A bare filename means "next to the index"; a relative path is relative to the index directory; an absolute path points into a project. Moving a project keeps the document — only the row needs fixing, and a row whose file is gone is reported, never guessed around.
- States: 进行中 (open) → 已接手 (picked up) → 已关闭 (closed). "Live" means open or picked up, and ordering uses the update time, not the creation time.
- The receiving session flips a line to 已接手 after reading; the sender flips it to 已关闭 when the task ends.
baton touch <file> --status ...does it in one command. baton resolvedecides what a bare marker means: one live target (exit 0), several candidates (exit 2), none or a dead route (exit 1).baton doctorchecks the catalog, the index, whether every row still resolves, and whether theAGENTS.mdrule block is present — filesystem only, no model tokens.baton scanfindsbaton:v1documents that were never registered (e.g. a project copied to a new machine);baton adoptregisters them.baton sync [--fix]reconciles documents that sit next to the index.baton pruneonly moves documents that really live inside the catalog (checked via realpath, so symlinks and junctions pointing outside are never followed) intoarchive/; documents in projects just lose their row. It reports by default and never deletes.
Drift check
Before continuing from an older handoff, baton drift verifies three facts in one pass: the key files it lists still exist, whether they changed after the document was written, and how many commits the repository moved since. It runs only when the document is older than 12 hours, so a same-day handoff pays nothing; --force overrides, --stale-hours tunes the gate.
The check is filesystem and git only — no model call, no rewriting, no verdict. Its output is evidence plus one line of advice: re-read the files it names before trusting the document.
CLI
node bin/baton.mjs init [--dir <location>] [--force] # first run: pick where the index lives
node bin/baton.mjs doctor [--json] # catalog / index / routes / AGENTS.md block
node bin/baton.mjs snippet # the AGENTS.md rule block to paste
node bin/baton.mjs check --tokens 300000 --window 800000
node bin/baton.mjs write --json payload.json [--dir <doc dir>] [--catalog <index dir>] [--dry-run] [--quiet]
node bin/baton.mjs new --title "标题"
node bin/baton.mjs adopt <file...> # register an existing baton:v1 document
node bin/baton.mjs scan [--roots a;b] [--adopt] # find unregistered documents
node bin/baton.mjs update 2026-11-29-0045-x.md --json payload.json
node bin/baton.mjs verify 2026-11-29-0045-x.md [--strict]
node bin/baton.mjs code 2026-11-29-0045-x.md [--long]
node bin/baton.mjs entry "⟦baton⟧ x.md"
node bin/baton.mjs archive x.md [--status 进行中]
node bin/baton.mjs list [--open] [--paths]
node bin/baton.mjs find [term] [--status S] [--since 7d] [--workspace W]
node bin/baton.mjs show <term|id> [--json]
node bin/baton.mjs set <term> [--name X] [--title Y] [--workspace W]
node bin/baton.mjs rm <term> [--doc keep|archive|delete] [--yes] [--all] [--force]
node bin/baton.mjs close <term> / reopen <term>
node bin/baton.mjs status [--stale-days 7] [--closed-days 30] [--max-closed 20]
node bin/baton.mjs drift 2026-11-29-0045-x.md [--workspace <dir>] [--force]
node bin/baton.mjs resolve [--json]
node bin/baton.mjs touch <file|path> [--status 进行中|已接手|已关闭]
node bin/baton.mjs sync [--fix]
node bin/baton.mjs prune [--older-than 30] [--apply]
Configuration
| Key | Default | Meaning |
|---|---|---|
registerSkill | true | Register the baton-handoff skill |
registerTools | true | Register baton_check / baton_handoff |
registerCommand | true | Register /baton |
catalogDir | '' | Index location; empty means auto-detect (BATON_ROOT, then $DSH_HOME/baton) |
docsDir | '' | Where documents are written; empty means next to the index |
defaultDir | — | Deprecated alias for docsDir |
nudge | true | Pressure reminders |
minTokens | 0 | Stay quiet below this usage; reduces noise, never changes the thresholds |
warnRatio | 0.6 | Halfway warning |
handoffRatio | 0.8 | Handoff threshold |
staleDays | 7 | Days without an update before an entry counts as stuck |
closedDays | 30 | Days before a closed entry is eligible for archiving |
maxClosed | 20 | Closed entries above this prompt a cleanup |
How reminders work
The plugin subscribes to two host events: session/event for token usage and the context window, and agent/pre-step to decide at every step — the reminder fires at the crossing step, not only at the first step of a turn.
Detection runs in the plugin process and costs no tokens. Only when a threshold is crossed does it inject a single line (about 25 tokens), at most once per session per tier — at 60%, at 80%, and after a compaction. There is no per-turn polling and no periodic prompt.
Portability
- Whole package:
skills/+bin/+lib/. Copy it anywhere Node >= 20 exists. - Skill only: copy
skills/baton/and write documents by hand; the CLI is optional. - Claude Code: place it at
~/.claude/skills/baton-handoff/— the directory name must match the frontmattername. - Codex / Cursor / others: merge
SKILL.mdintoAGENTS.mdor.cursor/rules, and keepreferences/PROTOCOL.mdbeside it.
Limits
- Triggering still depends on the model or on you typing the command.
- Without host usage data, reminders switch off entirely.
- A timestamp cannot tell "actively worked" from "abandoned", so stuck-entry wording is a question, not a verdict.
- The index is not a backup of the conversation; export the original session separately if you need it.
- Verified mainly on Windows with DSH; cross-model was verified at the document level, not as a live trigger in another client.
License
MIT