# Practical ways to use the Claude Agent SDK
โช Track all file changes made by the agent and rewind to any safe state at any time.
File Checkpointing tracks changes made via Write/Edit and lets you restore to any point using `rewind_files()`.
๐ Title: Rewinding File Changes with Checkpointing
๐ URL:
๐งฉ Overview
Enable with `enable_file_checkpointing=True`. Each turn's changes are tracked and assigned a checkpoint UUID. `rewind_files(checkpoint_id)` restores file state to that point.
๐ How to use it
Enable with `enable_file_checkpointing=True`. Each `UserMessage.uuid` in the stream serves as a checkpoint ID. Restore with `rewind_files(checkpoint_id)` (or `--rewind-files` flag in CLI).
๐ Practical usage
- Keep the latest checkpoint UUID before risky operations and instantly rewind to the last safe state on verification failure.
- Store per-turn UUIDs in an array for selective rollback: "Keep the turn 1 refactor but revert the turn 2 test additions."
- Build an interactive approval flow that asks users "Rewind these changes?" after document comment additions.
๐ก Use cases
๐ก Instant rollback to safe state on verification failure
๐ฏ Selective rollback of specific turns
๐ Faster trial-and-error cycles
โ ๏ธ Watch out
Changes via Bash (`echo >`, `sed -i`), directory operations, and remote files are NOT tracked. Conversation history is not rewound โ only files.
#
ClaudeAgentSDK# #
AI#