enableFileCheckpointing is one of the query() options. It enables the CLI to take snapshots before and after tools modify files; once enabled, the caller can use q.rewindFiles(userMessageId, ...) to roll back files to the state they were in when a particular user message started processing. These two features must be used together: without checkpointing enabled, rewind is not available.
Enabling File Checkpoint
Advanced: when you also need to adjust other CLI configuration viasettingsquery()options also accepts asettingsfield — either aSettingsobject or an absolute path string to a settings file. Its relationship withenableFileCheckpointing:
- When passing a
settingsobject, the SDK automatically mergesgeneral.fileCheckpointing.enabled = true— no need to write it manually.- When passing a
settingsfile path string, the SDK will not rewrite the file contents; you need to configure it yourself in that file:Just settingenableFileCheckpointing: truewithout passingsettingsis sufficient for scenarios that only need rewind.
Using Explicit User Message IDs
Rewind uses user message IDs as anchor points. For precise rollback, it’s recommended to use structured input and generate your ownuuid, so the UI can reliably reference “go back to before that message.”
Dry Run Preview
A dry run lets you see whether rollback is possible, which files would be affected, and overall insertion/deletion statistics. Dry run does not modify files. The returnedRewindFilesResult contains these fields:
| Field | Type | Description |
|---|---|---|
canRewind | boolean | Whether rollback can be performed. In dry run mode failures don’t throw — this field indicates the status |
error | string? | Diagnostic message when canRewind=false, can be displayed directly to the user |
filesChanged | string[]? | Absolute paths of affected files — useful for listing each file that will be reverted in the UI |
insertions | number? | Total lines that were inserted and will be “undone” by the rollback (aggregate) |
deletions | number? | Total lines that were deleted and will be “undone” by the rollback (aggregate) |
The SDK currently only returns the list of affected files and aggregate line-level statistics inRewindFilesResult— it does not return per-file diffs. If you need per-file differences, you can read the disk contents based onfilesChangedafter the dry run and compare them with the checkpoint, or use git/workspace diffing tools after executing the rewind.
Executing Rewind
Failure Semantics
| Call Form | Behavior When Rewind Is Not Possible |
|---|---|
rewindFiles(id, { dryRun: true }) | Resolves with { canRewind: false, error }, convenient for displaying diagnostics in the UI |
rewindFiles(id) (execution mode) | Promise rejects; the caller should use try/catch to display the failure reason |
Options Reference
| Field | Type | Description |
|---|---|---|
enableFileCheckpointing | boolean | Enable file checkpointing for use with rewindFiles() |
settings | string | Settings | Settings passed to the CLI; when passing an object, the SDK merges general.fileCheckpointing.enabled |
Return Value Reference
Best Practices
- Save user message IDs: Applications that need rollback capability should save the
uuidwhen sending messages; do not rely on UI text to look them up. - Dry run before rewinding: Show the impact scope first, then let the user confirm the rollback.
- Refresh UI after rollback: Rewind only changes files, not conversation history; the UI needs to reload relevant views based on
filesChanged. - Show
errorto the user on failure: Theerrortext whencanRewind=falsecan typically be displayed directly to end users for diagnostics.