# 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#