【Claude Code】Claude Code 的 Checkpoint 是怎么实现的

Claude Code 的 Checkpoint 是怎么实现的

概述

Checkpoint 是 Claude Code 提供的会话快照功能,可以保存当前对话的完整状态(消息、文件变更、上下文),并在需要时回退到指定时间点继续工作。


自动创建机制 : 每次用户输入都自动创建 Checkpoint ,无需手动创建

与 Git 的类比

Git 概念 Checkpoint 对应 说明
git commit /checkpoint 保存当前状态快照
git branch 并行任务线 支持多个独立工作流
git checkout /rewind 切换到指定快照
git stash 暂停任务 临时保存当前工作
git reset --hard /rewind --all 完全回退
git log /checkpoints list 查看历史

本质区别 :Checkpoint 是会话级的版本控制,不仅包含文件变更,还包含对话历史和 AI 上下文状态。


使用场景

场景 示例
错误恢复 误删代码后回退到上一个正确状态
分支探索 尝试新方案前创建 Checkpoint,不满意则回退
长任务保护 复杂任务中途自动创建 Checkpoint,防止丢失
上下文压缩 Checkpoint 作为压缩点,释放上下文窗口

checkpoint 管理

命令 说明
/checkpoint list 列出所有 checkpoints
/checkpoint show <id> 查看 checkpoint 详情
/checkpoint delete <id> 删除指定 checkpoint
/checkpoint prune 清理过期 checkpoints

如何调用不同的回退模式

回退命令

按两侧 Esc 或者 输入

bash 复制代码
/rewind

即可打开回退菜单,一个可滚动列表会把你的每条提示显示为检查点。选择某条消息后,你会看到四个选项:

复制代码
───────────────────────────────────────────────────────────────────────────────────────────────────
  Rewind

  Confirm you want to restore to the point before you sent this message: (回退前请确认你要保留到该点的内容)

  │ ckeckpoint 是怎么实现的
  │ (22h ago)

  The conversation will be forked.
  The code will be restored -368 in Claude Code的CheckPoint是怎么实现的.md.

  ❯ 1. Restore code and conversation (代码和对话都回到那一刻)
    2. Restore conversation  (只回退对话,保留当前文件/代码变更)
    3. Restore code (只回退文件/代码变更,保留对话)
    5. Summarize from here ( 在此处总结-将选定位置之后的所有内容压缩成摘要,保留该点之前对话的完整细)
    6. Never mind (取消操作)

什么时候用:Claude 自作主张改多了、改错方向了、或者你自己话说错了想重来

回退后,AI 会重新加载 Checkpoint 时的上下文

注意事项

注意事项 说明
操作不可逆 回退后,checkpoint 之后的变更会丢失
文件冲突 如果文件被外部修改,回退可能失败
回退会清除之后的 checkpoints 一旦回退到某个点,该点之后的 checkpoints 会被删除

/rewind 能回退几步?

能回到本次会话中任意一个 Claude 做出更改的节点,不限步数。但前提是这次会话还没关------关了会话再开回来,rewind 历史就丢了(但代码修改在磁盘上还在)

相关推荐
乾坤瞬间4 小时前
【claude code agent 实践7】后台任务机制深度解析: 从S02到S08的演进
claude code·code agent
lunatic74 小时前
Claude Code && Codex的安装方法
ai·codex·claude code
且去填词7 小时前
Claude Code Skills 实践:从提示词到专业化 AI 开发工作流
人工智能·ai编程·开发·claude code·skills
dozenyaoyida8 小时前
Claude Code Token 瓶颈破解:让 AI 编码永不中断的完整方案
token·上下文·claude code·ai记忆
乾坤瞬间1 天前
【claude code agent 实践3】Subagent子智能体机制深度解析:从S02到S04的演进
claude code·code agent
维元码簿1 天前
Claude Code 深度拆解:远程模式 4 — 无环境直连架构
ai·agent·claude code·ai coding
爱奥尼欧1 天前
MetaBot-用飞书远程操控Claude Code
飞书·claude code
linshutao1 天前
VS Code 配置 Claude Code插件和 DeepSeek
ai编程·deepseek·claude code