Skip to content
← Back to the blog
appssoftware development

Cursor broke my code: how do I undo the AI's changes?

How to roll back changes from Cursor or another AI agent: checkpoints, Claude Code's /rewind, the right git command for each case, and what none of them undo.

By Devonauts Team6 min read
Leer en español →
A woman grips her hair in frustration while looking at her laptop

If Cursor's agent broke your code, the quickest way back is the Restore Checkpoint option on the chat message before things went wrong: it returns every file the agent edited to how it was at that point. If the damage is older than the current chat, or came from commands the agent ran in the terminal, use git instead: git restore throws away uncommitted edits and git revert undoes a commit. Claude Code has the same kind of safety net under /rewind.

This guide covers each way back in the order to try them, what each one cannot undo, and the habits that turn the next bad edit into a one-click fix.

What should I do before undoing anything?

Stop the agent and stop prompting. Every new "please fix it" adds edits on top of the broken ones and makes the last good state harder to find.

Then work out three things:

  1. When did it last work? Scroll the chat and find the last message after which the app still ran. If you use git, git log --oneline lists your commits with their messages.
  2. What changed? git status lists modified, new and deleted files. git diff --stat shows how many lines changed in each one. A small feature that touched 25 files is a sign the agent wandered.
  3. Was it only code? Check the chat for terminal commands: package installs, file moves, database migrations, SQL. Those need extra care, covered below.

How do I restore a checkpoint in Cursor?

Cursor's agent creates checkpoints automatically before significant changes during an Agent session. Each one captures the state of the files the agent modified.

  1. In the chat, find the message just before the change that broke things.
  2. Click its checkpoint in the timeline to preview your files at that point, or hover over the message and use Restore Checkpoint.
  3. Restore. The files go back; the conversation stays where it is.
  4. Reload the app and confirm the problem is gone before you prompt again.

Know the limits. According to Cursor's checkpoint documentation, checkpoints are stored locally, separate from git, and are meant only for undoing agent changes. The docs describe file state only, so don't count on them to reverse npm install, a renamed folder or a database change. They are also not a history you can rely on next week.

How do I undo in Claude Code?

Run /rewind, or press Esc twice with an empty prompt, to open the rewind menu. Pick the prompt you want to go back to and choose Restore code, Restore conversation, or Restore code and conversation.

Claude Code takes a checkpoint before each prompt you send and keeps them with the conversation, so /rewind still works after you resume a session. The checkpointing docs are clear about the gaps: files changed by shell commands (rm, mv, cp) are not tracked, edits you make outside Claude Code usually aren't either, and old snapshots are cleaned up after about 30 days by default. For anything outside those limits, git is your undo.

Which git command undoes what?

If the project is in git, these cover almost every case. Run git status first so you know what you're about to throw away.

What happenedCommandNotes
The agent edited files and you want all of it gonegit restore .Only affects uncommitted changes to tracked files
One file is wrong, the rest is finegit restore src/pages/Checkout.tsxUse the path from git status
The agent created new files you don't wantgit clean -n, then git clean -f-n previews. Ignored files such as .env stay unless you add -x
The agent committed the bad changegit revert <commit>Adds a new commit that undoes it. Safe even after pushing
You want to go back to an older commit completelygit reset --hard <commit>Rewrites history. Avoid it on a branch others have pulled
You reset and now miss somethinggit reflogLists where your branch pointed recently, so you can reset back to it

To test an old commit before committing to it, run git switch --detach <commit>, start the app, and check it. git switch - takes you back to where you were.

One warning: git reset --hard and git restore discard uncommitted work for good. git reflog can bring back commits, not edits that were never committed.

What if there is no git and no checkpoint?

You still have options, roughly from best to worst:

  • Editor local history. VS Code-based editors keep a local history of saved files, shown in the Timeline view of the Explorer. It only covers files saved in the editor, not files changed by terminal commands.
  • A synced copy. If the project came from Lovable, Bolt or another builder with GitHub sync, the repository there has history even if your local folder doesn't.
  • Computer backups. Time Machine on macOS or File History on Windows, if they were on.

Once you're back to a working state, run git init and make a first commit before anything else.

What about the database?

Undoing code does not undo data. If the agent ran a migration that dropped a column or deleted rows, restoring the code gives you an app that expects data that is no longer there. Check what ran, then look at your provider's backups before you make more changes. Our guide on what to do when an AI agent deleted files or data walks through that recovery.

How do I make the next undo easy?

  1. Commit before every agent task. A commit with a clear message is a restore point that lasts forever.
  2. One branch per task. git switch -c add-invoices before you start. If it goes badly, switch back and delete the branch.
  3. Keep tasks small. A change you can review in five minutes is a change you can undo in five seconds.
  4. Commit when it works. Don't wait for the whole feature; save every working step.
  5. Push to GitHub. Your laptop is not a backup.
  6. Write down the boundaries. A project rules file can tell the agent not to run migrations or delete files without asking. See writing Cursor rules for a real project.
  7. Add a few tests. They tell you which prompt broke what. Start with tests for AI-generated code.

Quick answers

Does restoring a Cursor checkpoint delete my chat? No. It reverts the files and leaves the messages in place, so you can continue from there with a better prompt.

Can a checkpoint undo npm install or a migration? Don't rely on it. Cursor documents checkpoints as snapshots of files the agent modified, and Claude Code says outright that changes made by shell commands aren't tracked.

Is git reset --hard dangerous? It discards uncommitted changes permanently and rewrites the branch. Prefer git revert for anything already pushed.

Do other agentic editors work the same way? Most have some kind of checkpoint or revert, including Devin Desktop (formerly Windsurf), but each has its own limits. Git behaves the same in all of them.

Still broken after rolling back?

Sometimes the last working version was never committed, or the code and the database no longer match. If that's where you are, our Cursor project help and Devin Desktop and Windsurf project help pages explain how we untangle it. You can run the free health check for an outside view of the live app, or tell us what happened and a person will reply within one business day.

Still stuck with your app?

Run the free health check on your app's URL, or get the $299 App Rescue Audit: a senior engineer reviews the code and sends you a written report in 2 business days.