⚠️ 源单薄性声明 本条目只有 1 份官方 doccheckpointing.md 95 行 + agent-sdk/file-checkpointing.md)。没有社群救场案例、没有 checkpoint 失效事故。 已讲清楚:checkpoint 是什么、怎么 rewind、三种恢复选项 还没听到:什么时候 checkpoint 不够用、和 git 怎么配合 本条目是基础功能说明,不是最佳实践。

一句话

Checkpointing = Claude 在改文件之前自动存一份快照,你随时可以 /rewind 回到某个时刻。

它自己做的

来源:checkpointing.md 的 “How checkpoints work” 段。

Claude Code 默认就开着:

  • 每个用户 prompt 之前创建一个新 checkpoint
  • 跨 session 持久化——下次 resume 还在
  • 自动清理——30 天后随 session 一起清掉(可配)
  • 只跟踪 Claude 文件编辑工具的改动(不是你手动改的)

不用你配置任何东西

怎么用(/rewind

Esc 两次 或输入 /rewind——弹出你这次 session 的所有 prompt 列表,选一个点执行恢复。

四个动作

checkpointing.md 列的选择菜单:

动作作用
Restore code and conversation代码和对话都回到那个点
Restore conversation只回滚对话,保留当前代码
Restore code只回滚代码,保留对话
Summarize from here把选中点之后的对话压成摘要(腾 context)

三种 restore 的区别非常重要——代码和对话可以独立回滚。常见场景:

  • “我写的东西还行但对话讲歪了” → Restore conversation
  • “代码改错了但对话讨论的思路还有用” → Restore code
  • “整个都不对” → Restore code and conversation

Summarize from here(很容易被忽略的一手)

/compact 有区别:/compact 压整个对话;summarize from here 只压你选的点之后的内容,前面保留完整

用途:session 开头的需求分析你想保留,但中间的 20 次试错不想再占 context——选开头之后的点 → Summarize from here → 中间那段变成一个摘要。

Restore vs. Fork(重要对比)

doc 结尾有一句提醒:

“Restore 让你在同一个 session 里。如果你想分支出去试不同方法,同时保留原 session 完整,用 fork(claude --continue --fork-session)。”

  • Restore = 覆盖当前 session
  • Fork = 复制一份 session 到分支,两个都保留

想”试试另一种方案,不行就回来”用 fork。想”这次走错了重来”用 restore。

和 git 的关系

doc 没明说,但从社群实践推:

  • checkpoint 粒度比 git commit 细——每个 prompt 一个 checkpoint,commit 通常一段功能一个
  • checkpoint 30 天自动清,commit 永久
  • checkpoint 是 Claude 的 safety net,git 是 的 safety net
  • 不互相替代——都要

陈彬视角

这个功能容易被忽略但价值很高——尤其是 Claude 走偏时。新手的反应是手动 Ctrl+Z 或 git checkout,其实 /rewind 更精细(能单独回滚代码或对话,不用两个都牺牲)。

一个小习惯值得建立:大改之前先 git commit 一下。这样 checkpoint(短期救急)和 git(长期兜底)两层防护都在。Claude 搞崩了——/rewind 回一步;/rewind 也救不回来——git reset --hard

这是 thin 级条目——官方 doc 只讲了”功能是什么”,没讲”什么时候 rewind 不够”。等社群里有人真的用 rewind 救场/失败一次,再补。

关联

needs_sources(明确待补)

  • 真实 /rewind 救场/失败案例
  • checkpoint 和 git commit 配合的社群实践
  • checkpoint 被自动清除带来的坑