适用于 Claude Code 和 Codex 的交接 skill:在上下文耗尽前写好 HANDOFF.md
Dmitriy Solodukha,Caprock 开发者 · 发布于
测试于 (Claude Code 和 Codex)
适用于 Claude 和 Codex 的交接 skill:在上下文耗尽前写入 HANDOFF.md(目标、状态、失败的尝试、下一步);下一个会话会读取它。
适用于 Claude Code(以及 Codex、OpenCode、Cursor)的 handoff skill 会在上下文耗尽或你停止前写一份简短的 HANDOFF.md:目标、当前进展、决策及原因、尝试过但失败的方法、待解决的问题、可执行的后续步骤和触及的文件。在下一次会话中,输入“pick up where we left off”会让它读取该文件,与 git 核对,并从第 1 步开始。
安装 handoff skill
每个智能体只需一条命令。skill 只有一个 SKILL.md;安装时不会运行任何内容。
将全部九个 skill 作为插件安装。在 Claude Code 中输入以下内容:
也可以只安装这个 skill,在终端中进入项目文件夹后运行:
添加 -g 即可为所有项目安装。
在终端中进入项目文件夹后运行:
添加 -g 即可为所有项目安装。
在终端中进入项目文件夹后运行:
添加 -g 即可为所有项目安装。 尚未在 OpenCode 上测试:这个 skill 是采用开放格式的纯文本指令,但还没有在 OpenCode 上实际运行验证。
在终端中进入项目文件夹后运行:
添加 -g 即可为所有项目安装。 尚未在 Cursor 上测试:这个 skill 是采用开放格式的纯文本指令,但还没有在 Cursor 上实际运行验证。
使用 handoff skill 的提示词
你的措辞与 skill 描述匹配时,智能体会选择它;直接指定 skill 名称更有把握。点击提示词即可复制。
handoff skill 为 Claude 写入什么
文件包含固定部分:目标、状态(已完成、进行中、未提交、运行中)、决策、失败的尝试、待解答的问题、下一步、文件。以下规则让完全没有这段对话内容的新会话也能用上它:
- 下一步可直接执行:要运行的命令或要修改的函数,而不是“continue the auth work”。
- 保留失败记录,附上准确的报错行,避免再次尝试行不通的方法。
- 决策附带原因,让下个会话能判断某条是否仍然适用。
- 不含机密信息:只说明 token 存放的位置,不写出 token 本身。
- 使用仓库的语言编写,即使你用另一种语言与智能体对话。
除非你提出要求,否则它不会提交该文件。回复末尾会附上路径和第一步,让最后一条消息本身就足以说明如何继续。
我们运行了什么,智能体做了什么
每个 skill 都于 2026年11月29日在为其专门创建的临时仓库中运行,并作为项目 skill 安装。测试使用一个小型 Python 仓库,slug.py 中包含未完成的 slugify_unique 桩代码,以及相应测试。
Claude Code (claude -p --model sonnet)
I'm about to run out of context. Write a handoff for the next session: I was adding slugify_unique to slug.py (append -2, -3 when the slug is taken); I decided not to use a global set because tests must stay independent. Tried python-slugify, dropped it: no new dependencies.
调用了 handoff,严格按指定结构写入 HANDOFF.md,询问是提交还是忽略该文件,并以三行文本块结尾。文件使用俄语,这是测试者自己的 Claude Code 设置语言;正是这次运行促使 skill 加上了使用仓库语言编写的要求。
Claude Code (claude -p --model sonnet)
Pick up where we left off.
以读取模式调用 skill,按交接说明操作,编写了 slugify_unique 和五个测试,并更新了 HANDOFF.md,这次用的是英语。它明确说明没有运行测试:测试命令需要一项权限,而非交互式运行没有该权限。
Codex (0.163.0,codex exec -s workspace-write)
The same write prompt as above.
读取了 .agents/skills/handoff/SKILL.md,用英语写了交接记录,并按 skill 要求结束(链接和引文以纯文本显示):
Handoff written to HANDOFF.md. Next session: "Read HANDOFF.md and continue." First step: implement the collision loop in `slug.py:8`.
已测试的智能体
- Claude Code:测试于 2026年11月29日,使用
claude -p --model sonnet,skill 作为项目 skill 安装在.claude/skills/中。 - Codex:于 2026年11月29日使用 Codex 0.163.0(
codex exec)测试,skill 位于.agents/skills/。 - OpenCode 和 Cursor:未测试。此 skill 是以开放的 Agent Skills 格式编写的纯文本指令,但尚未在这两者上实际运行验证。
限制
- 交接是否可靠,取决于会话能核实哪些内容:智能体根据 git 和对话撰写交接记录,而不是凭记忆回想原本的意图。
- 它不会写入 Caprock 的 2nd Brain:Caprock 的 MCP 工具是只读的。
- 读取模式仅在 Claude Code 上测试过。
使用和不使用 Caprock 的情况
连接 Caprock MCP 服务器后,写交接记录时会调用 current_decisions 和 search_memories,确保记录不与已生效的决策冲突;读取交接记录时,如果没有文件,可改用 next_session_handoff、recent_sessions 和 session_summary。没有 Caprock 时,仅使用仓库和对话。Caprock 是免费开源应用,记录你电脑上的每个编程智能体会话。
完整的 SKILL.md
这是 dspv/skills 中修订版本 dfce799 的文件原样。手动安装时,将它保存在项目中:Claude Code 使用 .claude/skills/handoff/SKILL.md,Codex 使用 .agents/skills/handoff/SKILL.md。
--- name: handoff description: > Write a handoff for the next session or another agent before the context runs out or work stops: the goal, where things stand, decisions and why, what was tried and failed, open questions, exact next steps and the files touched, saved where the next session will find it (HANDOFF.md in the repository by default). Also reads the last handoff when a session starts. Use when the user says "write a handoff", "handoff skill claude", "hand this off", "save context for the next session", "I'm out of context", "wrap up for today", "pick up where we left off", "resume from the handoff" or "what was the last session doing". license: Apache-2.0 --- # Handoff A handoff is a short note that lets a fresh session, with none of this conversation, continue the work without asking the user to repeat anything. Write it from facts you can check (the repository, the commands you ran, what the user said), not from memory of what you meant to do. Two modes. Pick by what the user asked: - **Write**: the user wants to stop, the context is nearly full, or work moves to another agent. Go to "Writing a handoff". - **Read**: a session starts and the user says "continue", "pick up where we left off" or points at a handoff. Go to "Reading a handoff". ## Writing a handoff ### 1. Collect the facts Run these in the repository root and keep the output in mind (do not paste it whole): ```bash git status --short git branch --show-current git log --oneline -10 git diff --stat git stash list ``` Also note: commands you ran that passed or failed (tests, builds, checks) and their last result; any background process still running (a dev server, a watcher) and how it was started; anything the user decided or asked for in this conversation, in their words. If the Caprock MCP tools are available (server `caprock`), call `current_decisions` for this project and `search_memories` with the task's main words. Use them to check the handoff does not contradict a decision already in force, and to link a decision instead of retelling it. Caprock (<https://caprock.dev>, free, open source, runs locally) provides these tools; without them, rely on the repository and this conversation. ### 2. Write the file Default location: `HANDOFF.md` in the repository root. Use another place only if the user names one or the repository already keeps handoffs elsewhere (look for `HANDOFF.md`, `docs/handoff*`, `.handoff/`). If a `HANDOFF.md` exists, read it first: replace it with the new one, and carry over anything from it that is still open. Use exactly this structure. Leave a section out only when it would be empty, and say "none" for open questions rather than dropping the heading. ```markdown # Handoff: <task in a few words> Written <YYYY-MM-DD HH:MM, timezone> by <agent and model, if known>. Branch `<branch>`, last commit `<short sha> <subject>`. ## Goal <One or two sentences: what the user wants and what "done" looks like.> ## State - Done: <what is finished and verified, with how it was verified> - In progress: <what is half-done, where exactly it stops> - Uncommitted: <files changed but not committed, or "nothing"> - Running: <background processes and how to stop them, or "nothing"> ## Decisions - <decision>: <why>. <who decided: the user, or you with the reason> ## Tried and failed - <approach>: <what happened, the error or the reason it was dropped> ## Open questions - <question> (who can answer: the user, a doc, a test) ## Next steps 1. <first concrete action: a command to run or a file and function to change> 2. <...> ## Files - `<path>`: <what changed or why it matters> ``` Rules for the content: - **Next steps are executable.** "Run `npm test -- auth` and fix the two failures in `src/auth/session.ts`" is a step; "continue the auth work" is not. The first step is the one the next session does in its first minute. - **Failures are kept.** A dead end not written down gets tried again. Include the exact error line when there is one. - **Decisions carry the reason.** Without the reason the next session cannot tell whether it still applies. - **Absolute dates and exact names.** "2026-12-01", a branch name, a file path, a command; never "tomorrow" or "the config file". - **No secrets.** Never copy a token, password, key or private URL into the handoff. Name where it lives (an environment variable, a keychain entry) instead. - **The repository's language.** Write the handoff in the language the repository's docs and commits use, even when you talk to the user in another; the next session may be another agent. - **Short.** Aim for a page. A long log or diff stays in git; the handoff points at it. ### 3. Tell the user Do not commit the handoff unless the user asks. Ask once whether `HANDOFF.md` should be committed or added to `.gitignore` if the repository has neither. End your reply with: ```text Handoff written to <path>. Next session: "Read <path> and continue." First step: <step 1 from the file> ``` Also print the Goal, State and Next steps sections in that final reply. Some tools (Caprock's `next_session_handoff`, when the user has it switched on) hand a new session the last passage the previous session wrote, so the final message should stand on its own. ## Reading a handoff ### 1. Find it Look in this order and use the first that exists: 1. a path the user gave; 2. `HANDOFF.md` in the repository root, then `docs/handoff*` and `.handoff/`; 3. with the Caprock MCP tools: `next_session_handoff` (the memories and current decisions a new session in this repository gets, and when the last session left off), then `recent_sessions` and `session_summary` on the newest session for its files and branch. If nothing is found, say so in one line and ask what to work on. Do not invent a previous state. ### 2. Check it against the repository A handoff can be stale. Before acting on it: - compare its branch and last commit with `git branch --show-current` and `git log --oneline -5`; - check that "Uncommitted" matches `git status --short`; - note how old it is from its date. If anything disagrees (new commits, a different branch, the files already committed), trust the repository and say what changed since the handoff. ### 3. Report and start Reply with, in this order: ```text Handoff from <date>: <goal in one line>. Since then: <"nothing changed" or what differs in git>. Open questions: <list, or "none">. Starting with: <step 1>. ``` If an open question blocks step 1, ask it and wait. Otherwise do step 1. When the task is finished, delete `HANDOFF.md` or replace it with a new handoff, so the next session does not pick up work that is already done. ## Stop conditions - The handoff is written and the user has the path and the first step: stop writing. - The handoff names a step that needs the user (a decision, a credential, a review): ask, do not guess. - The repository disagrees with the handoff on what is committed: follow the repository and say so before doing anything else.
关于 handoff skill 的问题
- Claude 的 handoff skill 是什么?
- 这个 skill 让 Claude Code 在停止工作前写一份简短记录,包含目标、状态、决策、失败的尝试和下一步。这样,新会话或另一个智能体就能接着做,无需你重复任何内容。
- handoff skill 把笔记存在哪里?
- 默认保存在仓库根目录的 `HANDOFF.md`,也可以放在仓库已有的交接记录位置,或你指定的路径。它会询问要提交这个文件还是忽略它。
- 下一个会话如何使用交接记录?
- 说“Read HANDOFF.md and continue”或“pick up where we left off”。skill 会用 Git 核对笔记中的分支、提交和未提交文件,报告之后发生的变化,然后开始执行第一步。
- handoff skill 能用于 Codex 吗?
- 可以。在 2026年11月29日的测试中,Codex 0.163.0 从 `.agents/skills/` 读取 skill,并按其结构编写了交接笔记。