- Undo unwanted changes by restoring files to a known good state
- Explore alternatives by restoring to a checkpoint and trying a different approach
- Recover from errors when the agent makes incorrect modifications
How checkpointing works
When you enable file checkpointing, the SDK creates backups of files before modifying them through the Write, Edit, or NotebookEdit tools. User messages in the response stream include a checkpoint UUID that you can use as a restore point.File rewinding restores files on disk to a previous state. It does not rewind the conversation itself. The conversation history and context remain intact after calling
rewindFiles() (TypeScript) or rewind_files() (Python).- Files created during the session
- Files modified during the session
- The original content of modified files
RewindFilesResult counts every skipped path in its skippedLinks field. Skipping requires Claude Code v2.1.216 or later; before v2.1.216, a rewind wrote and deleted through links at tracked paths.
Implement checkpointing
To use file checkpointing, enable it in your options, capture checkpoint UUIDs from the response stream, then callrewindFiles() (TypeScript) or rewind_files() (Python) when you need to restore.
The following example shows the complete flow: enable checkpointing, capture the checkpoint UUID and session ID from the response stream, then resume the session later to rewind files. Each step is explained in detail below. The examples in this section use the prompt “Refactor the authentication module”. Run them in a project that contains an authentication module, or change the prompt to name files that exist in your project, so you can watch files change and see the rewind restore them.