Undo for Claude Code
How to undo Claude Code changes, including what a shell command did
There are three ways back, and each covers a different kind of change. /rewind reverses edits Claude made with its own file tools. Git brings back anything you committed or staged. Neither brings back a file that was never staged or committed and that a shell command deleted or overwrote, and that is the case this page is mostly about, including what to try if it has already happened to you.
Last updated
Which undo covers what
| What changed | /rewind | Git | Plugin |
|---|---|---|---|
| Claude edited a file with its edit tools | Usually | If committed | Yes |
A shell command changed a committed file (sed -i, a formatter, a script) | No | Yes | Yes |
| A shell command deleted or overwrote a file you never committed | No | Only if staged | Yes |
git checkout . or git reset --hard discarded uncommitted edits | No | Only if staged | Yes |
| A gitignored file was deleted | No | No | .env only |
| A database row, a remote resource, a file outside the repository | No | No | No |
The first two columns are built into tools you already have. Use them first; they cost nothing and need no setup. The plugin column holds within the limits below; of gitignored files it covers only root-level .env files.
What /rewind does and does not bring back
In Claude Code, run /rewind, or press Esc twice while the prompt input is empty, to go back to an earlier point in the session and restore the code, the conversation, or both. Claude Code takes a checkpoint before each prompt you send. Its documentation lists exceptions, among them edits made by subagents and a 30-day retention.
Its limit is written in Anthropic's documentation: checkpointing "does not track files modified by Bash commands" (read 9 October 2026). If Claude ran rm, mv, sed -i, a code generator, a formatter or a script it wrote a minute earlier, /rewind cannot undo what those commands changed.
What git can bring back
- A committed file that was changed or deleted:
git restore path/to/file.git restore .does this for every file and discards all other uncommitted edits, so name the file if you can. - A commit that a reset removed:
git refloglists where the branch pointed before.git branch recovered <that commit>keeps it without touching your working tree.git reset --hardalso returns to it, but discards uncommitted changes. - A file you staged with
git addbut never committed: its content is usually still in the object store until git prunes it, about two weeks by default.git fsck --lost-foundwrites the unreferenced blobs into.git/lost-found/other, named by object id and not by file name. Do not rungit gcbefore you have looked.
Git has nothing for a file that was never staged or committed. That is why an agent that deletes one tends to say so. In a Claude Code session on one test machine, told to run rm -rf src on a folder holding two uncommitted files, its reply was: "Deleted src (untracked, so not recoverable from git)."
If you have already lost something
Stop the agent first, so nothing else is written over what you want back. Then try these in order. None of them needs anything installed beforehand.
- The session transcript. Claude Code keeps each session as a JSONL file under
~/.claude/projects/, in a folder named after the project path. Files Claude read, wrote or edited usually appear there as tool results or tool inputs, so content can often be copied out. Transcripts are deleted after 30 days by default, and partial reads and edits hold only part of the file. Search the folder for the file name. - Your editor's local history. In VS Code and editors built on it, open the Explorer, find the Timeline panel, and look for the file; for a deleted file, run "Local History: Find Entry to Restore" from the command palette. It only holds files you saved in the editor.
git fsck --lost-found, if the file was ever staged withgit add.- System backups: Time Machine on macOS, File History on Windows, or snapshots if your file system takes them.
If none of those has it, the content is gone. The next section is about not being here a second time.
Undo that covers shell commands
Provenrail is a free, MIT-licensed plugin that takes a snapshot of the working tree before every tool call that can change a file in a git repository, Bash included. It snapshots the tree and not the file a tool names, because a shell command does not say what it will touch. In Claude Code:
/plugin marketplace add pofky/provenrail
/plugin install provenrail-guard@provenrail
There is no package to install, no account, no config file and no server. It needs python3, which most macOS and Linux developer machines already have. After that:
/guard-undo list checkpoints, with what each action changed
/guard-undo last put the tree back to before the most recent action
The snapshots go into a second git object store under ~/.provenrail. Your project's own .git is never written: no stash, no commit, no ref, nothing new in git status. A restore first snapshots the current state, so an undo can itself be undone, and a full restore is checked by tree hash before it prints "Verified: the working tree now matches the checkpoint exactly."
In the rm -rf src session above, /guard-undo last wrote both uncommitted files back with identical checksums. On a 381-file repository on the same machine the first snapshot took 1.04 seconds and each one after it 0.03 seconds.
What this undo does not cover
- Gitignored files, apart from root-level
.envfiles. That excludesnode_modules, build output and anything else your.gitignorenames. - Files over 50 MiB. They are skipped and listed.
- Commits, branches and stashes in your real repository. Use
git reflogfor those. - Nested repositories and submodules. They are recorded as a pointer and a restore never touches them.
- Databases, remote resources and anything outside the repository.
- Folders that are not git repositories. It does nothing there.
- Anything older than 14 days. Checkpoints are deleted after that.
- A change made before the plugin was installed.
If a snapshot cannot finish in 10 seconds, checkpoints pause for that project and Provenrail says so; the tool call still runs. It is a way back from a mistake, not a backup. The plugin has been driven end to end on Claude Code only.
Questions
- How do I undo Claude Code changes?
- Run /rewind in Claude Code, or press Esc twice while the prompt input is empty, to reverse edits Claude made with its own file tools. For a committed file that a shell command changed, run git restore with the file's path. For a file that was never staged or committed and that a shell command deleted or overwrote, neither works: only a snapshot taken before the command has the content, which is what the free Provenrail plugin takes before every tool call that can change a file in a git repository.
- Does /rewind undo changes made by a Bash command in Claude Code?
- No. Anthropic's Claude Code documentation states that checkpointing does not track files modified by Bash commands. If Claude ran rm, mv, sed -i, a formatter or a script, /rewind cannot undo what that command changed. Git can restore the file if it was committed, and a working-tree snapshot taken beforehand can restore it if it was not.
- Can I recover a file Claude Code deleted that was never committed to git?
- Sometimes. Claude Code stores each session as a JSONL file under ~/.claude/projects, and files Claude read, wrote or edited usually appear there as tool results or tool inputs, so content can often be copied out. Transcripts are deleted after 30 days by default, and partial reads and edits hold only part of the file. Your editor's local history may hold it if you saved the file there, git fsck --lost-found can recover it if it was ever staged, and a system backup such as Time Machine may have it. If none does, the content is gone.
- How do I undo git checkout or git reset --hard run by Claude Code?
- A commit removed by a reset can be found with git reflog and kept with git branch recovered followed by that commit, which does not touch the working tree. Uncommitted edits that git checkout . or git reset --hard discarded are not in git at all. Unless they were staged, they can be restored only from something that captured the working tree first: your editor's local history, a backup, or a snapshot such as the one the Provenrail plugin takes before each tool call that can change a file.
- Is there an undo for Claude Code that covers rm -rf?
- Provenrail is a free MIT-licensed Claude Code plugin that snapshots the working tree into a separate git object store before every tool call that can change a file in a git repository, including Bash. In a session on one test machine where Claude ran rm -rf on a folder holding two uncommitted files, /guard-undo last restored both with identical checksums. It does not cover gitignored files other than root-level .env files, files over 50 MiB, databases or anything outside the repository, and it keeps checkpoints for 14 days.
- Does the Provenrail undo plugin change my git repository?
- No. Snapshots are written to a second git object store under ~/.provenrail on your own disk. The project's real .git directory is never written, so there is no stash, no commit, no ref and nothing new in git status. Undo uploads nothing and needs no account. The optional phone remote is separate: if you set it up, it sends approval questions to the messaging service you choose.