ClaudeMods
☰
ZH-CN
● 0 人在线 · 浏览 0 次
赞助提交作品
GitHub 仓库 · 发布者 Akash001uts

context-handoff

在会话变长时平稳交接:达到上下文阈值后 Claude 更新文档并写入交接记录,会话带着指令压缩,然后由启动提示继续执行。提供实时上下文读数和 /wrap-up 技能

Akash001uts@Akash001uts

Akash001uts/claude-mods/tree/main/plugins/context-handoff

已翻译

关于这个 mod

context-handoff

会话变长后,Claude 往往更难跟上进度,而自动压缩也不总能保留真正需要的部分。这个 mod 会妥善交接工作。它适合无法在一个上下文窗口内完成的较长工作,例如完整作业、持续几天的项目或大型重构。没有它时,我每次压缩前都要手写“我们目前进行到这里”的笔记。

工作方式

当上下文窗口达到阈值(默认 50%)时:

  1. Claude 会被要求收尾。它会更新项目已有的文档,写入交接文件(.claude/handoff.md),并起草压缩指令和启动提示。
  2. mod 会用这些指令运行 /compact,让摘要保留重要内容。
  3. 压缩完成后,它会发送启动提示,Claude 会从交接文件继续工作。

它也能让 Claude 看到上下文有多满。每个提示都会得到一行隐藏信息,例如 Context window: 34% used (68.0k of 200.0k),并且会被告知在窗口逐渐填满时建议收尾(只建议一次,而且只在任务确实完成时)。如果你在会话结束时自行运行 /context-handoff:wrap-up,下次在该项目中打开会话时,启动提示就会等在提示框里。

命令和设定

  • 状态列会显示 Handoff at 50%,表示功能已启用;交接进行时还会显示当前步骤。
  • /handoff 会立即开始交接,无论当前上下文占用多少。
  • /handoff 60(或 /handoff at 60%)会改变自动交接开始的时机。任何 5% 到 95% 之间的值都可以,并会保存到插件的设置中,在会话之间保持不变。
  • /handoff off 和 /handoff on 会暂停或恢复当前会话的自动交接。
  • /handoff status 会显示当前读数和设置,/handoff resume 会把已保存的启动提示放回提示框。
  • 在 /config 中可以修改 mode:auto(默认)会自行完成全部工作,ask 会把交接提示放进提示框供你发送,off 只把读数显示给 Claude。handoffPath 会改变交接文件的位置。
  • 它只会从主对话交接,而且只会在一轮正常结束后交接。如果你中断一轮,它会取消;Claude Code 自己的自动压缩也不会触发启动提示。

运行和储存的内容

  • 它从 Claude Code 读取会话的上下文使用量(已使用百分比、已使用 token、窗口大小)。它不会把任何内容发送到 Claude Code 之外。
  • 它提交的提示。 交接开始时,它会提交收尾提示。该提示只包含当前上下文百分比和窗口大小、交接文件路径、上述步骤,没有其他内容。压缩后,它会提交 Claude 写出的启动提示。在 ask 模式中,它只会填入提示框,由你决定是否发送。会话开始时,它也可以把保存的启动提示放进提示框(不会发送)。
  • 它对提示所做的改变。 你发送的每个提示都会多出一行隐藏的上下文读数,例如 [context-handoff] Context window: 34% used (68.0k of 200.0k); handoff at 50%. 你的文字不会改变。
  • 它加入系统提示的内容。 一段简短指南,说明这行信息的含义、在任务自然结束时建议收尾一次,以及交接文件的位置。
  • 它运行的命令。 每次交接只运行一次 /compact,而且是在 Claude 调用 handoff_ready 且这一轮结束之后。它会把 Claude 的压缩指令作为参数传入。
  • 它自己的工具。 它增加一个 handoff_ready 工具,Claude 会在收尾结束时调用它。mod 自己会回应这个调用:保存启动提示和压缩指令(或在会话结束时保存下次使用的启动提示),然后回复 Claude。它不会接触其他工具。你的正常权限规则仍适用,因此第一次可能会看到提示;如果不想被询问,可以把 mcp__context-handoff__handoff_ready 加入允许规则。
  • 它修改的设定。 /handoff 60 会把阈值保存为这个插件的 threshold 设定(与 /config 中相同)。它不会修改其他内容,也不会接触环境变量。
  • 收尾期间由 Claude(不是 mod)编辑项目已有文档并写入交接文件,使用它平常的工具,因此通常的权限提示仍会生效。
  • 启动提示会保存在 Claude Code 的插件储存中,并按项目建立索引,因此可以在下次会话提供。使用后会删除。

安装

请先查看作者 README 确认 marketplace 和插件名称;命令可能随仓库结构改变。

claude plugin marketplace add Akash001uts/claude-mods
claude plugin install context-handoff
原文 / README

context-handoff

Once a session gets long, Claude tends to get worse at keeping track of things, and auto-compact doesn't always keep the parts you actually need. This mod hands the work off properly instead. It's for longer pieces of work that don't fit in one context window, like a full assignment, a project spread over a few days, or a big refactor. Without it I was writing "here's where we're up to" notes by hand before every compact.

How it works

When the context window hits a threshold (50% by default):

  1. Claude gets asked to wrap up. It updates the docs your project already has, writes a handoff file (.claude/handoff.md), and drafts compaction instructions plus a kickoff prompt.
  2. The mod runs /compact with those instructions, so the summary keeps what matters.
  3. Once compaction finishes, it sends the kickoff prompt and Claude picks up from the handoff file.

It also lets Claude see how full the context is. Each prompt gets a hidden line like Context window: 34% used (68.0k of 200.0k), and Claude's told to suggest wrapping up (once, and only when a task is actually finished) if the window is filling up. If you run /context-handoff:wrap-up yourself at the end of a session, the kickoff prompt will be waiting in the prompt box next time you open a session in that project.

Commands and settings

  • The status line shows Handoff at 50% so you know it's armed, and shows what step it's on while a handoff runs.
  • /handoff starts a handoff straight away, whatever the context level.
  • /handoff 60 (or /handoff at 60%) changes when the automatic handoff starts. Anything from 5% to 95% works, and it saves to the plugin's settings so it sticks between sessions.
  • /handoff off and /handoff on pause or resume the automatic handoff for the current session.
  • /handoff status shows the current reading and settings, and /handoff resume puts a saved kickoff prompt back in the box.
  • In /config you can change mode: auto (the default) does everything itself, ask puts the handoff prompt in the box for you to send, and off just shows Claude the reading. handoffPath changes where the handoff file goes.
  • It only hands off from the main conversation, and only after a turn finishes normally. If you interrupt a turn it cancels, and Claude Code's own auto-compact never triggers the kickoff prompt.

What it runs and stores

  • It reads the session's context usage from Claude Code (percentage used, tokens used, window size). It doesn't send anything outside Claude Code.
  • Prompts it submits. When a handoff starts, it submits the wrap-up prompt. That prompt contains the current context percentage and window size, the handoff file path, and the steps above, nothing else. After compaction it submits the kickoff prompt Claude wrote. In ask mode it only fills the prompt box and you decide whether to send. At the start of a session it can also put a saved kickoff prompt in the prompt box (it doesn't send it).
  • What it changes in prompts. Each prompt you send gets one extra hidden line with the context reading, like [context-handoff] Context window: 34% used (68.0k of 200.0k); handoff at 50%. Your own text isn't changed.
  • What it adds to the system prompt. A short guide telling Claude what that line means, to suggest wrapping up once at the natural end of a task, and where the handoff file goes.
  • Commands it runs. Only /compact, once per handoff, after Claude has called handoff_ready and the turn has finished. It passes Claude's compaction instructions as the argument.
  • Its own tool. It adds one tool, handoff_ready, which Claude calls at the end of a wrap-up. The mod answers that call itself: it saves the kickoff prompt and compaction instructions (or, at the end of a session, saves the kickoff prompt for next time) and replies to Claude. It doesn't touch any other tool. Your normal permission rules apply to it, so you may get a prompt the first time; add mcp__context-handoff__handoff_ready to your allow rules if you don't want to be asked.
  • Settings it changes. /handoff 60 saves the threshold as this plugin's threshold setting (the same one in /config). It doesn't set anything else or touch environment variables.
  • Claude (not the mod) edits your project's existing docs and writes the handoff file during a wrap-up, using its normal tools, so your usual permission prompts still apply.
  • The kickoff prompt is saved in Claude Code's plugin storage, keyed to the project, so it can be offered next session. It's deleted once it's used.

Licence

MIT

其他同名作品

更多类似作品