# How to undo Claude Code changes (rewind, git, recovery)

> Undo Claude Code changes with /rewind checkpoints, git and VS Code Local History, and recover files a Bash command deleted. Covers Codex CLI too.

Source: https://ccassist.dev/blog/undo-claude-code-changes/
Published: 2026-10-01
Last updated: 2026-10-01

---

**TL;DR:** To undo Claude Code changes, press `Esc` twice with an empty prompt (or run `/rewind`), pick the prompt before things went wrong, and choose **Restore code**. That only covers edits Claude made with its file-editing tools, within the last 100 checkpoints and about 30 days. Anything a Bash command did (`rm`, `mv`, `sed -i`, a script) is not tracked. For those, use `git restore`, and next time commit before you start a session.

## How do I undo Claude Code changes?

Claude Code saves a checkpoint of your files each time you send a prompt that starts a turn. To go back:

1. Make sure the prompt input is empty, then press `Esc` twice. Or type `/rewind`.
2. Pick the prompt you want to go back to. The list shows every prompt in the session.
3. Choose what to restore:

| Option | Files | Conversation |
|---|---|---|
| **Restore code and conversation** | Back to that point | Back to that point |
| **Restore code** | Back to that point | Kept as is |
| **Restore conversation** | Kept as is | Back to that point |
| **Summarize from here / up to here** | Unchanged | Compressed into a summary |

After a conversation restore, your original prompt comes back into the input box so you can edit and resend it. The code options only appear when that checkpoint has file changes to revert. All of this is in Anthropic's [checkpointing docs](https://code.claude.com/docs/en/checkpointing#rewind-and-summarize) (Claude Code 2.1.x, checked 1 October 2026).

Checkpoints are saved with the conversation, so you can close the terminal, run `claude --resume`, pick the session, and still `/rewind`. If you're not sure which session made the change, [find it in your Claude Code chat history](https://ccassist.dev/how-to/view-claude-code-chat-history/) first.

## What /rewind does not undo

This is where most "undo Claude Code" advice stops short. Rewind only knows about edits made through Claude's file-editing tools (Edit and Write). The docs list what falls outside it:

- **Bash commands.** `rm file.txt`, `mv old.txt new.txt`, `cp`, `sed -i`, a heredoc (`cat > file <<EOF`), a Python one-off: none of these can be undone through rewind.
- **Most subagent edits.** Edits from a background subagent are usually not in your session's checkpoints. The docs say to use git for those.
- **Your own edits and other sessions.** Changes you make in the editor, or that a second Claude Code session makes, are normally not captured.
- **Messages you queued mid-turn.** They join the running turn and get no checkpoint of their own. Rewind to the prompt that started the turn instead.
- **Symlinked and hard-linked files.** Restore skips them and warns `Restored the code, but skipped N files`.

Retention matters too. Claude Code keeps snapshots for the 100 most recent checkpoints in a session and deletes a session's snapshots about 30 days after it last saved one. That is the same [`cleanupPeriodDays`](https://code.claude.com/docs/en/settings-reference#cleanupperioddays) sweep that deletes old transcripts, which we cover in [where Claude Code stores conversations](https://ccassist.dev/blog/where-claude-code-stores-conversations/). If you rewind to a checkpoint whose snapshots are gone, you get [`No files were restored`](https://code.claude.com/docs/en/errors#no-files-were-restored).

![Matrix of undo methods against kinds of change. For Claude's Edit and Write tools: /rewind yes (100 turns, about 30 days), git yes if committed first, VS Code Local History no, CCAssist undo yes (free same day), CCAssist Recovery copies (free today's). For Bash commands: /rewind no, git yes for tracked files, Local History no, CCAssist diff only, Recovery only if a copy was saved earlier. For your own edits: only git and Local History.](https://ccassist.dev/blog/undo-claude-code-changes.png "Coverage by kind of change. Sources: Claude Code checkpointing docs, VS Code docs and CCAssist 0.7.5 source, checked 1 October 2026.")

## Which fix for which problem

| Symptom | Best tool | What to run |
|---|---|---|
| A wrong edit two turns ago, the rest is fine | `/rewind` | Pick the prompt before it → **Restore code** |
| You want the conversation back but keep the code | `/rewind` | Pick the prompt → **Restore conversation** |
| Everything since one prompt is bad | `/rewind` | **Restore code and conversation** |
| Session is closed, change was yesterday | `/rewind` after resume | `claude --resume`, pick the session, `/rewind` |
| Claude ran `rm` on a file git tracks | git | `git restore path/to/file` |
| Claude ran `rm` on an untracked file | Saved copies | See [Recover a file a shell command deleted](#recover-a-file-a-shell-command-deleted) |
| A `sed -i` or script touched many files | git | `git diff`, then `git restore -p` or `git restore .` |
| Undo one hunk, keep the rest | git | `git restore -p path/to/file` |
| A commit vanished after `git reset --hard` | git reflog | `git reflog`, then `git branch rescue HEAD@{1}` |
| You broke a file yourself in VS Code | Local History | Timeline → **Local History: Find Entry to Restore** |
| Codex CLI made the change | git | `git restore` (Codex has no file undo) |
| `/rewind` says `No files were restored` | git or saved copies | Snapshots were swept; check git, then the steps below |

## Make git your real safety net

Anthropic's docs say it plainly: checkpoints are for quick session-level recovery and are ["not a replacement for version control"](https://code.claude.com/docs/en/checkpointing#not-a-replacement-for-version-control). Git sees every change on disk, whichever tool made it. A few habits cover almost every bad session:

```bash
# Before the session: snapshot your starting point
git add -A && git commit -m "wip: before claude session"

# After: see everything that changed, Bash edits included
git status
git diff

# Throw away all uncommitted changes to tracked files
git restore .

# Pick hunks to throw away, one at a time
git restore -p

# Set everything aside (incl. new files) to compare, then bring it back
git stash push -u
git stash pop
```

A WIP commit on a branch costs nothing and you can squash it later. If you prefer not to commit, `git stash push -u` also records untracked files, which a plain `git stash` skips.

`git reflog` is the undo for git itself. It lists every position `HEAD` has been in, so a commit that disappeared after a `reset --hard`, a rebase or a branch delete is usually one `git branch rescue <sha>` away. Git's [reflog docs](https://git-scm.com/docs/git-reflog) have the details.

One more git trick for deleted files: if the file was ever `git add`ed but never committed, the content is still in the object store as a loose blob. `git fsck --lost-found` writes such blobs into `.git/lost-found/other/`, where you can grep for your content.

## Recover a file a shell command deleted

When Claude runs `rm` or overwrites a file with a script, rewind can't help. Try these in order:

1. **Git.** `git restore path/to/file` brings back the last committed version. Untracked? See the `git fsck --lost-found` note above.
2. **Claude Code's own backups.** If Claude edited the file with its edit tools earlier in any session, the pre-edit copy may still be in `~/.claude/file-history/<session-id>/`. Files there are named `<hash>@v<n>`, not by path. The session transcript maps paths to them in `file-history-snapshot` lines:

   ```bash
   jq -r 'select(.type=="file-history-snapshot")
     | .snapshot.trackedFileBackups | to_entries[]
     | select(.key | endswith("src/config.ts"))
     | "\(.value.backupTime)  \(.value.backupFileName)"' \
     ~/.claude/projects/<project-folder>/<session-id>.jsonl | sort -u
   ```

   Then copy `~/.claude/file-history/<session-id>/<backupFileName>` back into place. This key layout is what Claude Code 2.1.286 writes (checked 1 October 2026). It's undocumented, so it may change.
3. **The transcript itself.** If Claude created the file with the Write tool, or read it in full, the session `.jsonl` holds that content as text. Search it for a line you remember.
4. **VS Code Local History.** VS Code adds an entry [each time you save a file in the editor](https://code.visualstudio.com/docs/getstarted/userinterface#_timeline-view). If you ever saved the file in VS Code, open the Timeline view's `...` menu and run **Local History: Find Entry to Restore**. Writes by a terminal CLI are not editor saves, so don't count on it for Claude's own edits.
5. **OS backups.** `rm` skips the Trash. Time Machine, File History on Windows or a snapshot filesystem is the last resort.

## Does Codex CLI have an undo?

Not for files, as of 1 October 2026. Codex CLI had an experimental `/undo` that used "ghost" git commits. It was removed; in [issue #9203](https://github.com/openai/codex/issues/9203) a maintainer wrote on 16 January 2026 that it "was causing many issues even for users who did not use the feature" and would need a redesign to return. The current [slash command list](https://github.com/openai/codex/blob/main/codex-rs/tui/src/slash_command.rs) has `/diff` (git diff including untracked files) and `/fork`, but no undo or rewind.

Pressing `Esc` twice in Codex opens an earlier prompt to edit and fork the chat from. Files stay as they are: [issue #11626](https://github.com/openai/codex/issues/11626), still open, asks for a `/rewind` that also reverts code. So with Codex, git is the undo. Run `/diff` to see what changed, then `git restore`.

## Where CCAssist fits

[CCAssist](https://marketplace.visualstudio.com/items?itemName=agsoft.claude-history-viewer) is our VS Code extension for Claude Code and Codex CLI history. It helps when the change is in a past session, when you want to undo one file rather than a whole turn, or when a file is gone. Everything below is in version 0.7.5 (released 27 September 2026):

- **Diffs per turn and per file.** Each prompt in a conversation shows which files it changed, with a diff. Shell edits (heredocs, `sed -i`, redirects) are detected and shown as diffs too, so a Bash change doesn't go unseen.
- **Undo and reapply.** Undo a single change, one file's changes in a turn, or all files in a turn, and reapply them later. It works backwards from the recorded edits, trying all of them in memory before writing. Shell-made changes are shown but **not undoable**, because there's no recorded before-state. New-file creations aren't undoable here either.
- **Conversation checkpoints.** Prompts show the files as they were when the prompt was sent, and you can compare them with the current version.
- **Recovery tab.** Lists every full copy of a project file that Claude, Codex and Grok sessions left behind: Claude's file-history backups, Write tool contents, files Codex added with `apply_patch`, and Grok's rewind snapshots. Filter by **Deleted** or **Changed**, compare a copy with the current file, and restore it. It only scans when you open the tab.

**Free vs Pro:** on the Free plan, diffs and undo/redo work for same-day changes, and Recovery opens today's copies. [Pro](https://ccassist.dev/upgrade/) removes those limits and adds **Undo All** in the review panel.

What it does *not* do: bring back a file no session ever saved a full copy of, undo Bash changes, or replace git.

## How we checked

- Claude Code behaviour from the [checkpointing](https://code.claude.com/docs/en/checkpointing) and [`.claude` directory](https://code.claude.com/docs/en/claude-directory) docs, read 1 October 2026; the `file-history` layout and `jq` query checked against a local Claude Code 2.1.286 install (key shapes only).
- Codex CLI from `openai/codex` `main` (`slash_command.rs`) and issues #9203 and #11626, read 1 October 2026.
- VS Code Local History from the [user interface docs](https://code.visualstudio.com/docs/getstarted/userinterface#_timeline-view), read 1 October 2026.
- CCAssist features and Free/Pro limits from the extension source and changelog at version 0.7.5.

Install [CCAssist from the Marketplace](https://marketplace.visualstudio.com/items?itemName=agsoft.claude-history-viewer) (or [Open VSX](https://open-vsx.org/extension/agsoft/claude-history-viewer)) and you'll see each session's file changes with per-turn diffs and undo buttons, plus a Recovery tab listing saved copies of your project's files.

## Frequently asked questions

### How do I undo Claude Code changes?

Press Esc twice with an empty prompt, or run /rewind, pick the prompt before the bad change, and choose Restore code. This covers edits made with Claude's file-editing tools. For changes made by Bash commands, use git.

### Does /rewind undo files Claude deleted with rm?

No. Checkpointing does not track files changed by Bash commands such as rm, mv, cp or sed -i. Restore a tracked file with git restore, or look for a saved copy in ~/.claude/file-history if Claude edited the file earlier in a session.

### How long are Claude Code checkpoints kept?

Claude Code keeps file snapshots for the 100 most recent checkpoints in a session, and the retention sweep deletes them about 30 days after the session last saved one. Raise cleanupPeriodDays in settings to keep them longer.

### Does Codex CLI have an undo or rewind command?

Not for files, as of 1 October 2026. The experimental /undo was removed, and Esc Esc in Codex rewinds the conversation but leaves file changes in place. Use git to revert Codex's edits.
