close

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

/close

/close

Capture learnings while context is rich, then commit and exit.
在上下文信息完整时梳理经验,然后提交并退出。

When to Use

适用场景

  • Session ending naturally (work complete)
  • Context window nearly full
  • User says "wrap up", "let's finish", "one more thing then done"
  • Main task complete and about to summarize
  • 会话自然结束(工作已完成)
  • 上下文窗口即将占满
  • 用户提及“wrap up”“let's finish”“one more thing then done”
  • 主要任务完成,即将进行总结

When NOT to Use

不适用场景

  • Mid-session checkpoint (pause and check direction instead)
  • Quick question that doesn't need handoff
  • Exploratory work with no conclusions yet
  • 会话中途检查点(此时应暂停并确认方向)
  • 无需交接的快速问题
  • 尚未得出结论的探索性工作

Structure

流程结构

Prerequisites → Verify infrastructure
Pre-flight    → Return to home directory
Gather        → todos, tracker (bon), git, drift, SESSION_ID
Orient        → Claude answers six questions in prose → user responds
Decide        → Claude proposes Now/Next plan → user amends (STOP)
Act           → execute, write handoff, stage extraction, commit
Remember      → index session (background, automatic)

Prerequisites → 验证基础设施
Pre-flight    → 返回主目录
Gather        → 待办事项、追踪器(bon)、git、偏差、SESSION_ID
Orient        → Claude用散文形式回答六个问题 → 用户回复
Decide        → Claude提出Now/Next计划 → 用户修改(暂停执行)
Act           → 执行计划、撰写交接文档、准备提取内容、提交
Remember      → 索引会话(后台自动执行)

Prerequisites

前置条件

Before running /close, verify infrastructure is healthy. Broken scripts mean lost handoffs.
CheckHowIf Broken
close-context.sh exists
[ -x ~/.claude/scripts/close-context.sh ]
Run
claude-doctor.sh
check-home.sh exists
[ -x ~/.claude/scripts/check-home.sh ]
Fix symlinks
Handoffs dir writable
[ -d ~/.claude/handoffs ]
Create:
mkdir -p ~/.claude/handoffs
Quick pre-flight:
bash
[ -x ~/.claude/scripts/close-context.sh ] && [ -x ~/.claude/scripts/check-home.sh ] && echo "OK" || echo "BROKEN"
If broken: STOP, diagnose, then write handoff manually rather than skipping closure entirely. See
~/Repos/trousse/references/ERROR_PATTERNS.md
.

运行/close前,请验证基础设施是否正常。 脚本故障会导致交接文档丢失。
检查项检查方式故障处理
close-context.sh是否存在
[ -x ~/.claude/scripts/close-context.sh ]
运行
claude-doctor.sh
check-home.sh是否存在
[ -x ~/.claude/scripts/check-home.sh ]
修复符号链接
Handoffs目录是否可写
[ -d ~/.claude/handoffs ]
创建目录:
mkdir -p ~/.claude/handoffs
快速预检命令:
bash
[ -x ~/.claude/scripts/close-context.sh ] && [ -x ~/.claude/scripts/check-home.sh ] && echo "OK" || echo "BROKEN"
若故障:立即停止,先诊断问题,再手动撰写交接文档,切勿跳过收尾流程。详情请见
~/Repos/trousse/references/ERROR_PATTERNS.md

Pre-flight: Return Home (MANDATORY)

预检:返回主目录(必填)

You may have
cd
'd during work. Your system prompt contains
Working directory: /path/...
in the
<env>
block — this is immutable, where the session actually started.
  1. Extract that exact path from your system prompt
  2. Run:
    ~/.claude/scripts/check-home.sh "/that/path"
  3. If
    CD_REQUIRED=true
    , run
    cd <HOME_DIR>
    immediately
Do not skip. Do not trust pwd. Do not reason about whether you moved back. The script is authoritative.

工作过程中你可能执行过
cd
命令切换目录。系统提示的
<env>
块中包含
Working directory: /path/...
,这是会话实际启动的不可变路径。
  1. 从系统提示中提取该精确路径
  2. 运行:
    ~/.claude/scripts/check-home.sh "/that/path"
  3. 若返回
    CD_REQUIRED=true
    ,立即执行
    cd <HOME_DIR>
请勿跳过此步骤。不要信任pwd命令的结果,也不要自行判断是否已返回主目录。脚本的判断是权威的。

Gather

收集信息

bash
~/.claude/scripts/close-context.sh
Script outputs: TIME, GIT, BON, LOCATION context, HANDOFF_DIR, SESSION_ID.
Use TIME_OF_DAY for greetings. Use YEAR to anchor the handoff date. Hold onto HANDOFF_DIR and SESSION_ID — you'll need both in Act.
bash
~/.claude/scripts/close-context.sh
脚本输出内容包括:TIME、GIT、BON、LOCATION上下文、HANDOFF_DIR、SESSION_ID。
使用TIME_OF_DAY生成问候语,使用YEAR标记交接文档日期。请牢记HANDOFF_DIR和SESSION_ID——在Act阶段会用到这两个参数。

Script Failure Handling

脚本故障处理

If the script fails (exit code 127 = file not found, or any error):
  1. STOP. Tell the user: "close-context.sh failed. Likely a broken symlink."
  2. Diagnose: Run
    ~/.claude/scripts/check-symlinks.sh
  3. Fallback: If you can't fix it, write handoff manually to
    ~/.claude/handoffs/<encoded-path>/
    — don't skip closure entirely.
Why this matters: Broken scripts (Jan 3-10 2026) meant /close ran without proper context gathering. Never continue silently.
From script output, assess:
  • Work progress — what's done, what's incomplete?
  • Tracker — Bon: open items to complete or defer
  • Git — uncommitted files? unpushed commits?
  • Drift — what did /open say we'd do vs what we actually did?
Surface stale artifacts: screenshots, temp files, old sketches, superseded plans.

若脚本执行失败(退出码127表示文件未找到,或其他错误):
  1. 立即停止,告知用户:“close-context.sh执行失败,可能是符号链接损坏。”
  2. 诊断问题:运行
    ~/.claude/scripts/check-symlinks.sh
  3. 备选方案:若无法修复,手动将交接文档写入
    ~/.claude/handoffs/<encoded-path>/
    ——切勿完全跳过收尾流程。
重要性说明:2026年1月3日-10日期间曾出现脚本故障,导致/close命令在未收集完整上下文的情况下运行。切勿静默继续执行。
根据脚本输出,评估以下内容:
  • 工作进度——已完成和未完成的工作
  • 追踪器——Bon中待完成或需延期的事项
  • Git状态——是否有未提交文件?未推送的提交?
  • 偏差——/open命令中计划的工作与实际完成的工作有何差异?
清理过时产物:截图、临时文件、旧草图、已废弃的计划。

Orient

梳理反思

This is THE reflection. What emerges here feeds the handoff and the extraction. There is no second pass later.
Answer all six questions in prose — don't compress into bullets, don't pre-bake options. The point is surfacing what you noticed that the user might not have.
Looking Back:
  1. What did we forget? — Dropped intentions, docs now stale, tests we said we'd write, files touched with untraced downstream effects
  2. What did we miss? — Edge cases, unverified assumptions, things that work in test but may not in production
  3. What could we have done better? — Simpler approaches, abstractions in the wrong place, patterns from the codebase we ignored
Looking Ahead: 4. What could go wrong? — Race conditions, silent failures, fragile dependencies, things that work now but break when X changes 5. What won't make sense later? — Why we made a particular choice, implicit knowledge not written down, non-obvious relationships between files 6. What will we wish we'd done? — Tests, verification, documentation, conversations we should have had
Share these directly, then ask: "What resonates? What am I missing?"
Wait for the user's response. Their additions and corrections go into the handoff Reflection section verbatim.

这是核心的反思环节。此阶段得出的内容将用于交接文档和记忆提取,后续不会有二次梳理机会。
请用散文形式回答所有六个问题——不要压缩为项目符号,也不要预设选项。目的是挖掘你注意到但用户可能忽略的信息。
回顾总结:
  1. 我们遗漏了什么?——未落实的计划、已过时的文档、承诺要写的测试、修改后未追踪下游影响的文件
  2. 我们忽略了什么?——边缘案例、未验证的假设、测试环境可行但生产环境可能失效的内容
  3. 我们本可以做得更好的地方?——更简单的实现方式、错误的抽象位置、未遵循的代码库模式
前瞻思考: 4. 可能出现什么问题?——竞态条件、静默故障、脆弱的依赖关系、当前正常但X变更后会失效的内容 5. 后续可能无法理解的内容?——做出特定选择的原因、未记录的隐性知识、文件间非显而易见的关联 6. 我们会后悔没做什么?——测试、验证、文档、本该进行的沟通
直接分享以上思考,然后询问:“哪些内容你有共鸣?我还遗漏了什么?”
等待用户回复。用户补充和修正的内容将原封不动放入交接文档的Reflection部分。

Decide

决策阶段

STOP. Do not execute anything until this phase completes.
From Gather + Orient, identify all incomplete work and draft a concrete plan. Present it — don't ask the user what they want. Propose; let them amend.
立即停止,完成此阶段前请勿执行任何操作。
结合Gather和Orient阶段的结果,识别所有未完成工作并制定具体计划。主动提出计划——不要询问用户需求。先给出方案,再由用户修改。

Bucket everything

工作分类

Now — executes before /exit, benefits from current context:
  • Incomplete work finishable in under 2 minutes
  • Close a tracker item with resolution notes
  • Update CLAUDE.md (local or global) when a clear pattern emerged
  • Quick fixes where the how is obvious
Bon — each becomes a tracked item for a future session. Before filing any bon, answer: "If this never gets done, what breaks?" If the answer is "not much", it belongs in the handoff Next section, not a bon. This is the gate.
Handoff only — direction, context, and risks that don't rise to bon level.
Now——在/exit前执行,可利用当前上下文:
  • 2分钟内可完成的未完成工作
  • 用解决记录关闭追踪器事项
  • 当明确模式出现时,更新CLAUDE.md(本地或全局)
  • 操作方式明确的快速修复
Bon——每个事项将成为未来会话的追踪项。在创建Bon前,请回答:“如果永远不做这件事,会有什么影响?” 如果答案是“影响不大”,则应放入交接文档的Next部分,而非Bon。这是筛选标准。
仅交接——无需追踪的方向、上下文和风险信息。

Present the plan

提交计划

"Here's my plan:
Now: [concrete list — things I'll do before /exit]
Bons to file: [each with one line on what breaks if skipped]
Handoff only: [things worth noting but not tracking]
Tell me if anything should move."
Wait for approval. Nothing executes until the user confirms or amends.

“我的计划如下:
Now: [具体列表——/exit前要完成的工作]
待创建的Bon事项: [每个事项需包含一行说明:若跳过会有什么影响]
仅交接内容: [值得记录但无需追踪的信息]
请告诉我是否需要调整。”
等待用户确认。用户确认或修改后,方可执行后续操作。

Act

执行阶段

Execute in this order.
请按以下顺序执行。

Execute "Now" items

执行“Now”事项

Do the approved immediate actions: finish incomplete todos, close tracker items with notes, update CLAUDE.md, quick fixes.
完成已确认的即时操作:完成待办事项、用记录关闭追踪器事项、更新CLAUDE.md、快速修复。

File bons

创建Bon事项

For each approved item:
bash
bon new "title" --why "consequence if not done" --what "concrete actions" --done "definition of done"
--why
quality gate:
must state the consequence of skipping, not describe the work. "Prevents next Claude rediscovering the problem from scratch" is a consequence. "Because we need to do this" is not.
对于每个已确认的事项:
bash
bon new "title" --why "不执行的后果" --what "具体操作" --done "完成标准"
--why
质量标准
:必须说明跳过的后果,而非描述工作内容。例如“避免后续Claude重新发现同一问题”是合理的后果,而“因为我们需要做这件事”则不符合要求。

Write handoff

撰写交接文档

Handoff location is non-negotiable. The script computes the path; you use it exactly.
bash
~/.claude/scripts/close-context.sh | grep -E 'HANDOFF_DIR|SESSION_ID'
This outputs both — use them directly, never recompute.
RuleWhy
Write to
{HANDOFF_DIR}/{session-id}.md
Central location, /open finds it
Never write locally (
.handoff.md
in project)
/open won't find it — information becomes invisible
Never compute path yourselfEncoding differences cause folder fragmentation
Why this matters (Jan 2026 incident): A Claude wrote to
.handoff-kube-migration.md
locally. The next session's /open loaded a stale handoff instead — the work existed but was invisible to the protocol.
Fallback: If SESSION_ID is empty (script failed), use timestamp:
2026-01-04-2215.md
Filename: first 8 chars of SESSION_ID +
.md
Example:
SESSION_ID=51d17dc5-b714-481c-9dfb-6d4128800e7b
51d17dc5.md
Handoff template:
undefined
交接文档的存储位置不可更改。脚本会计算路径,请直接使用该路径。
bash
~/.claude/scripts/close-context.sh | grep -E 'HANDOFF_DIR|SESSION_ID'
该命令会输出两个参数——请直接使用,切勿自行计算。
规则原因
写入
{HANDOFF_DIR}/{session-id}.md
集中存储,/open命令可找到
切勿写入本地(如项目中的
.handoff.md
/open命令无法找到——信息会变得不可见
切勿自行计算路径编码差异会导致文件夹碎片化
重要案例(2026年1月事件):某Claude将交接文档写入本地
.handoff-kube-migration.md
,导致下一会话的/open命令加载了过时的交接文档——工作内容存在但协议无法识别。
备选方案:若SESSION_ID为空(脚本故障),使用时间戳命名:
2026-01-04-2215.md
文件名格式:SESSION_ID的前8个字符 +
.md
示例:
SESSION_ID=51d17dc5-b714-481c-9dfb-6d4128800e7b
51d17dc5.md
交接文档模板:
undefined

Handoff — {DATE}

交接文档 — {DATE}

session_id: {SESSION_ID} purpose: {first Done bullet, truncated to ~60 chars}
session_id: {SESSION_ID} purpose: {第一个Done事项的摘要,约60字符}

Done

已完成

  • [Completions in verb form — include item ID if closing one] e.g., "Fixed auth bug (claude-go-xyz)" or "Completed migration (bon-gutowa)"
  • [动词形式的完成内容——若关闭追踪项请包含事项ID] 示例:"修复认证漏洞(claude-go-xyz)"或"完成迁移(bon-gutowa)"

Gotchas

注意事项

[What would trip up next Claude — specific, not generic]
[后续Claude可能遇到的问题——具体而非泛泛]

Risks

风险

[What could go wrong with what we built]
[我们构建的内容可能出现的问题]

Next

后续工作

[Direction for next session]
[下一会话的方向]

Artifacts

产物

[Only if Google Drive work — see Knowledge Work section]
[仅适用于Google Drive工作——见知识工作部分]

Commands

命令

Optional — verification or continuation commands

可选——验证或后续操作命令

Reflection

反思

Claude observed: [Key observations from Orient] User noted: [What they added or emphasized]
undefined
Claude观察到: [Orient阶段的关键结论] 用户补充: [用户添加或强调的内容]
undefined

Knowledge Work Context (Google Drive)

知识工作上下文(Google Drive)

When working in Google Drive (not ~/Repos): Add an Artifacts section.
You already know what you touched — you called MCP tools during the session. Recall which docs you read (
get_content
), updated (
update_doc
,
append_to_doc
), or browsed (
list_files
).
undefined
当在Google Drive(而非~/Repos)中工作时:添加产物部分。
你已了解自己操作过的内容——会话中调用过MCP工具。回忆你读取(
get_content
)、更新(
update_doc
/
append_to_doc
)或浏览(
list_files
)的文档。
undefined

Artifacts

产物

Working folder: Project Name
This session:

Knowledge work doesn't have commits. This is the equivalent. Next Claude can `get_content()` on these links to pull current state — links are stable, content is always fresh.
工作文件夹:项目名称
本次会话:

知识工作没有提交记录,此部分相当于提交记录。后续Claude可通过`get_content()`调用这些链接获取最新状态——链接稳定,内容始终是最新的。

Stage extraction for memory

准备记忆提取内容

After writing the handoff, generate a session extraction from your live context. This replaces the expensive
claude -p
subprocess the session-end hook would otherwise spawn.
Write the extraction JSON using the Write tool to
/tmp/garde-extraction.json
:
json
{
    "summary": "2-3 sentences — what happened and why it matters",
    "arc": {
        "started_with": "initial goal/problem",
        "key_turns": ["pivots, discoveries, changes in direction"],
        "ended_at": "final state"
    },
    "builds": [{"what": "thing created/modified", "details": "context"}],
    "learnings": [{"insight": "what was learned", "why_it_matters": "significance", "context": "how discovered"}],
    "friction": [{"problem": "what was hard", "resolution": "how resolved or 'unresolved'"}],
    "patterns": ["recurring themes, collaboration style, meta-observations"],
    "open_threads": ["unfinished business, deferred work"]
}
Guidelines:
  • summary
    = the "so what" — why this session mattered, not what was done
  • builds
    = concrete artifacts: code, config, docs, skills
  • learnings
    = insights that transfer to other contexts (not just "I learned X exists")
  • friction
    = things harder than expected and how they resolved
  • open_threads
    = deferred, not abandoned
Then stage it:
bash
~/.claude/scripts/stage-extraction.sh < /tmp/garde-extraction.json \
    && rm /tmp/garde-extraction.json
The script computes the correct UUID filename and places it where the hook expects. If the script is missing (fresh install before
install.sh
runs), the hook falls back to
garde process
— safe to continue.
撰写完交接文档后,从当前上下文生成会话提取内容。这将替代会话结束钩子原本会启动的昂贵
claude -p
子进程。
使用Write工具将提取内容JSON写入
/tmp/garde-extraction.json
json
{
    "summary": "2-3句话——会话内容及其重要性",
    "arc": {
        "started_with": "初始目标/问题",
        "key_turns": ["转折点、发现、方向变更"],
        "ended_at": "最终状态"
    },
    "builds": [{"what": "创建/修改的内容", "details": "上下文"}],
    "learnings": [{"insight": "学到的内容", "why_it_matters": "重要性", "context": "发现过程"}],
    "friction": [{"problem": "遇到的困难", "resolution": "解决方式或‘未解决’"}],
    "patterns": ["重复出现的主题、协作方式、元观察"],
    "open_threads": ["未完成的工作、延期的任务"]
}
指导原则:
  • summary
    = 核心价值——会话的重要性,而非具体做了什么
  • builds
    = 具体产物:代码、配置、文档、技能
  • learnings
    = 可迁移到其他场景的洞见(不只是“我了解了X的存在”)
  • friction
    = 比预期更困难的内容及其解决方式
  • open_threads
    = 延期而非放弃的工作
然后准备提取内容:
bash
~/.claude/scripts/stage-extraction.sh < /tmp/garde-extraction.json \
    && rm /tmp/garde-extraction.json
脚本会计算正确的UUID文件名并放入钩子预期的位置。若脚本缺失(
install.sh
运行前的全新安装),钩子会回退到
garde process
——可安全继续执行。

Commit

提交代码

If git dirty in the working directory:
  • Stage relevant files (handoff too if the repo is the project)
  • Commit with standard message + co-authorship
  • Push if user approves
Only commit the working directory. Other repos' dirty state is not your concern.
若工作目录的Git状态为dirty:
  • 暂存相关文件(若仓库是项目仓库,也需暂存交接文档)
  • 使用标准提交信息并添加共同作者
  • 若用户同意,推送提交
仅提交当前工作目录,无需关心其他仓库的dirty状态。

Tell user to exit

告知用户退出

Say: "Type
/exit
to close." Don't exit programmatically.

提示:“输入
/exit
以关闭会话。” 请勿以编程方式自动退出。

Remember

后台索引

Automatic — handled by session-end hook. You don't invoke this.
The hook (
~/.claude/hooks/session-end.sh
) takes one of two paths when the user runs
/exit
:
  1. Staged extraction exists (the file you wrote above):
    • garde index
      on the session (fast, no LLM)
    • garde store-extraction
      with your pre-generated JSON
    • Staging file removed
    • No subprocess spawned
  2. No staged extraction (crash, ctrl-c, no /close):
    • Falls back to
      garde process
      — spawns
      claude -p
      to extract from the raw transcript
    • Same quality, slower, costs a subprocess
Either way, handoffs are scanned afterward. Just tell the user to
/exit
.

自动执行——由会话结束钩子处理,无需手动调用。
当用户运行
/exit
时,钩子(
~/.claude/hooks/session-end.sh
)会执行以下两种路径之一:
  1. 存在已准备的提取内容(你写入的文件):
    • 对会话执行
      garde index
      (快速,无需LLM)
    • 使用你预先生成的JSON执行
      garde store-extraction
    • 删除准备文件
    • 无需启动子进程
  2. 无已准备的提取内容(崩溃、ctrl-c、未使用/close):
    • 回退到
      garde process
      ——启动
      claude -p
      子进程从原始会话记录中提取内容
    • 质量相同,但速度更慢,且需要子进程
无论哪种情况,后续都会扫描交接文档。只需告知用户输入
/exit
即可。

Anti-Patterns

反模式

PatternProblemFix
Compress Orient into bullets or optionsMisses unexpected observationsAnswer six questions in prose
Ask "what do you want?" in DecidePuts burden on user, invites deferralPropose a concrete plan; user amends
File bons with weak
--why
Future Claude can't prioritiseState the consequence of skipping
Skip pre-flight cd checkHandoff written to wrong projectAlways run check-home.sh
Write handoff locally (.handoff.md)/open won't find itUse HANDOFF_DIR from script
Silently drop incomplete workWork disappearsEvery piece in Now, bon, or handoff Next
Commit other reposUnwanted "helpful" tidyingOnly commit working directory
Recompute SESSION_ID or HANDOFF_DIREncoding drift, folder fragmentationRead from close-context.sh output

模式问题修复方案
将Orient阶段压缩为项目符号或选项遗漏意外发现用散文形式回答六个问题
在Decide阶段询问“你想怎么做?”将负担转嫁给用户,导致拖延提出具体计划,由用户修改
创建Bon时
--why
描述薄弱
后续Claude无法确定优先级明确说明跳过的后果
跳过预检的cd检查交接文档写入错误项目始终运行check-home.sh
将交接文档写入本地(.handoff.md)/open命令无法找到使用脚本输出的HANDOFF_DIR
静默丢弃未完成工作工作内容丢失所有工作必须归入Now、Bon或交接文档的Next部分
提交其他仓库不必要的“善意”整理仅提交当前工作目录
自行计算SESSION_ID或HANDOFF_DIR编码偏差、文件夹碎片化从close-context.sh输出中读取

GODAR Reference

GODAR参考对照表

Phase/open/close
GatherHandoff, tracker, scriptTracker, git, drift; HANDOFF_DIR + SESSION_ID
Orient"Where we left off"Six questions in prose → user responds
DecideUser picks directionClaude proposes Now/Bon/Handoff plan → user amends
ActDraw-down from BonExecute, write handoff, stage extraction, commit
RememberIndex session (background, automatic on /exit)
阶段/open/close
Gather(收集)交接文档、追踪器、脚本追踪器、git、偏差;HANDOFF_DIR + SESSION_ID
Orient(梳理)“上次会话进度”六个问题的散文回答 → 用户回复
Decide(决策)用户选择方向Claude提出Now/Bon/Handoff计划 → 用户修改
Act(执行)从Bon中提取任务执行计划、撰写交接文档、准备提取内容、提交
Remember(记忆)索引会话(/exit时后台自动执行)