Claude Code Checkpoints & Rewind Feature - Undo AI Code Changes
Learn how to use Claude Code's checkpoints and rewind feature to safely undo AI-generated code changes. Use Esc+Esc or /rewind to rollback mistakes and maintain control over your codebase.
One of Claude Code's most powerful features is its built-in checkpointing and rewind system. This feature lets you safely experiment with AI-generated code changes while maintaining full control over your codebase. If Claude makes changes you don't like, you can instantly rewind to any previous state.
What are Checkpoints in Claude Code?
Checkpoints are automatic snapshots of your code state during a Claude Code session. Think of them as save points in a video game - if something goes wrong, you can always go back to a known good state.
Key benefits:
- Safety net - Experiment freely knowing you can undo any changes
- Quick recovery - Rewind to any previous state instantly
- Flexible options - Choose to restore code, conversation, or both
- Confidence - Let Claude make bold refactoring attempts without fear
How Claude Code Checkpoints Work
Claude Code automatically tracks file edits as you work:
- Before each edit - A checkpoint is created before Claude modifies any file
- Automatic tracking - All direct file edits through Claude's tools are captured
- Session-based - Checkpoints persist throughout your current session
Important Limitations
- Bash commands not tracked - File modifications made by bash commands (like
mv,rm,sed) cannot be undone through rewind - Only Claude's direct edits - Only files edited through Claude's file editing tools are tracked
- Session scope - Checkpoints only exist within the current session
Using the Rewind Feature
Quick Rewind: Esc + Esc
The fastest way to open the rewind menu:
Press Esc twice (Esc + Esc)
This opens the rewind interface where you can choose what to restore.
Command: /rewind
You can also use the slash command:
/rewind
Rewind Options
When you open the rewind menu, you have three choices:
| Option | What it does |
|---|---|
| Conversation only | Rewind to a previous user message while keeping all code changes |
| Code only | Revert file changes while keeping the conversation history |
| Both code and conversation | Restore both to a prior point in the session |
Selecting a Restore Point
The rewind interface shows you a timeline of changes:
Rewind to:
[1] 10:30 - Before editing src/utils.js
[2] 10:32 - Before refactoring api/routes.js
[3] 10:35 - Before adding validation logic
[4] 10:40 - Before updating tests
Select the point you want to return to, then choose what to restore (code, conversation, or both).
Practical Examples
Example 1: Undo a Bad Refactor
You asked Claude to refactor a function, but don't like the result:
You: Refactor the handleSubmit function to use async/await
Claude: [Makes changes to handleSubmit]
You: Actually, I prefer the original approach.
[Press Esc + Esc]
[Select "Code only"]
[Choose the checkpoint before the refactor]
Claude: Code restored to previous state. The original handleSubmit is back.
Example 2: Try Multiple Approaches
Experiment with different implementations safely:
You: Add form validation to the signup form
Claude: [Implements validation approach A]
You: Can you try a different approach using Zod instead?
Claude: [Implements approach B with Zod]
You: I think the first approach was simpler.
[Press Esc + Esc]
[Select "Code only"]
[Choose checkpoint before Zod implementation]
Claude: Restored to the first validation approach.
Example 3: Recover from a Misunderstanding
If Claude misunderstands your request:
You: Update the API endpoints
Claude: [Updates endpoints in an unexpected way]
You: Wait, that's not what I meant.
[Press Esc + Esc]
[Select "Both code and conversation"]
[Choose checkpoint before the changes]
You: Let me clarify - I want to update the base URL, not the route paths.
Claude: Got it! I'll update just the base URL configuration.
Example 4: Keep Code, Restart Conversation
Sometimes you want to keep the code but try a different conversation direction:
You: [Asked several questions, got confused responses]
[Press Esc + Esc]
[Select "Conversation only"]
[Choose earlier point]
You: Let me ask this differently...
Best Practices
1. Use Git for Permanent History
Checkpoints are for quick, session-level recovery. Use Git for permanent version control:
- Checkpoints = "Local undo" within a session
- Git commits = Permanent history across sessions
# After you're happy with Claude's changes
git add .
git commit -m "Add form validation"
2. Be Aware of Bash Limitations
Remember that bash command effects aren't tracked:
# This CAN be undone (direct file edit)
Claude: I'll update the config file...
[Uses Edit tool]
# This CANNOT be undone through rewind
Claude: I'll move the file...
[Uses: mv old-name.js new-name.js]
If you're doing risky operations, commit to Git first.
3. Rewind Early, Rewind Often
Don't hesitate to use rewind. It's designed for experimentation:
- Try bold refactoring attempts
- Explore different implementation approaches
- Undo immediately if something feels wrong
4. Choose the Right Restore Option
- Code only - When Claude's explanation was good but the code wasn't
- Conversation only - When the code is fine but you want to ask differently
- Both - When you want a complete fresh start from that point
Checkpoints vs Git
| Feature | Checkpoints | Git |
|---|---|---|
| Scope | Current session only | Permanent across all time |
| Speed | Instant (Esc + Esc) | Requires commit/checkout |
| Granularity | Every file edit | Per commit |
| Bash changes | Not tracked | Tracked if committed |
| Collaboration | Single user | Multi-user |
| Best for | Quick experimentation | Permanent history |
Recommended workflow:
- Experiment freely with Claude (using checkpoints for quick undos)
- When satisfied, commit to Git
- Continue with the next task
Advanced Tips
Viewing Change History
Before rewinding, you can ask Claude what changed:
You: What files did you modify in this session?
Combining with Git Stash
For extra safety on experimental work:
# Before asking Claude to make big changes
git stash
# Let Claude work...
# If things go wrong and rewind isn't enough
git stash pop
Session Boundaries
Checkpoints don't persist between sessions. If you close Claude Code and reopen:
- Previous checkpoints are gone
- New session starts fresh
- This is why Git commits matter!
Troubleshooting
"Rewind not available"
This can happen if:
- No changes have been made yet in the session
- You're at the beginning of the session
Solution: Make sure Claude has made at least one file edit first.
Changes not appearing in rewind
Remember that only direct file edits are tracked. If Claude used bash commands to modify files, those changes won't appear in the rewind menu.
Solution: Use Git to recover from bash-based changes, or ask Claude to use direct file editing tools.
Checkpoint seems incorrect
The checkpoint captures the state before Claude's edit. If you rewind to checkpoint 3, you get the code as it was before the third edit was made.
Why This Feature Matters
The rewind feature addresses a key concern with AI coding assistants: trust and control.
Without checkpoints, you might hesitate to let AI make significant changes. With the rewind feature:
- Let Claude attempt ambitious refactors
- Try multiple implementation approaches quickly
- Recover instantly from any mistakes
- Build confidence in AI-assisted development
- Maintain full control over your codebase
Claude Code 2.0 introduced this feature based on extensive community feedback, making it one of the safest AI coding tools available.
Summary
Claude Code's checkpoints and rewind feature provides:
- Automatic safety - Checkpoints created before every file edit
- Quick access - Press Esc + Esc or use /rewind
- Flexible options - Restore code, conversation, or both
- Instant recovery - Undo mistakes in seconds
- Git integration - Works alongside your version control
This feature lets you experiment freely while maintaining complete control over your code.
Related Guides:
- Getting Started with Claude Code
- Installation Guide
- Best Practices
- Claude Code vs Cursor vs GitHub Copilot
Sources: