How to Undo Claude Code Changes (With or Without Git)

· 7 min read· Читать по-русски

To undo Claude Code changes in the current session, press Esc twice (or type /rewind), pick the message before things went wrong and choose Restore code. That brings back files Claude edited with its own editing tools. It does not bring back files that Claude deleted, moved or copied with terminal commands, edits made by most subagents, or anything older than the session's checkpoints. For those, you need a real history: git, a cloud drive's version history or a backup. Below is what each option can and can't undo, in plain words, and how to avoid losing work next time.

Step 1: /rewind, Claude Code's built-in undo

Claude Code saves a checkpoint before every prompt you send. According to Anthropic's checkpointing docs:

  • How to open it: run /rewind, or press Esc twice when the prompt box is empty.
  • What you can restore: the code and the conversation, just the conversation, or just the code. Pick the message you want to go back to.
  • How far back: file snapshots for the 100 most recent checkpoints of a session. Checkpoints survive closing and resuming a session, but snapshots are deleted about 30 days after the session last saved one.

The limits matter more than the features:

/rewind brings back /rewind does not bring back
Files Claude changed with its edit and write tools Files changed by terminal commands: rm, mv, cp and the like
Edits made in this session Your own edits outside Claude Code, and edits from other sessions
Edits of a skill running in the foreground Most subagent edits, including background ones
Symlinked or hard-linked files
Anything sent elsewhere: an upload, an email, a deploy

The docs end with a clear warning: checkpoints are for "quick, session-level recovery," not a replacement for version control.

Step 2: asking Claude to undo — carefully

"Undo that" sounds like the easiest fix. It can be the riskiest. In one Claude Code bug report, a request to roll back led Claude to run git reset --hard, which wiped a morning of uncommitted work. The report was closed as a duplicate of an older one about the same command.

If you ask the agent to put something back:

  • Name the file and the moment: "Bring notes/plan.md back to how it was in the last saved version", not "undo that."
  • Ask for the plan first: "Tell me which command you'll run before you run it."
  • Say no to anything that throws work away. git reset --hard, git checkout -- . and git clean discard unsaved changes. A safe undo adds a new version on top; it doesn't erase history.

Step 3: with git, undo is a new version

If your project is a git repository, every saved version (commit) can be brought back, as long as it was saved. Two kinds of undo cover almost everything:

  • One file back to an earlier version. git restore --source=<version> -- path/to/file puts the file back as it was in that version. Your other files stay as they are.
  • A whole version undone. git revert <version> makes a new version that cancels that one. History keeps both, so the undo can itself be undone.

Both are "forward" undos: nothing is erased. If you're not sure which version to go back to, git log lists them with messages; Claude Code's commits carry a Co-Authored-By: Claude line by default, so the agent's versions are easy to spot.

What git can't help with: changes that were never saved as a version. If the agent edited files and then something wiped them before a commit, git has nothing to restore. That is why the habit in step 5 matters.

Step 4: without git

No git, no history? You still have options, depending on where the folder lives:

  • A Google Drive folder. Drive keeps earlier versions of each file. Its help page says a version "might be permanently deleted after 30 days or if there are 100 newer versions" unless you mark it Keep forever. On drive.google.com: right-click the file, then File information > Manage versions, and download the version you want.
  • Yandex Disk keeps file history only inside its own apps (14 days on the free plan, longer with Yandex 360), not for other programs.
  • Time Machine (Mac) or File History (Windows). If backups were on, open the project folder and step back in time.
  • A copy of the folder. Many guides for non-developers suggest duplicating the project before a big session. Low-tech, and it works.

If none of these exist, check whether the file is still open in an app with its own undo or autosave. After that, honestly, the change is gone, and it's time to set up git (the agent can do it for you in one prompt).

Undo in X-Filer, without git words

This part is about our own product. X-Filer is a desktop app for Windows and macOS we make for people who run a project with Claude Code. It shows the project's versions in a feed — each marked Agent or You — and two buttons do the undoing:

  • Restore as it was brings one file back to how it was before a version.
  • Revert version undoes a whole version.

Both add a new version instead of rewriting history, so any undo can be undone. If the file has unsaved changes, X-Filer saves them as a version first, so even those aren't lost. And if a later version touched the same lines, Revert version doesn't guess: it stops, tells you that you and the agent edited the same place, and leaves the files as they were.

Where it works, honestly:

  • A project on your computer with git: both buttons. Git has to be installed; you never see its commands.
  • A GitHub repository: both buttons, after a GitHub sign-in. Each undo is a new version on GitHub.
  • A Google Drive sync folder (macOS for now): Restore as it was, from Drive's revisions, once that Drive account is connected in X-Filer. There's no whole-version undo, because a drive has file revisions, not project versions.
  • A Yandex Disk folder: X-Filer shows which files changed, but can't bring an old version back, since Yandex Disk gives no file history to other apps.
  • A folder without git: you can read and edit, but there's no history to undo from. X-Filer suggests how to keep the project and copies a ready task for Claude Code to set it up.

Agent vs. you is told apart by Claude Code's commit signature only. See the agent projects page for the whole picture, or our guide on seeing what Claude Code changed.

Step 5: make the next undo easy

  • Keep the project in git, even if you never touch git. Ask the agent: "Set this folder up as a git repository and save a version after each task." Then every task has a version to come back to.
  • Put it on GitHub. That gives you a copy off your computer, and cloud sessions need it anyway.
  • Write the rule into CLAUDE.md. For example: "Never run git reset --hard, git checkout -- . or git clean. Ask before deleting files." CLAUDE.md guides the agent rather than enforcing anything, so keep backups too.
  • Look before you leave. A quick check of the Changes panel at the end of a session catches most surprises while /rewind can still fix them.

FAQ

Can I undo Claude Code changes after closing the session?

Yes, if you resume it: checkpoints are saved with the conversation, so /rewind still works after claude --resume until the snapshots are cleaned up (about 30 days by default). For anything older, you need git or a backup.

Why didn't /rewind restore a deleted file?

Because the file was probably deleted by a terminal command such as rm. Checkpoints only track edits made with Claude's file editing tools. Look in the Trash, your drive's version history, or a backup.

How do I undo only one file?

In /rewind, restoring code brings back every file Claude edited after that point. To bring back just one file, use git (git restore --source=<version> -- <file>), your drive's version history, or Restore as it was in X-Filer.

Bottom line

/rewind is the fastest undo inside a session, but it only knows what Claude edited with its own tools. Everything else needs a history, and git is the simplest one to have, even if you never type a git command. If you'd rather see the agent's versions and undo them with a button, try X-Filer.

Read next