Logo Vincent
Back to all posts

Claude Code /rewind Explained: AI Made a Mistake? Undo It Instantly

Claude
Claude Code /rewind Explained: AI Made a Mistake? Undo It Instantly

Why You Need /rewind

You ask Claude to refactor a module. It changes 5 files. You take a look — completely wrong direction.

What now? Manually git checkout each file? If you haven’t committed yet, you can’t even find a clean diff.

Or another scenario: Claude’s first few responses were great, but the last one went off track. You want to go back to “before it went wrong” and start over.

/rewind is your undo button. One command to roll back both code and conversation to any previous point.

What Is /rewind

/rewind is Claude Code’s code and conversation rollback command (also aliased as /checkpoint). It restores your file state and conversation history to any earlier point in the session.

Type:

/rewind

An interactive message selector appears, letting you choose “where to go back to.”

How It Remembers History

There’s an elegant mechanism behind this: the file snapshot system.

After each Claude response, Claude Code automatically snapshots all files that Claude has modified. This process is completely transparent — you won’t even notice it happening.

Specifically:

  • Trigger: After each Claude response completes
  • Snapshot content: All files edited, created, or deleted by Claude
  • Storage location: ~/.claude/file-history/{sessionId}/
  • Versioning: Each file is numbered by version (v1, v2, v3…)
  • Limit: Up to 100 snapshots per session; oldest are evicted when exceeded

File backups are incremental — only files that actually changed get a new version. If a file didn’t change between two turns, the previous backup is reused, saving space.

Four Rollback Modes

After selecting your rollback point, you have four options:

1. Restore Code and Conversation

Restore code and conversation

The most commonly used mode. Files are restored to the selected point’s state, and all conversation messages after that point are deleted. The conversation “forks” — you can restart the discussion from that point.

2. Restore Conversation Only

Restore conversation

Only deletes conversation messages after the selected point — files stay unchanged. Use this when Claude’s later responses were unhelpful, but you want to keep the code changes.

3. Restore Code Only

Restore code

Only restores files to the selected point’s state — conversation stays intact. Use this when you want to preserve the conversation context (like Claude’s analysis) but need to undo the code changes.

4. Summarize from Here

Summarize from here

Messages after the selected point get compressed into a single summary message. Saves context space while preserving key information.

The Interface

The /rewind interaction is designed to be intuitive.

Step 1: Select the rollback point

Your conversation history appears on screen, with each message showing:

  • Message content summary
  • Code change stats (files changed, lines added/removed)
  • If only one file was changed, its filename is displayed

Navigate with arrow keys, confirm with Enter.

Step 2: Confirm the rollback method

After selecting a point, a confirmation screen shows:

  • Which message you selected
  • How many files will be restored
  • How many lines of code will change
  • Rollback mode selection (code+conversation, code only, conversation only, summarize)

A reminder appears at the bottom:

⚠️ Rewinding does not affect files edited manually or via bash

What Gets Rolled Back, What Doesn’t

This is critical to understand:

Will be rolled back

  • Files modified by Claude via the file edit tool (FileEditTool)
  • Files created by Claude via the file write tool (FileWriteTool)
  • Files deleted by Claude (restored from backup)

Will NOT be rolled back

  • Files you edited manually
  • Files modified via Bash commands (e.g., sed, awk)
  • Changes made by external tools or your IDE

Simple rule: Only Claude’s “official” file operations are tracked and reversible. If Claude used the Bash tool to run sed -i on a file, that change is outside rewind’s tracking scope.

File Backup Mechanism

A few technical details to help you understand the system’s reliability.

Backup file format

~/.claude/file-history/{sessionId}/
├── abc123def4567890@v1    # First version of a file
├── abc123def4567890@v2    # Second version
├── abc123def4567890@v3    # Third version
├── f1e2d3c4b5a69788@v1    # Different file, first version
└── f1e2d3c4b5a69788@v2

Filenames are hashes of the original path, plus a version number.

Change detection

Claude Code doesn’t blindly back up every time. It:

  1. Checks file stat info (size, modification time)
  2. If stats changed, reads file content for byte-level comparison
  3. Only creates a new version for files that truly changed

Permission preservation

When restoring files, not only content is restored — file permissions are too (via chmod). So executable scripts remain executable after rollback.

Practical Use Cases

Case 1: Wrong refactoring direction

You ask Claude to refactor a class into functional style. It changes 5 files, but after reviewing, you prefer the original.

/rewind

Select the message before the refactoring → Restore code and conversation → Back to square one.

Case 2: Undo only the last step

Claude helped you through three rounds of changes. First two were great, third one broke things.

/rewind

Select the message before the third round → Restore code and conversation → Keep the first two rounds’ work.

Case 3: Code is fine, conversation needs a redo

Claude’s code changes were correct, but the subsequent conversation went off track. You want to re-guide from a certain point.

/rewind

Select a message → Restore conversation → Files stay as-is, conversation restarts from the selected point.

Case 4: Context getting too long

The session is getting long, context is nearly full. You want to preserve key information but compress the history.

/rewind

Select an appropriate point → Summarize from here → Subsequent messages are compressed into a summary.

Enabling and Disabling

The file snapshot system is enabled by default — no configuration needed.

If you want to disable it for performance or privacy reasons:

# Disable via environment variable
export CLAUDE_CODE_DISABLE_FILE_CHECKPOINTING=1

Or set fileCheckpointingEnabled: false in global configuration.

When disabled, /rewind can still roll back conversations, but cannot restore files.

/rewind vs git

You might think: I have git, why do I need /rewind?

Feature/rewindgit
GranularityPer conversation turnPer commit
Requires prior commitNoYes
Tracks uncommitted changesAutomaticDoesn’t
Can roll back conversationYesNo
Tracks manual editsNoYes

In short: git is long-term version management, /rewind is instant undo within a session. They complement each other.

Best practice: Commit at every important milestone, then use /rewind for fine-grained rollbacks between commits.

Final Thoughts

The core value of /rewind is giving you the courage to make mistakes.

When collaborating with AI on code, you can’t always give perfect instructions. Claude can’t always understand you perfectly either. With /rewind, you can experiment boldly: let Claude try an aggressive approach — roll back if it doesn’t work out; let it take a risky path — come back if it’s a dead end.

AI coding without an undo button is incomplete.

More Articles

© 2026 vincentqiao.com . All rights reserved.