AI Deleted My Code: How to Recover
Source: Dev.to

First: Don’t Close Anything
Your editor likely still has deleted files in memory. Every tab you close is a potential loss. Keep everything open while you work through this.
Check Your Editor’s Undo History
If the deleted file’s tab is still open, try Ctrl+Z (or Cmd+Z on Mac) repeatedly. Sometimes the file content is recoverable even after the file itself was deleted from disk. This doesn’t always work, especially for files the AI deleted without opening, but it’s worth trying first.
Use Local History
Both VS Code and Cursor maintain a local history of file changes that most developers don’t know about.
- Press
Ctrl+Shift+P(orCmd+Shift+P). - Type Local History: Find Entry to Restore.
- Browse for your deleted files.
This works even for files that were deleted, as long as they were edited at some point.
Check Your AI Tool’s Recovery Features
- Cursor: Look for “Checkpoint created” messages in the Composer panel. Each prompt creates a checkpoint you can restore to. Click Restore next to the one from before the deletion.
- Claude Code: Press
Esctwice or type/rewindto open the checkpoint menu. You can restore just the code, just the conversation, or both.
These features are tied to conversation context. If you’ve done a lot of work since the deletion, or if the deletion happened through tab completions rather than the Composer, you might not have a useful checkpoint.
Fall Back to Git
If you committed before the AI made its changes, Git can restore your files:
git status # See what's been deleted
git checkout . # Restore everything to the last commit
If you didn’t commit, Git can’t help—this is why regular commits are essential.
When Nothing Works
Check your system backups:
- macOS: Time Machine
- Windows: File History
- Cloud sync services: Dropbox, OneDrive, Google Drive, etc.
These may keep recent versions of your files. It’s a long shot, but sometimes it works.
Preventing This Next Time
AI agents are unpredictable. Better prompts and careful diff reviews help, but they don’t eliminate risk. The solution is to have recovery baked in, not bolted on.
Using mrq
mrq watches your project directory and captures every file change automatically—no manual commits required.
mrq watch # Start watching the project
mrq history # See recent snapshots
mrq restore abc123 # Restore to a specific snapshot
With mrq, you’re back to exactly where you were, even if you never committed. Every change is captured, every state is recoverable.
mrq captures every file change automatically while you code with AI. Set it once, recover instantly when things break.