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:
- 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.
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
- Why AI-First Startups Only Need One Programming Language
- cc-ping: Ping All Your Claude Code Configs in One Command
- Shocking! This Tool Lets Programmers Finish 95 Minutes of Work in 4 Minutes! 24x Efficiency Boost
- CCBot - 24x Development Efficiency Boost
- Claude Code /add-dir: The Monorepo Command You Miss
- Claude Code Token-Saving Tip: The Power of the Exclamation Mark
- I Built a Bot That Runs Claude Code From Chat
- Claude Code /btw Command Explained: Quick Side Questions Without Breaking Flow
- Claude Code /compact: Free Up Context, Keep Progress
- Claude Code /config: Every Setting Explained
- Claude Code /context: What's Eating Your Context Window?
- Claude Code /diff: See Exactly What Changed, Turn by Turn
- Claude Code /fast: Same Opus, 2x Speed — Worth It?
- Best Practice for External Knowledge in Claude Code: GitHub MCP + Context7
- Claude Code /hooks: Make AI Follow Your Rules
- Claude Code /init: Generate CLAUDE.md in 10 Seconds
- Claude Code MCP: Give Your AI Access to Any Tool
- Claude Code /memory Explained: Make AI Truly Remember Your Project
- Claude Code /model: Opus vs Sonnet vs Haiku Guide
- Claude Code /permissions: Fine-Grained Control Over What AI Can Do
- Claude Code /plan Explained: Think Before You Code
- Claude Code + Playwright MCP: AI Can Finally "See" the Page
- Claude Code /resume Command Explained: Don't Let Your Conversations Go to Waste
- Claude Code /review: Let AI Do Your Code Review
- Claude Code Skills Explained: Build Your Custom Command Library
- Claude Code /stats: See How Much AI Does For You
- Claude Code /status Command Explained: Your Session Dashboard
- Claude Code /tasks Command Explained: Master Your Background Tasks
- Claude Code /usage Command Explained: Know Your Remaining Quota
- Claude Code /vim: Vim Keybindings in Your AI Coding Assistant
- Claude Code in 2026: The Only Setup Guide You Need
- The Complete Guide to Claude: From Chat to Code to Automation
- Claude Code /agents Explained: Custom AI Sub-Agents, Each with Their Own Role
- Claude Code /doctor Explained: One-Click Diagnostics for Your Dev Environment
- Claude Code /effort Explained: Control How Hard Your AI Thinks
- Claude Code /cost Explained: How Much Is Your AI Coding Really Costing?
- Claude Code /export Explained: Take Your AI Conversations With You
- Claude Code /plugin Explained: Install Plugins for Your AI Coding Assistant
- Claude Code /theme Explained: Give Your Terminal a New Look
- Claude Code /insights: Using AI to Analyze How You Use AI
- Claude Code /rename Explained: Give Your Sessions Meaningful Names
- Claude Code settings.json Explained (1): Where Config Files Live and Who Wins
- Claude Code settings.json Deep Dive (Part 2): The Permissions System
- Claude Code settings.json Deep Dive (Part 3): The Hooks System
- Claude Code settings.json Deep Dive (4): env, Models, Auth, and Other Useful Fields