Claude Code・Codex用handoffスキル:コンテキストが尽きる前にHANDOFF.mdを作成

Dmitriy Solodukha、Caprock開発者 · 公開日

にClaude CodeとCodexでテスト済み

Claude・Codex用の引き継ぎスキル。コンテキストが尽きる前に、目的、状態、失敗、次の手順をHANDOFF.mdに残し、次のセッションが読みます。

Claude Code(およびCodex、OpenCode、Cursor)向けのhandoffスキルは、コンテキストが尽きる前や作業を止める前に、短いHANDOFF.mdを書きます。目標、現状、理由付きの決定、試して失敗したこと、未解決の疑問、実行可能な次の手順、変更したファイルを記します。次のセッションで「前の続きから」と頼むと、そのファイルを読み、gitと照合して手順1に着手します。

handoffスキルをインストールする

エージェントごとに1コマンド。スキルはSKILL.md 1ファイルで、インストール時に何も実行しません。

9スキルをプラグインとして導入します。Claude Code内で次を入力してください:

このスキルだけを導入する場合は、プロジェクトのフォルダーで次を実行します:

全プロジェクトに導入するには -g を追加します。

handoffスキルを使うプロンプト

依頼の内容が説明と合うと、エージェントがスキルを選びます。名前を指定すると確実です。プロンプトをクリックしてコピーできます。

handoffスキルがClaude向けに記録する内容

項目はGoal、State(完了・進行中・未コミット・実行中)、Decisions、Tried and failed、Open questions、Next steps、Filesです。会話を知らない次のセッションにも使えるよう、次の規則を守ります:

  • 次の手順を実行可能に:「認証の作業を続ける」ではなく、実行するコマンドや変更する関数を書きます。
  • 失敗も残す。行き止まりの方法を再試行しないよう、正確なエラー行も残します。
  • 決定に理由を残す。次のセッションで今も適用すべきか判断できるようにします。
  • 秘密情報を残さない:トークンそのものではなく、保存場所だけを書きます。
  • エージェントとは別の言語で会話していても、リポジトリの言語を使います。

依頼なしではcommitしません。返答の最後にパスと最初の手順を示すので、最後のメッセージだけでも使えます。

実行したテストとエージェントの動作

各スキルは2026年11月29日に、専用の使い捨てリポジトリへプロジェクトスキルとしてインストールして実行しました。小さな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を書き、コミットするか無視するかを尋ね、3行のブロックで締めました。テスター自身のClaude Code設定の言語であるロシア語で書かれたため、この実行を受けてスキルに「リポジトリの言語で書く」という指示が加わりました。

Claude Code (claude -p --model sonnet)

Pick up where we left off.

読み取りモードでスキルを呼び出し、引き継ぎに従ってslugify_uniqueと5つのテストを書き、今回は英語でHANDOFF.mdを更新しました。非対話実行にない権限をテストコマンドが必要としたため、テストは実行していないと明記しました。

Codex (0.163.0, codex exec -s workspace-write)

The same write prompt as above.

.agents/skills/handoff/SKILL.mdを読み、英語で引き継ぎを書き、スキルの指示どおりに締めくくりました(リンクと引用は通常のテキストで表示):

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/skills/にプロジェクトスキルとしてインストールし、claude -p --model sonnetで検証しました。
  • Codex:2026年11月29日にCodex 0.163.0(codex exec)、.agents/skills/内のスキルで検証しました。
  • OpenCodeとCursor:未検証です。オープンなAgent Skills形式の通常の指示ですが、どちらでも実行して確認していません。

制限

  • 引き継ぎの精度は、そのセッションで確認できた範囲までです。意図の記憶ではなく、gitと会話に基づいて記述します。
  • Caprockの2nd Brainには書き込みません。MCPツールは読み取り専用です。
  • 読み取りモードを検証したのはClaude Codeだけです。

Caprockがある場合とない場合

Caprock MCPサーバーに接続している場合、引き継ぎを書く際はcurrent_decisionsとsearch_memoriesを呼び、既に有効な決定と矛盾しないようにします。読む際はファイルがなければnext_session_handoff、recent_sessions、session_summaryを使えます。Caprockがなければリポジトリと会話だけを使います。Caprockは、コンピューター上のすべてのコーディングエージェントのセッションを記録する無料のオープンソースアプリです。

Caprockを入手 →

SKILL.md全文

dspv/skillsのリビジョンdfce799にあるファイルそのものです。手動で導入する場合、プロジェクト内の、Claude Codeは.claude/skills/handoff/SKILL.md、Codexは.agents/skills/handoff/SKILL.mdに保存してください。

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スキルについての質問

Claude用handoffスキルとは?
作業を止める前に、目的、状態、決定、失敗、次の手順を短いノートに残すスキルです。説明を繰り返さず、新しいセッションや別のエージェントに引き継げます。
handoffスキルはどこに保存しますか?
既定はリポジトリ直下の`HANDOFF.md`です。既存の引き継ぎ場所や指定したパスも使えます。commitするかignoreするか確認します。
次のセッションは引き継ぎをどう使いますか?
「Read HANDOFF.md and continue」「pick up where we left off」と伝えます。ノートのブランチ、commit、未コミットファイルをgitと照合し、その後の変更を報告して最初の手順を開始します。
handoffスキルはCodexでも使えますか?
使えます。Codex 0.163.0が2026年11月29日のテストで`.agents/skills/`から読み込み、指定形式の引き継ぎを作成しました。

出典

アプリ本体の表示言語は英語です。