Mono
Join the waitlist

How to undo changes made by an AI coding agent

Undo an AI coding agent’s edits safely: restore one file, discard what it left uncommitted or revert its commit, without losing your own work.

To undo an AI coding agent’s changes, check what changed, then use the matching Git command: git restore for edited files, git clean for new files and git revert for a commit. Save a safety copy with git stash first. Claude Code’s own /rewind can restore code too, but it doesn’t track every change.

This guide starts once you’ve decided to drop the work; reviewing AI code changes helps you decide. Mono shows what changed but doesn’t undo it, so the commands are the same there.

1. Stop the agent and see what changed

First, stop the agent. In Mono, the send button becomes a cancel button while the agent works. In a terminal in the project folder, run:

text
git status
git log --oneline -5

The first lists modified, deleted, staged and new files. The second shows recent commits, including any the agent made. Note which changes are yours: undo commands don’t know who wrote a line.

What you see How to undo it
Modified or deleted file, not staged git restore <path>
Staged change git restore --staged <path>, then undo the file
New, untracked file git clean -n <path>, then git clean -f <path>
A commit you didn’t want git revert <commit>

In Mono, “Show changes” lists modified and new files since the last commit, so it won’t show a commit the agent made.

2. Save a safety copy first

Restore and clean discard uncommitted work permanently, so save everything first:

text
git stash push --include-untracked -m "before undo"
git stash apply --index

The first saves your modified and new files and cleans the working tree; the second puts them back, keeping what was staged. Nothing looks different, but git stash list now holds a copy named “before undo”.

If you undo too much, git restore --source "stash@{0}" <path> brings back an edited file from the newest stash.

3. Undo one file or one part of it

Pick the narrowest command:

  • git restore <path> discards the unstaged edits in that file.
  • git restore --staged <path> unstages a change but keeps the edit in the file.
  • git restore -p <path> asks about each changed part (hunk) separately, which helps when you and the agent edited the same file.
  • git clean -n <path> lists the untracked files that git clean -f <path> would remove. Always give a path.

The git restore documentation explains each option.

4. Undo everything the agent left uncommitted

If none of the changes are yours, discard them all from the project root with git restore --staged --worktree ., then git clean -n . and git clean -f . for new files. Otherwise, work by path.

Here’s a made-up example: you asked an agent to rename the CSS class .btn-primary to .button-main in a “tidy-recipes” project. Earlier, it committed a lockfile update nobody asked for. This time it changed the class in 3 files, reformatted 12 unrelated files and created styles/tokens.css. Meanwhile, you edited README.md by hand, and you want to keep that.

After the safety copy, restore the agent’s files (here, src/ and styles/main.css) and remove its new file:

text
git restore src/ styles/main.css
git clean -n styles/tokens.css
git clean -f styles/tokens.css

Don’t use git restore . here: it would discard your README edit too. If you had edits inside src/, name the agent’s files one by one.

Now git status lists only README.md, and git diff shows only your lines. The lockfile commit is still there.

5. Undo a commit the agent already made

git revert records a new commit that reverses an earlier one. The git revert documentation says it needs a clean working tree, so set your README edit aside first:

text
git stash push -m "readme" README.md
git revert <lockfile commit>
git stash pop

Use the hash from git log, and add --no-edit to skip the message editor. git stash pop brings back “readme” and leaves “before undo” in the list. Now git status lists only README.md, and git log --oneline shows Revert "Update lockfile" on top.

For a pushed commit, prefer revert to git reset, which rewrites history others may already have. If a commit seems lost after a reset or rebase, git reflog lists the commits you’ve recently been on, with their hashes.

6. Use agent checkpoints, with Git as the backup

Claude Code saves a checkpoint before each prompt: run /rewind, or press Esc twice with an empty prompt, to restore the code, the conversation or both. Its checkpointing documentation lists the limits: shell command changes aren’t tracked, outside edits usually aren’t captured, and checkpoints don’t replace version control. Availability also depends on the app you run the agent in.

So make Git your fallback:

  • Commit or branch before each task, so “the last commit” means “before the agent”.
  • Tell the agent not to commit without asking, for example in your AGENTS.md file.
  • Keep approvals on. Mono’s YOLO mode, which accepts every agent request, is off by default. See what to check before allowing.

In Mono, a project’s card opens a terminal in the project folder on your computer, from your phone too (see the remote coding guide). Mono isn’t available yet, but you can join the waitlist.

Written by

Reunified makes apps that bring scattered things back together.

Keep reading

All posts

Coming soon

Join the waitlist

Leave your email and we'll write to you when Mono is ready to download.

Where will you use Mono?