Rewind file changes with checkpointing changedagent-sdk/file-checkpointing
Nearest release: v2.1.325, published 3 hours before upstream edited the page. Shown because the two are within 24 hours of each other. Nothing here says the release caused the edit.
Upstream edited this page at 14 Nov 2026 00:06 UTC, give or take a minute or two: the time comes from Anthropic’s own sitemap rather than from a commit. This site recorded the change at 14 Nov 2026 00:07 UTC.
Upstream edited
Recorded here
Lines+23added
Lines−12removed
From line
10
where the diff opens
First seen
14 Aug 2026
this site's first read of the page
Recorded edits14to this page, all time
The whole hunk
from line 10, old and new numbered
/
from line 10
1010
1111## How checkpointing works
1212
13When 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.
13When you enable file checkpointing, the SDK creates backups of files before modifying them through the Write, Edit, or NotebookEdit tools. Each prompt that starts a turn is a checkpoint, and its user message's UUID is the restore point.
1414
1515> [!NOTE]
1616>
from line 143
143143
144144**2. Capture checkpoint UUID and session ID**
145145
146With the `replay-user-messages` option set, each user message in the response stream has a UUID that serves as a checkpoint.
146With the `replay-user-messages` option set, the user message for each prompt that starts a turn has a UUID that serves as a checkpoint. User messages that carry tool results have a UUID too, but it isn't a checkpoint.
147147
148148For most use cases, capture the first user message UUID (`message.uuid`); rewinding to it restores the tracked files to their original state. To store multiple checkpoints and rewind to intermediate states, see [Multiple restore points](#multiple-restore-points).
149149
from line 167
167167
168168### Checkpoint before risky operations
169169
170This pattern keeps only the most recent checkpoint UUID, updating it before each agent turn. If something goes wrong during processing, you can immediately rewind to the last safe state and break out of the loop.
170This pattern keeps only the most recent checkpoint UUID, updating it at each prompt that starts a turn. If something goes wrong during processing, you can immediately rewind to the last safe state and break out of the loop.
171171
172172Before running this example, replace `your_revert_condition` (Python) or `yourRevertCondition` (TypeScript) with your own check, such as error detection or a validation failure; the placeholder is not defined in the example.
173173
from line 189
189189 await client.query("Refactor the authentication module")
190190
191191 async for message in client.receive_response():
192 # Update checkpoint before each agent turn starts
192 # Update checkpoint at each prompt you send; a tool result isn't one
193193 # This overwrites the previous checkpoint. Only keep the latest
194 if isinstance(message, UserMessage) and message.uuid:
194 if (
195 isinstance(message, UserMessage)
196 and message.uuid
197 and message.tool_use_result is None
198 and message.parent_tool_use_id is None
199 ):
195200 safe_checkpoint = message.uuid
196201
197202 # Decide when to revert based on your own logic
from line 226
221226 let safeCheckpoint: string | undefined;
222227
223228 for await (const message of response) {
224 // Update checkpoint before each agent turn starts
229 // Update checkpoint at each prompt you send; a tool result isn't one
225230 // This overwrites the previous checkpoint. Only keep the latest
226 if (message.type === "user" && message.uuid) {
231 if (message.type === "user" && "isReplay" in message && message.isReplay && message.uuid) {
227232 safeCheckpoint = message.uuid;
228233 }
229234
from line 247
242247
243248### Multiple restore points
244249
245If Claude makes changes across multiple turns, you might want to rewind to a specific point rather than all the way back. For example, if Claude refactors a file in turn one and adds tests in turn two, you might want to keep the refactor but undo the tests.
250If Claude makes changes across several prompts, you might want to rewind to a specific point rather than all the way back. For example, if your first prompt refactors a file and your second adds tests, rewind to your second prompt's checkpoint to keep the refactor and undo the tests.
246251
247This pattern stores all checkpoint UUIDs in an array with metadata. After the session completes, you can rewind to any previous checkpoint:
252This pattern stores each checkpoint UUID in an array with metadata. After the session completes, you can rewind to any previous checkpoint:
248253
249254```python Python theme={null}
250255import asyncio
from line 285
280285 await client.query("Refactor the authentication module")
281286
282287 async for message in client.receive_response():
283 if isinstance(message, UserMessage) and message.uuid:
288 if (
289 isinstance(message, UserMessage)
290 and message.uuid
291 and message.tool_use_result is None
292 and message.parent_tool_use_id is None
293 ):
284294 checkpoints.append(
285295 Checkpoint(
286296 id=message.uuid,
from line 344
334344
335345 try {
336346 for await (const message of response) {
337 if (message.type === "user" && message.uuid) {
347 if (message.type === "user" && "isReplay" in message && message.isReplay && message.uuid) {
338348 checkpoints.push({
339349 id: message.uuid,
340350 description: `After turn ${checkpoints.length + 1}`,
from line 644
634644
635645* File checkpointing was not enabled on the original session (`enable_file_checkpointing` or `enableFileCheckpointing` was not set to `true`)
636646* The session wasn't properly completed before attempting to resume and rewind
647* The UUID came from a user message that carries a tool result, which isn't a checkpoint
637648
638649**Solution**: Ensure `enable_file_checkpointing=True` (Python) or `enableFileCheckpointing: true` (TypeScript) was set on the original session, then use the pattern shown in the examples: capture the first user message UUID, complete the session fully, then resume with an empty prompt and call `rewindFiles()` once.
639650
No line in this hunk matches that.