session-handoff
Session Handoff
Mode Detection
First, determine which mode to run:
- GENERATE mode — user has a long current conversation and wants to summarize it for a new session
- LOAD mode — user is in a new/fresh session and wants to retrieve a previously saved summary
GENERATE Mode
Step 1: Compress the conversation
Scan the full conversation history. Ruthlessly discard: greetings, failed attempts, intermediate reasoning, repetition.
Extract only:
| Category | What to capture |
|---|---|
| 背景 | Why this work exists, what system/project is involved |
| 目标 | The concrete end state being worked toward |
| 约束 | Hard limits: tech stack, style rules, user preferences |
| 已完成 | Files changed, decisions made, problems solved |
| 已确认事实 | Things verified, tested, or explicitly agreed upon |
| 未解决 | Bugs, questions, blockers not yet resolved |
| 下一步 | The single most important action to take next |
Label every fact:
[confirmed]— tested, verified, or explicitly agreed[pending]— assumed, planned, or not yet verified
Step 2: Produce two versions
极简版(token-saving):
## 背景
[1-2 sentences]
## 目标
[1 sentence]
## 已做
- [confirmed] item
## 未解决
- [pending] item
## 下一步
[single action]
标准版(ready to work):
## 背景与目标
[2-4 sentences]
## 约束
- [confirmed] constraint
## 已完成工作
- [confirmed] what + outcome
## 已确认事实
- [confirmed] fact
## 待确认 / 未解决
- [pending] open question
## 下一步建议
1. Immediate action
2. Follow-up (if any)
Step 3: Save to file
Save the standard version to ~/.claude/session-handoffs/ with filename YYYY-MM-DD_HH-MM-SS.md.
Then enforce the 10-file limit: list all files in that directory sorted by name (oldest first), delete any beyond the 10 most recent.
mkdir -p ~/.claude/session-handoffs
# Write file, then:
ls -1 ~/.claude/session-handoffs/*.md | sort | head -n -10 | xargs rm -f 2>/dev/null
Step 4: Output the ready-to-paste block
After the two versions, output this block (use the minimal version inside):
---
📋 复制以下内容粘贴到新窗口:
[极简版完整内容]
> 继续之前的工作:[goal]。请从"[next step]"开始。
---
Tell the user: 已保存到 ~/.claude/session-handoffs/YYYY-MM-DD_HH-MM-SS.md,也可在新窗口用"加载历史会话"直接读取。
LOAD Mode
Step 1: List available summaries
ls -1t ~/.claude/session-handoffs/*.md 2>/dev/null
If no files exist, tell the user: 暂无保存的会话摘要。
Step 2: Show the list
Display filenames with index, newest first. Show the first line of each file as a hint if possible.
Example output:
找到以下历史会话摘要:
[1] 2026-04-29_14-32-10.md (最新)
[2] 2026-04-28_09-15-44.md
[3] 2026-04-27_21-03-22.md
输入编号查看详情,或直接说"加载第1份"。
Step 3: Load selected file
Read and display the full content of the selected file. Then ask:
已加载摘要。你想从"[next step from summary]"继续,还是先确认一下背景?
Rules
- Omit any section that has nothing meaningful to say
- Prefer bullet points over prose
- GENERATE mode: always save the file, even if the conversation is short
- LOAD mode: always show the list first, don't auto-load without user selection