Atlas
TechnicalHow-to

Claude Code Rewind: Undo AI Edits with Checkpoints

How Claude Code checkpoints and /rewind restore code, conversation or both, what they can't undo (Bash, most subagent edits), and how to pair them with git.

The short version

  • Claude Code captures the state of your code before each prompt that starts a turn. /rewind (or Esc twice on an empty prompt) lets you restore code, conversation, or both.
  • Rewind only tracks edits made through Claude's file-editing tools. Bash changes such as rm or mv, edits from other sessions and most subagent edits are not undone.
  • Checkpoints are session-level recovery, not version control: commit to git before risky steps and run git status after a rewind.
  • The Summarize options in the rewind menu compress part of the conversation without touching your files, like a targeted /compact.
On this page
  1. The short version
  2. How do Claude Code checkpoints work?
  3. How do I rewind in Claude Code?
  4. Can I use rewind to free up context?
  5. What does rewind not undo?
  6. A workflow that combines rewind and git
  7. Resuming later
  8. Conclusion
  9. Questions people ask

Claude Code can undo its own file edits. It automatically captures the state of your code before each prompt you send that starts a turn. You open the rewind menu with /rewind (or by pressing Esc twice on an empty prompt) to restore code, conversation, or both. It does not track everything, so it works best next to git rather than instead of it.

This guide covers how checkpoints work, the six actions in the rewind menu, the cases where rewind does less than you might expect, and a workflow that combines it with git and context management.

How do Claude Code checkpoints work?

Checkpointing is on by default and needs no setup. Per the official checkpointing documentation:

  • Every prompt you send that starts a turn creates a new checkpoint, capturing the state of your code before Claude acts.
  • Claude Code keeps file snapshots for the 100 most recent checkpoints in a session.
  • Checkpoints are saved with the conversation, so you can still run /rewind after you resume a session.
  • Snapshots are deleted in the retention sweep, by default about 30 days after the session last saved one. Rewinding to a checkpoint whose snapshots are gone can fail with No files were restored. Set cleanupPeriodDays to keep them longer.

Only direct edits made through Claude's file-editing tools are tracked. That detail explains most of the limitations below.

How do I rewind in Claude Code?

Two ways to open the menu:

text
/rewind

Or press Esc twice while the prompt input is empty. If the input contains text, double Esc clears it instead. The cleared text is saved to your input history, so press Up to get it back.

The menu lists the prompts you sent in the session. Pick the point you want to act on, then choose an action:

ActionWhat it does
Restore code and conversationReverts both to that point
Restore conversationRewinds to that message, keeps current code
Restore codeReverts file changes, keeps the conversation
Summarize from hereCompresses the conversation from this point forward
Summarize up to hereCompresses the conversation before this point, keeps later messages
Never mindBack to the list, no changes

The two code-restore options appear only if the selected checkpoint has tracked file changes to revert. After restoring the conversation or choosing Summarize from here, the original prompt from the selected message is put back in the input field so you can edit and re-send it. That makes "same task, better prompt" quick to do.

Which restore option should I pick?

  • Claude went down a wrong path and you want a clean retry: Restore code and conversation. You get the state before the bad turn, with the prompt ready to edit.
  • The code is wrong but the discussion is useful: Restore code. Claude keeps the conversation, and you can say "that approach broke X, try again".
  • The code is fine but the conversation got muddy: Restore conversation, or use a Summarize option.

Can I use rewind to free up context?

Yes. Summarize keeps you in the same session and compresses context, like a targeted /compact. The docs give one use case: summarize a verbose debugging session from the midpoint forward while keeping your initial instructions intact.

Summarizing does not change files on disk, and the original messages stay in the session transcript, so Claude can still reference the details. To steer the summary, highlight a Summarize option with the arrow keys and type instructions where the row reads "add context (optional)", then press Enter. Selecting an option with its number key summarizes immediately with no instructions.

Anthropic's best-practices guide lists the other context tools:

  • /clear resets context between unrelated tasks.
  • /compact <instructions> gives more control over compaction, for example /compact Focus on the API changes.
  • Summarize from here / up to here compacts only part of the conversation.
  • /btw asks a side question whose answer never enters conversation history.

The same guide gives a rule of thumb: if you have corrected Claude more than twice on the same issue in one session, the context is cluttered with failed approaches. Run /clear and start again with a more specific prompt.

If you ran /clear earlier in the same Claude Code process, the rewind menu shows an extra entry at the top, /resume <session-id> (previous session). Selecting it resumes the conversation from before the clear. It is available until you exit Claude Code or resume a different session.

What does rewind not undo?

Read this section before you rely on rewind. The documentation lists these gaps.

Bash commands

Files modified by Bash commands are not tracked. If Claude runs rm file.txt, mv old.txt new.txt or cp source.txt dest.txt, rewind cannot reverse it. Only direct file edits made through Claude's file-editing tools are tracked, so anything a shell command changes, such as generated files or installed dependencies, is outside rewind's reach.

Subagent edits

A subagent makes edits with the same file tools, but Claude Code usually does not capture those edits in your session's checkpoints. Rewinding restores only the files Claude had already edited in your conversation. The subagent's edits to other files stay, so use git to revert them.

The one documented exception is a skill with context: fork that runs in the foreground (set background: false). It edits your working tree during your own turn, so rewind restores its edits as usual. A forked skill that runs in the background, which is the default, and a background /code-review --fix run are not restored.

Outside changes

Only files edited within the current session are tracked. Manual changes you make outside Claude Code and edits from other concurrent sessions are normally not captured, unless they happen to modify the same files as the current session. If you run several sessions at once, each can rewind only its own work.

Restore skips any tracked path that is a symlink or hard link and shows a Restored the code, but skipped N files warning. The skipped files keep their current contents. Config files that a dotfile manager symlinks into your project and files pnpm hard-links into place are the usual cases. To see which paths were skipped, turn on debug logging with /debug before you restore. The log at ~/.claude/debug/<session-id>.txt names each one. To undo changes to such a file, ask Claude to reverse the edit or edit it yourself.

Messages typed mid-turn

A message you type while Claude is still working has no checkpoint of its own and can be marked "No code restore". The edits Claude made after reading it count toward the prompt that started the turn. To undo those file changes, select the prompt that started the turn and choose Restore code or Restore code and conversation. That reverts Claude's edits from the whole turn, including those made before your message arrived.

A workflow that combines rewind and git

Treat rewind as the fast inner loop and git as the safety net.

  1. Start from a clean tree. Commit or stash before a risky task, so anything rewind misses can be reverted with git.
  2. Let Claude try the risky thing. Anthropic's guide says that instead of planning every move, you can tell Claude to try something risky and rewind if it doesn't work.
  3. Check the result with something that returns pass or fail. Tests, a build or a linter. The best-practices guide recommends giving Claude a check it can run, and the same check tells you whether a rewind is needed.
  4. If it fails, rewind. Use Restore code and conversation for a retry, or Restore code to keep the discussion.
  5. After any rewind, run git status. Look for files Bash created or changed, and for anything a subagent touched. Revert those with git.
  6. Commit when green. The docs are explicit that checkpoints are for quick, session-level recovery and are not a replacement for version control.

You can also reduce the risk in step 1 with a permission rule or a hook that blocks destructive Bash commands, since those are exactly what rewind cannot take back.

Rewind or branch?

Summarize keeps you in the same session. If you want to try a different approach while keeping the original session intact, the docs point to /branch or claude --continue --fork-session instead. Use rewind when you are discarding an attempt, and a branch when you want to keep both.

Resuming later

Checkpoints are saved with the conversation, so closing the terminal does not lose them. claude --continue picks up where you left off, and claude --resume lets you choose from a list. Naming sessions with /rename (for example oauth-migration) makes them easier to find. If you resume an old session and expect rewind to work, remember the roughly 30-day default for snapshot retention.

Conclusion

Each prompt that starts a turn is a restore point, and /rewind gives you code-only, conversation-only or both. The blind spots are Bash side effects, most subagent edits, other sessions and symlinked or hard-linked files. Keep git as the real record: commit before risky work and check git status after a rewind.

Questions people ask

How do I undo changes in Claude Code?

Run /rewind, or press Esc twice on an empty prompt, pick the prompt you want to go back to, and choose Restore code, Restore conversation, or Restore code and conversation. Only edits made through Claude's file-editing tools are restored.

Does Claude Code rewind undo Bash commands like rm or mv?

No. Checkpointing does not track files changed by Bash commands, so those changes cannot be undone through rewind. Use git to recover them.

How many checkpoints does Claude Code keep?

File snapshots are kept for the 100 most recent checkpoints in a session. Snapshots are also deleted by default about 30 days after the session last saved one, unless you raise cleanupPeriodDays.

Is rewind a replacement for git?

No. The documentation describes checkpoints as quick, session-level recovery and says to keep using version control such as Git for commits, branches and long-term history.

Can I use /rewind to shrink the context window?

Yes. The Summarize from here and Summarize up to here options compress part of the conversation without changing files on disk, like a targeted /compact.

Sources

  1. Checkpointing - Claude Code Docs
  2. Best practices for Claude Code

Researched and drafted with Claude, then checked against the sources above. Atlas is an independent product, not affiliated with Anthropic or OpenAI. Claude and Claude Code are trademarks of Anthropic; Codex is a product of OpenAI.