Claude Code Checkpoints: Safe AI Development with Instant Rollback
Master Claude Code's checkpoint system to develop fearlessly. Learn how automatic save states, instant rewind, and strategic checkpoint management enable safe, experimental coding with AI assistance.
TL;DR
Claude Code's checkpoint system provides automatic save states before every AI-generated change, enabling instant rollback when needed:
- Automatic Checkpoints: Created before every modification Claude makes
- Instant Rewind: Press
Esctwice or use/rewindto restore previous state - No Performance Impact: Lightweight snapshots, not full copies
- Complementary to Git: Works alongside version control for double protection
- Experimental Freedom: Code fearlessly knowing you can always undo
Checkpoints transform AI-assisted development from "hope this works" to "let's try and see"—with zero risk.
Why Checkpoints Matter for AI Development
The AI Coding Problem
Traditional development:
1. Write code carefully
2. Test thoroughly
3. Commit if successful
4. If broken, use git revert
Risk: Controlled - you wrote the code, you understand it
AI-assisted development (before checkpoints):
1. Ask AI to make changes
2. AI modifies 20 files
3. Something breaks
4. Which change caused the issue?
5. Manual debugging or starting over
Risk: Higher - AI made many changes, harder to trace issues
AI-assisted development (with checkpoints):
1. Ask AI to make changes → Auto-checkpoint created
2. AI modifies 20 files
3. Something breaks
4. Esc Esc → Instant rewind to before changes
5. Refine instructions, try again
Risk: Minimal - instant rollback at any time
Real-World Scenario
Without Checkpoints:
You: "Refactor the authentication system to use JWT instead of sessions"
Claude: [Modifies 15 files across auth/, api/, and middleware/]
You: *Tests the app* - Login broken, session logic tangled with new JWT code
You: "Uh, can you revert those changes?"
Claude: "I don't have access to previous states. You'll need to use git
or manually undo the changes."
Result: 30 minutes lost debugging or reverting via git
With Checkpoints:
You: "Refactor the authentication system to use JWT instead of sessions"
[Checkpoint Created] Before: JWT authentication refactoring
Claude: [Modifies 15 files across auth/, api/, and middleware/]
You: *Tests the app* - Login broken
You: Esc Esc
[Checkpoint Restored] Reverted to: Before JWT authentication refactoring
You: "Let's try again. Keep session logic intact, add JWT as alternative auth method"
Result: 5 seconds to rollback, immediate retry with better instructions
How Checkpoints Work
Automatic Checkpoint Creation
Every time Claude Code prepares to modify your codebase:
1. Analyze Request
↓
2. Create Checkpoint ← Automatic
- Current file states
- Git status
- Working directory snapshot
↓
3. Execute Changes
- Modify files
- Run commands
- Update dependencies
↓
4. Present Results
- Show changes
- Run tests
- Wait for approval
What's Included in a Checkpoint
Checkpoint Contents:
✓ All file modifications since last checkpoint
✓ File additions and deletions
✓ Git branch and commit state
✓ Current working directory
✓ Environment state (for relevant changes)
Not Included:
✗ External database changes (use transactions for this)
✗ Cloud deployments (use staging environments)
✗ Third-party API calls (cannot undo external effects)
Checkpoint Storage
# Checkpoints stored in project directory
.claude/
checkpoints/
checkpoint-1737123456789.json # Timestamp-based
checkpoint-1737123789012.json
checkpoint-1737124012345.json
# Each checkpoint is lightweight
# Average size: 10-50KB (only diffs, not full copies)
# Auto-cleanup after 24 hours or 50 checkpoints (configurable)
Using Checkpoints Effectively
Quick Rewind (Most Common)
Keyboard Shortcut: Esc Esc (press Escape twice quickly)
When to use:
- Immediately after Claude makes unwanted changes
- Test fails after Claude's modifications
- Code doesn't match expectations
- Want to try a different approach
Example:
You: "Add input validation to all API endpoints"
Claude: [Modifies 30 files]
You: *Notices Claude used a validation library you don't want*
You: Esc Esc
[Restored to before changes]
You: "Add input validation using our existing validateRequest middleware"
Rewind Command
# Rewind to previous checkpoint
/rewind
# Rewind multiple checkpoints
/rewind 3 # Go back 3 checkpoints
# Rewind to specific checkpoint
/rewind checkpoint-1737123456789
# List available checkpoints
/checkpoint list
# View checkpoint details
/checkpoint show checkpoint-1737123456789
Strategic Checkpoint Usage
Manual Checkpoints (before risky operations):
# Create named checkpoint before major change
/checkpoint create "before-database-migration"
# Perform risky operation
claude "Migrate from MongoDB to PostgreSQL"
# If successful, continue
# If failed, restore named checkpoint
/checkpoint restore "before-database-migration"
Checkpoint Workflow for Large Refactorings:
Instead of:
"Refactor entire codebase to TypeScript" → High risk, hard to review
Better:
1. "Convert models/ to TypeScript" → Checkpoint → Review → Approve
2. "Convert controllers/ to TypeScript" → Checkpoint → Review → Approve
3. "Convert services/ to TypeScript" → Checkpoint → Rewind (found issue)
→ Refine instructions → Try again → Approve
4. "Update build config for TypeScript" → Checkpoint → Review → Approve
Each step is independently rewindable
Advanced Checkpoint Techniques
Checkpoint Branching
Scenario: Trying two different implementation approaches
[Checkpoint A] Initial state
Approach 1: "Use Redis for caching"
→ Claude implements Redis caching
→ Benchmark: 200ms average response
Esc Esc (rewind to Checkpoint A)
Approach 2: "Use in-memory LRU cache"
→ Claude implements LRU cache
→ Benchmark: 150ms average response
Choose Approach 2, proceed from there
Checkpoint + Git Integration
Checkpoints: Temporary safety net during active development
Git Commits: Permanent version history
Workflow:
1. Git commit (stable state)
2. Ask Claude for feature
3. Checkpoint created automatically
4. Claude makes changes
5. Test changes:
- If good → Git commit (persist)
- If bad → Esc Esc (rewind), try again
6. Repeat until feature complete
7. Final git commit
Checkpoints = fast experimentation
Git = permanent history
Checkpoint Groups
# Tag related checkpoints for complex features
/checkpoint tag "user-authentication-feature"
# Later, view all checkpoints for that feature
/checkpoint list --tag "user-authentication-feature"
# Rewind to start of feature development
/checkpoint restore --tag "user-authentication-feature" --first
Checkpoint Best Practices
1. Review Incrementally
❌ Bad: Let Claude make 100 changes, review at end
✓ Good: Review after each logical group of changes
Example:
"Build user profile feature"
→ Break into steps, review each checkpoint:
1. Database schema → Review → Approve
2. API endpoints → Review → Approve
3. Frontend components → Review → Approve
4. Tests → Review → Approve
2. Use Descriptive Names for Manual Checkpoints
# ❌ Bad
/checkpoint create "backup"
/checkpoint create "temp"
# ✓ Good
/checkpoint create "before-payment-refactor"
/checkpoint create "working-auth-before-oauth"
/checkpoint create "pre-dependency-upgrade"
3. Don't Rely Solely on Checkpoints
Checkpoints are temporary (24-hour default retention)
For important milestones:
1. Checkpoint (immediate safety)
2. Test thoroughly
3. Git commit (permanent record)
Think of checkpoints as "undo" and git as "save"
4. Clean Up Old Checkpoints
# Auto-cleanup configuration
claude config set checkpoint.retention 48h # Keep for 48 hours
claude config set checkpoint.max-count 100 # Keep max 100
# Manual cleanup
/checkpoint clean --older-than 7d # Delete checkpoints older than 7 days
/checkpoint clean --keep-last 20 # Keep only last 20 checkpoints
5. Checkpoint Before Experiments
# Before trying something experimental
/checkpoint create "before-experimental-optimization"
claude "Try these aggressive performance optimizations:
- Implement worker threads for CPU-intensive tasks
- Add Redis caching layer
- Switch to streaming responses
- Enable HTTP/2 server push"
# Test the results
# If performance worse or bugs introduced → Restore checkpoint
# If performance better → Keep changes and git commit
Troubleshooting Checkpoints
Checkpoint Restore Failed
Error: Cannot restore checkpoint - working directory has uncommitted changes
Solution:
git stash # Stash manual changes
/rewind # Restore checkpoint
git stash pop # Re-apply manual changes if needed
Checkpoint File Conflict
Error: Checkpoint contains conflicts with current state
Cause: Files modified both by Claude and manually since checkpoint
Solution 1 (Keep manual changes):
/checkpoint restore --keep-current
Solution 2 (Keep checkpoint version):
/checkpoint restore --force
Solution 3 (Merge manually):
/checkpoint show <checkpoint-id> # View checkpoint contents
# Manually merge desired changes
Checkpoint Storage Full
Warning: Checkpoint storage exceeds 1GB
Solutions:
1. Clean old checkpoints: /checkpoint clean --older-than 7d
2. Reduce retention: claude config set checkpoint.max-count 50
3. Exclude large files: Add to .claudeignore
Lost Checkpoint
Issue: Accidentally rewound too far, want to "redo"
Solution:
/checkpoint history # Shows full checkpoint timeline
Output:
[1] checkpoint-1737123456789 - "Initial state"
[2] checkpoint-1737123789012 - "After auth refactor"
[3] checkpoint-1737124012345 - "After API updates" ← currently here
[4] checkpoint-1737124234567 - "After frontend changes" ← can restore
/checkpoint restore checkpoint-1737124234567 # Jump to later checkpoint
Checkpoint Configuration
Global Settings
# Configure checkpoint behavior
claude config edit
# checkpoint.yaml
retention:
max_age: 48h # Keep checkpoints for 48 hours
max_count: 100 # Keep max 100 checkpoints
storage:
location: .claude/checkpoints
max_size: 1GB # Maximum storage for checkpoints
auto_checkpoint:
enabled: true # Auto-create before changes
min_files: 1 # Create checkpoint if modifying 1+ files
cleanup:
auto: true # Auto-clean old checkpoints
schedule: daily # Run cleanup daily
Per-Project Settings
# .claude/config.yaml in your project
checkpoints:
enabled: true
create_before_commands: true
retention: 72h # Keep longer for this critical project
# Exclude large files from checkpoints
exclude:
- "*.log"
- "node_modules/"
- "build/"
- "dist/"
Checkpoint vs Git: When to Use Each
| Scenario | Use Checkpoint | Use Git |
|---|---|---|
| AI just made changes | ✓ Automatic | Later, if keeping |
| Trying experimental approach | ✓ Quick rewind | If experiment succeeds |
| Stable feature complete | ○ Temporary | ✓ Permanent history |
| Need to share with team | ✗ Local only | ✓ Push to remote |
| Need history > 24 hours | ✗ Auto-deleted | ✓ Permanent |
| Fast iteration during development | ✓ Instant | ○ Slower |
| Production-ready code | ○ Last resort | ✓ Required |
Best Practice: Use both together
Git commit (stable baseline)
↓
Claude makes changes → Checkpoint created
↓
Test → Good? → Git commit
→ Bad? → Rewind checkpoint, try again
Real-World Checkpoint Workflows
Debugging Unknown Issue
Problem: App started crashing, unsure which recent change caused it
Solution using checkpoints:
1. /checkpoint list # View recent checkpoints
2. /rewind 1 # Go back one change
3. Test app # Still crashing? Continue...
4. /rewind 2 # Go back two changes
5. Test app # Works! Issue introduced in between
6. /checkpoint restore checkpoint-[problematic-one]
7. Review specific changes that caused issue
8. Ask Claude to fix that specific change
A/B Testing Implementations
Compare two different algorithms:
[Checkpoint] Initial state
Version A: "Implement sorting using quicksort"
→ Test performance: 150ms
→ /checkpoint create "quicksort-version"
/rewind # Back to initial state
Version B: "Implement sorting using merge sort"
→ Test performance: 120ms
→ /checkpoint create "mergesort-version"
Keep Version B (better performance)
Git commit mergesort implementation
Progressive Feature Refinement
1. "Build basic user search"
→ Checkpoint → Test → Works but slow
2. "Optimize search with indexing"
→ Checkpoint → Test → Faster but wrong results
3. Esc Esc (rewind optimization)
4. "Optimize search with caching instead"
→ Checkpoint → Test → Faster AND correct
5. Git commit refined implementation
Each iteration builds on previous checkpoint
Performance Considerations
Checkpoint Creation Speed
Small projects (<100 files):
Checkpoint creation: <100ms (imperceptible)
Medium projects (100-1000 files):
Checkpoint creation: 100-500ms (minimal delay)
Large projects (>1000 files):
Checkpoint creation: 500ms-2s (may want to exclude large dirs)
Optimizing Checkpoint Performance
# Exclude unnecessary directories
# .claudeignore
node_modules/
.next/
build/
dist/
*.log
.git/
# Result: Faster checkpoints, less storage
Checkpoint Restore Speed
Restore is typically faster than creation:
- Small project: <50ms
- Medium project: 50-200ms
- Large project: 200ms-1s
Nearly instant for typical use cases
Conclusion
Claude Code's checkpoint system transforms AI-assisted development from cautious to fearless. Key benefits:
✓ Experiment Freely: Try any approach, instantly rewind if needed ✓ Iterate Faster: No fear of breaking working code ✓ Learn from AI: See what works and what doesn't, refine instructions ✓ Catch Mistakes Early: Review changes incrementally with rollback safety ✓ Complement Git: Fast iteration during development, permanent history when stable
Remember: Checkpoints are your safety net for AI collaboration. Use them liberally, rewind without hesitation, and commit to git only when you're confident.
Start leveraging checkpoints today and experience the confidence of risk-free AI-assisted development.
Keywords: claude code checkpoints, AI code safety, instant rollback, version control, safe AI development, undo AI changes, claude code rewind, development safety net, experimental coding, AI pair programming