← Blog
explainx / blog

How to restore previous code in Claude Code CLI: checkpoint feature similar to Cursor's restore functionality

Press ESC twice in Claude Code CLI to access checkpoint restore options that let you revert to previous code states. Choose from four options: restore code and conversation, restore conversation only, restore code only, or cancel. Similar to Cursor's checkpoint feature but built into Claude Code.

5 min readYash Thakker
Claude CodeDeveloper ToolsVersion ControlCheckpointsProductivity

MDX restores the committed source plus an HTML comment attribution; plain text bundles the rendered markdown body with the explainx.ai attribution footer.

How to restore previous code in Claude Code CLI: checkpoint feature similar to Cursor's restore functionality

Claude Code CLI has a powerful but lesser-known checkpoint restore feature that lets you revert to previous code and conversation states—similar to Cursor's checkpoint functionality—without relying on git.

The feature is activated by pressing ESC twice in rapid succession, which opens a menu with four restoration options:

  1. Restore code and conversation — revert both files and chat history
  2. Restore conversation — revert only the chat history
  3. Restore code — revert only file changes
  4. Nevermind — cancel the operation

This is particularly useful during experimentation, debugging, or when trying multiple approaches to a problem. You can quickly revert changes without the overhead of git commits or stash operations.

This article explains how to use the restore feature, when to use each option, how it compares to Cursor's checkpoints, and best practices for checkpoint-driven development.

Claude Code restore checkpoint feature — ESC twice to restore

How to activate the restore menu

The restore feature is accessed with a simple keyboard shortcut:

  1. Press ESC twice (rapidly, within about 1 second)
  2. A menu appears with four options
  3. Use arrow keys or number keys to select an option
  4. Press Enter to confirm

Claude Code checkpoint restore menu showing four options

What happens when you press ESC twice

# You're in an active Claude Code session
$ claude

# You've made several code changes and had a conversation
> Can you add error handling to the API?
[Claude makes changes to server.ts, adds try-catch blocks]

> Actually, let me try a different approach
# Press ESC ESC (twice rapidly)

┌─────────────────────────────────────────────────────┐
│  Restore checkpoint                                  │
├─────────────────────────────────────────────────────┤
│  1. Restore code and conversation                   │
│  2. Restore conversation                            │
│  3. Restore code                                    │
│  4. Nevermind                                       │
└─────────────────────────────────────────────────────┘

Understanding the four restore options

Each restore option serves a different use case during development:

1. Restore code and conversation

Use case: You want to completely undo both the code changes and the conversation history.

Before restore:
- server.ts modified with try-catch blocks
- 5 messages in conversation about error handling

After "Restore code and conversation":
- server.ts reverted to checkpoint state
- Conversation reverted to checkpoint state
- Fresh slate for new approach

When to use:

  • You've gone down a wrong path entirely
  • Both the code and conversation are no longer relevant
  • You want to start fresh from a known good state

2. Restore conversation

Use case: Keep your code changes but reset the conversation context.

Before restore:
- server.ts modified with try-catch blocks (KEEP)
- 5 messages in conversation about error handling (REVERT)

After "Restore conversation":
- server.ts still has try-catch blocks
- Conversation history cleared
- Useful for explaining code to someone else with fresh context

When to use:

  • You want to keep the code but explain it differently
  • The conversation became cluttered or went off-topic
  • You're starting a new task but want to keep recent code changes

3. Restore code

Use case: Revert code changes but preserve the conversation history.

Before restore:
- server.ts modified with try-catch blocks (REVERT)
- 5 messages in conversation about error handling (KEEP)

After "Restore code":
- server.ts reverted to checkpoint state
- Conversation history preserved
- Useful for referencing what didn't work

When to use:

  • The code approach didn't work but the discussion is valuable
  • You want to reference the conversation while trying a new implementation
  • Debugging: keeping the analysis but reverting attempted fixes

4. Nevermind

Use case: Cancel the restore operation.

# You pressed ESC ESC by accident
# Select "Nevermind" to continue without restoring anything

Comparison with Cursor's checkpoint feature

Both Claude Code and Cursor offer checkpoint functionality, but with different approaches:

FeatureClaude CodeCursor
ActivationPress ESC twiceDedicated checkpoint UI
GranularityCode, conversation, or bothCode checkpoints
Session scopeCurrent sessionProject-based
Git integrationIndependentCan integrate with git
Conversation restore✅ Yes❌ No
Visual timeline❌ No (menu-based)✅ Yes

Key advantage of Claude Code: The ability to restore conversation state separately from code is unique and valuable for maintaining context during experiments.

Key advantage of Cursor: Visual checkpoint timeline makes it easier to see what changed at each checkpoint.

When to use Claude Code restore vs git

Use Claude Code restore when:

✅ Experimenting with quick iterations ✅ Trying multiple approaches in a single session ✅ You want to preserve conversation context ✅ No need for permanent version control ✅ Working on throwaway code or spikes

Use git when:

✅ You need permanent version control ✅ Collaborating with others ✅ You want detailed commit messages and history ✅ Changes need to be shared across machines ✅ You're working on production code

Best practice: Use both—Claude Code restore for rapid iteration, git for checkpoints you want to keep.

Practical workflow examples

Example 1: API design experimentation

$ claude

> Design a REST API for user authentication

# Checkpoint 1 (automatically created)
[Claude designs JWT-based auth]

> Actually, let's try session-based auth instead
[Claude implements session-based approach]

# Not happy with it
ESC ESC → "Restore code and conversation"
# Back to Checkpoint 1

> What about OAuth2 with refresh tokens?
[Claude implements OAuth2]

# This works! Commit to git
$ git add . && git commit -m "Add OAuth2 authentication"

Example 2: Debugging with conversation preservation

$ claude

> The login endpoint returns 500 errors

# Deep conversation about potential causes
# Claude suggests checking database connection, environment variables, etc.

> Try fixing the database connection timeout
[Claude modifies db.ts with new timeout settings]

# Didn't work, but the conversation analysis is valuable
ESC ESC → "Restore code"
# Code reverted, conversation preserved

> Based on your analysis above, let's try the environment variable approach
[Claude fixes .env configuration]
# This works!

Example 3: Cleaning up conversation clutter

$ claude

> Refactor the authentication module
[Long conversation with multiple tangents and clarifications]

# Code is good, but conversation is messy
ESC ESC → "Restore conversation"
# Code preserved, conversation reset

> I've refactored the auth module to use dependency injection
# Fresh conversation context for the next developer

Best practices for checkpoint-driven development

1. Know your checkpoint states

Claude Code creates automatic checkpoints at key moments (exact timing is implementation-dependent). Understanding when checkpoints are created helps you restore to the right state.

2. Use restore for experiments, git for keepers

# Experiment with Claude Code restore
ESC ESC → try approach A
ESC ESC → try approach B
ESC ESC → try approach C

# When you find the winner, commit to git
$ git add . && git commit -m "Implement approach B for auth"

3. Preserve valuable conversations

If a conversation contains valuable analysis or context, use "Restore code" instead of "Restore code and conversation" to keep the discussion.

4. Combine with /goal for autonomous checkpoints

If you're using /goal for long-running tasks (see Claude Code /goal command guide), you can use restore to revert if the autonomous agent goes off track.

> /goal All tests passing, coverage > 90%
[Claude works for 30 minutes across multiple turns]
[Results are not what you expected]

ESC ESC → "Restore code and conversation"
# Back to before /goal was invoked

Keyboard shortcut summary

ActionShortcutResult
Open restore menuESC ESC (twice rapidly)Shows 4 restore options
Navigate menuArrow keys or 1/2/3/4Highlight option
Confirm selectionEnterExecute restore
CancelSelect "Nevermind" or ESCClose menu without restoring

Related on ExplainX

Bottom line

Claude Code's checkpoint restore feature (activated by pressing ESC twice) provides Cursor-style checkpoint functionality with the added benefit of separate conversation and code restoration.

The four options—restore code and conversation, restore conversation, restore code, or nevermind—give you fine-grained control over what to revert during development.

Use it for rapid experimentation during active sessions, and commit valuable changes to git for permanent version control. The combination of Claude Code checkpoints for iteration and git for persistence creates a powerful workflow for AI-assisted development.

Next time you're experimenting with Claude Code, try ESC ESC to explore different approaches without fear of losing progress.


Claude Code documentation: https://github.com/anthropics/claude-code. ExplainX is not affiliated with Anthropic.

Related posts