Claude Code /rewind: Undo Any AI Mistake in One Command
Table of Contents
- Why You Need /rewind
- What Is /rewind
- How It Remembers History
- Four Rollback Modes
- 1. Restore Code and Conversation
- 2. Restore Conversation Only
- 3. Restore Code Only
- 4. Summarize from Here
- The Interface
- What Gets Rolled Back, What Doesn’t
- Will be rolled back
- Will NOT be rolled back
- File Backup Mechanism
- Backup file format
- Change detection
- Permission preservation
- Practical Use Cases
- Case 1: Wrong refactoring direction
- Case 2: Undo only the last step
- Case 3: Code is fine, conversation needs a redo
- Case 4: Context getting too long
- Enabling and Disabling
- /rewind vs git
- Final Thoughts
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:
- Checks file stat info (size, modification time)
- If stats changed, reads file content for byte-level comparison
- 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 | /rewind | git |
|---|---|---|
| Granularity | Per conversation turn | Per commit |
| Requires prior commit | No | Yes |
| Tracks uncommitted changes | Automatic | Doesn’t |
| Can roll back conversation | Yes | No |
| Tracks manual edits | No | Yes |
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.
If what you actually want is not “rolling back to a checkpoint” but “compressing the conversation to free up context,” use /compact. The two are often used together.
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.
Related Articles
Claude Code Agent Loop: Dissecting the Heart of an AI Coding Assistant
How does Claude Code understand your requests, invoke tools, and self-recover step by step? A source-code deep dive into the Agent Loop's core architecture — streaming responses, parallel tool execution, auto-compaction, and error recovery.
Claude Code settings.json Explained (1): Where Config Files Live and Who Wins
A complete guide to Claude Code's configuration file system — five config sources, their file paths, priority rules, array merging vs value overriding, and enterprise managed settings delivery.
Claude Code settings.json Deep Dive (Part 2): The Permissions System
A thorough breakdown of Claude Code's permissions configuration — allow/deny/ask rule arrays, wildcard syntax, MCP tool permissions, defaultMode options, and additionalDirectories.
Claude Code settings.json Deep Dive (Part 3): The Hooks System
A thorough breakdown of Claude Code's hooks configuration — four hook types, core events (PreToolUse/PostToolUse/Stop/Notification), stdin/stdout protocol, exit code semantics, and practical examples.
Claude Code settings.json Deep Dive (4): env, Models, Auth, and Other Useful Fields
A comprehensive guide to the remaining settings.json fields in Claude Code — env variable injection, model configuration, authentication helpers, Git attribution, session cleanup, language and UI, thinking depth, auto-updates, memory system, and more.