AI Broke My Code: How to Fix It
Your AI coding assistant just broke your project. Here's how to recover your code and get back to a working state fast.
Your AI assistant just turned your working code into a mess of errors. Maybe it refactored something it shouldn’t have. Maybe it deleted files it thought were “unused.” Maybe it hallucinated imports that don’t exist.
Take a breath. Your code is probably recoverable, though how quickly depends on what protection you had in place.
First: Stop and Assess
Before you do anything else:
- Don’t keep prompting the AI to “fix it” — that often makes things worse
- Don’t close your editor — files may still be in memory
- Don’t restart anything — you might lose undo history
Now let’s get your code back.
If You Have mrq Running
If you set up mrq before this happened, recovery takes one command:
mrq history # See recent snapshots
mrq restore abc123 # Pick the one from before things broke
Your code is back to a working state. Doesn’t matter how many files the AI touched or how many changes ago the breakage started, since every state was captured automatically.
This is why developers who rely heavily on AI keep mrq running in the background. When things break (and they will), recovery is instant.
If you had mrq running, that’s all you need. If not, keep reading for other options.
If You Don’t Have mrq (Fallback Options)
Without automatic snapshots, recovery is harder and less reliable. Here are your options.
Ctrl+Z (Immediate Undo)
Hit Cmd+Z (Mac) or Ctrl+Z (Windows/Linux) repeatedly in each affected file.
Limitation: Each file has its own undo history. If the AI broke 20 files, you need to undo in each one separately. If you’ve made other edits since, undo might not get you to the right state. And after accepting AI suggestions, undo behavior can be unpredictable.
Tool-Specific Recovery
Cursor Checkpoints: Look for “Checkpoint created” in the Composer panel. Click “Restore” next to the one from before things broke.
Limitation: Only covers Composer interactions. Tab completions and Agent mode often have no checkpoints. Doesn’t persist across sessions.
Claude Code:
Use /undo to revert the last change, or /undo all to revert the entire conversation.
Limitation: Only works within the current session. If context was lost, these commands won’t help.
GitHub Copilot: No built-in recovery. You’re relying on Ctrl+Z and Git.
VS Code Local History
Press Cmd+Shift+P → “Local History: Find Entry to Restore”. Select files and pick timestamps from before the breakage.
Limitation: File-by-file recovery. Tedious if many files are affected. Only works for files that were open at some point.
Git (If You Committed)
If you committed before the AI made changes:
git diff # See what changed
git checkout . # Discard all uncommitted changes
Or restore specific files:
git checkout HEAD -- src/auth.ts src/utils.ts
Limitation: Git only saves what you committed. If you were iterating quickly without commits, Git can’t help. And the one time you forget to commit is usually the time AI goes haywire.
Common AI Breakages
| What Happened | Without mrq | With mrq |
|---|---|---|
| AI deleted files | Hunt through Local History file-by-file | mrq restore |
| AI broke imports | Ctrl+Z in each file, hope it works | mrq restore |
| AI refactored too much | Restore Checkpoint (maybe) | mrq restore |
| AI introduced bugs | Manual fix or git checkout (if committed) | mrq restore |
| AI changed wrong files | Git checkout per file (if committed) | mrq restore |
Why This Keeps Happening
AI coding assistants are trained on patterns, not understanding. They will occasionally:
- Misinterpret what you asked for
- Delete files they think are unused
- Make changes to files you didn’t mention
- Hallucinate imports or function names
- “Clean up” code you wanted to keep
You can write better prompts and review diffs carefully. But you can’t eliminate the risk. AI will occasionally break things in ways that take time to fix manually.
What matters is whether recovery takes 3 seconds or 30 minutes.
Set Up Protection Now
If you’re reading this after AI broke your code, you now understand why automatic snapshots matter.
mrq runs in the background and captures every file change:
npm install -g mrq-cli
mrq login
mrq watch
Now every change is captured automatically, from any AI tool, any editor, any operation.
Next time AI breaks something:
mrq restore abc123
Back to exactly where you were, without hunting through checkpoints or hoping you committed.
Developers who work confidently with AI tend to have recovery set up before they need it.
Summary
With mrq running, mrq restore gets you back in seconds. Without it, you’re looking at Ctrl+Z, Checkpoints, Local History, or Git, which are less reliable and more time-consuming. For next time, automatic snapshots mean recovery is always instant.
Related Reading
- AI Deleted My Files: Recovery for Cursor, Claude, Copilot - File deletion specifically
- How to Undo Changes in Cursor AI - Cursor-specific recovery
- How to Undo in Claude Code - Claude Code recovery
- Backup Your Code Before Using AI - Prevention strategies
mrq captures every file change automatically while you code with AI. One command to start, instant recovery when things break.
Written by mrq team