Skip to content
Black FridayBlack Friday: both apps $5.99, ends 1 Dec

Guide

How to undo what a coding agent changed on your Mac

Claude Code, Cursor and Codex can edit dozens of files in a minute. Here is how to see exactly what one changed, and the fastest way to put it back, whether or not the files were in git.

By · Updated · 7 min read

The short answer

If the project uses git, run git status and git diff to see what the agent changed, then git restore <file> to put a file back. Inside the tools, Claude Code has /rewind and Cursor has Restore Checkpoint; Codex CLI has no command that restores files. Files never committed to git need Time Machine or Agent Undo.

On this page

First: stop the agent and look before you fix

Stop the session (Esc in Claude Code and Codex, the stop button in Cursor) so it doesn't keep editing while you work out what happened. Don't ask it to fix its own change yet: each new edit makes the original harder to get back. Then find out what changed.

See and undo the changes with git

If the folder is a git repository, git already knows every difference from your last commit. Run these in Terminal from the project folder:

See what changed
git status          # files changed, deleted and added
git diff            # the exact lines changed in tracked files
git clean -n        # new untracked files (only lists, deletes nothing)
  • The agent edited a file

    Command
    git restore path/to/file
  • The agent deleted a tracked file

    Command
    git restore path/to/file
  • Undo every change to tracked files

    Command
    git restore .
  • Keep the changes aside instead of losing them

    Command
    git stash push --include-untracked
  • The agent made a commit

    Command
    git log, then git revert <commit>
  • You undid too much

    Command
    git reflog lists where the branch has been, so you can go back to it
Putting things back with git

Git can only restore what it has seen. A file that was never committed and that the agent changed or deleted isn't in git's history, so git restore can't bring it back. Files deleted with rm don't go to the Trash either. For those, see files that were never in git.

Claude Code: /rewind

Claude Code takes a checkpoint before each prompt you send. Run /rewind (or its alias /undo), or press Esc twice with an empty prompt, pick the prompt to go back to, and choose Restore code to put the files back while keeping the conversation, or Restore code and conversation to rewind both. Checkpoints are saved with the session, so you can resume a session and still rewind it.

  • Shell commands aren't covered. A file changed only by a Bash command, such as rm, mv or a script, isn't tracked and stays as it is.
  • Most subagent edits aren't restored, except to files Claude had already edited in your conversation.
  • Symlinked and hard-linked files are skipped, which includes files pnpm hard-links into place.
  • Snapshots expire: by default they are deleted about 30 days after the session last saved one.

Cursor: Restore Checkpoint

Cursor's Agent saves a checkpoint before significant changes. Click Restore Checkpoint on an earlier request, or hover over a message and click +, to put every modified file back as it was at that point. Restoring changes files only: the messages stay in the chat. Cursor keeps checkpoints on your Mac, separate from git, and its documentation says to use them only for undoing Agent changes.

Codex CLI: use /diff, then git

Codex CLI's slash commands include no command that restores files (checked 22 November 2026). Run /diff to see what Codex changed, staged, unstaged and untracked, then undo it with git as above. Esc twice with an empty composer edits your previous message and forks the chat; it doesn't put files back.

For a big task, /worktree runs Codex in a separate git worktree, so its changes stay out of your working copy until you merge them.

Files that were never in git

New files, .env files, local databases and anything in .gitignore aren't in git's history. If an agent overwrote or deleted one, try these in order:

  1. The agent's own undo, if the agent edited the file with its editing tools (Claude Code's /rewind, Cursor's Restore Checkpoint).
  2. The Trash, if the file was moved there rather than deleted with rm.
  3. Time Machine. Open the project folder in Finder, then open Time Machine with Spotlight. Use the arrows to go back to a backup from before the session, select the file and click Restore. Time Machine also keeps local snapshots on the Mac's own disk; how to check when Time Machine last backed up shows how to list them.
  4. Your editor's local history. In VS Code and Cursor, the Timeline view and the Local History: Find Entry to Restore command (press Command-Shift-P to find it) keep earlier versions of files you edited in the editor.

Agent Undo in iKnowMyMac

iKnowMyMac's Agent sessions, under Projects, follows each coding agent session from the moment the agent starts, such as Claude Code, Codex CLI, Gemini CLI or Cursor's agent. Agent Undo keeps copies of the files in folders where agents work, so each session's card lists what it deleted, changed and added in the project folder, with Changes and Undo… buttons.

  • Put back one file, a few, or the folder as it was when the session started, including files that were never in git.
  • A confirmation first lists what will be restored, replaced, removed and left alone.
  • Undo the undo: whatever a restore replaces is kept first, so the restore can be taken back too.

Limits: the copies stay on your Mac, on the same disk as the originals, so this is not a backup; keep Time Machine on. The newest change can be missed, and git history isn't covered: it puts files back, not commits.

The Agent sessions section in iKnowMyMac: a Claude Code session that ended 22 minutes ago left next dev, vite and a node watcher running on ports 3000 and 5173, a live Codex CLI session, and a Cursor Agent session that left nothing running. Above the sessions, Agent Undo says 3 folders are protected and up to date, and each session's card ends with what it did to its folder, such as 14 changed, 3 deleted and 6 added, with Changes and Undo buttons.
Agent sessions in iKnowMyMac, rendered from the app with simulated sessions and figures.

Before the next session

  • Commit or stash first. A clean git status before you start means git diff shows only the agent's work.
  • Give big tasks their own branch or worktree (git worktree add ../task-branch -b task-branch, or Codex's /worktree).
  • Keep secrets and data out of the agent's folder, or at least out of the files it is asked to touch.
  • Keep Time Machine on. It's the one option here that keeps copies on another disk.

FAQ

Questions

Something else? support@iknowmymac.com

Can I undo a Claude Code change after I closed the session?

Usually, yes. Claude Code saves checkpoints with the conversation, so resume the session and run /rewind. By default the file snapshots are deleted about 30 days after the session last saved one, and changes made only by shell commands were never tracked.

Why didn't /rewind put my file back?

Claude Code's checkpoints don't track a file that only a Bash command changed, most subagent edits, or symlinked and hard-linked files, which includes files pnpm hard-links into place. Use git restore for tracked files, and Time Machine for the rest.

Does Codex CLI have an undo command?

Not for files, as of 22 November 2026: its slash commands include no command that restores files. Run /diff to see what changed, then use git restore or git stash. Running a big task in a worktree with /worktree keeps it apart from your working copy.

The agent deleted files that were never in git. Can I get them back?

Git can't restore them. Check the agent's own undo (Claude Code's /rewind, Cursor's Restore Checkpoint), then the Trash, then Time Machine and its local snapshots. iKnowMyMac's Agent Undo can put them back from its copies of the project folder.

Is Cursor's Restore Checkpoint the same as git?

No. Cursor stores checkpoints on your Mac, separate from git, and its documentation says to use them only for undoing Agent changes and git for permanent version control. Restoring a checkpoint changes files only; the chat messages stay.

Know why your Mac is slow.

macOS 15 Sequoia or later · Apple silicon. A 55.3 MB native app, notarized by Apple. No account, no analytics, no telemetry.

One-time purchase · every feature · 5-day refund