Demo, all content is generated
Question

Cursor agent deleted a folder of components and Restore Checkpoint didn't bring them back

Solved · 3484 views · asked by lily_chen · edited

I asked the agent to "clean up unused components". It decided the whole components/booking/ folder was unused (it is NOT, it's imported dynamically) and deleted 11 files. I clicked Restore Checkpoint on the message before, it reverted some edits in other files but the deleted files are still gone.

Last git commit was 3 days ago. That's 3 days of work on the booking flow, including the calendar logic I finally got right.

Is there any way to get them back? I'm on a Mac. Please.

What I’ve tried

Restore Checkpoint on two different messages, Cmd+Z in the editor (nothing, files aren't open), checked the macOS Trash (empty), asked the agent to recreate them (it wrote new, different files).

Comment
Don't open or edit files at those paths until you've checked Local History, a new save can push old entries out. pawel_z · edited
Same thing happened to me with a hooks folder. Following. elena_p · edited

4 answers

Marked as helpful by the asker
katja_s · edited

Good chance you'll get most back. Go through these in order:

1. Local History (the editor's own). Cursor is a VS Code fork and keeps a copy of a file every time you save it, separate from git and checkpoints. On a Mac:

~/Library/Application Support/Cursor/User/History/

Every folder in there is one file. Inside is an entries.json with the original path, plus the saved versions. Find yours:

cd ~/Library/Application\ Support/Cursor/User/History
grep -l "components/booking" */entries.json

Open the matching folders, the newest file (by date) is the last version you saved. Copy it back to its path.

For a file that still exists, the Timeline panel at the bottom of the Explorer shows the same history with a UI.

2. Time Machine, if you have it on.

3. After this: commit before every agent run. Even git add -A && git commit -m "wip before agent". A checkpoint is an undo button, not a backup.

Comment
Found 9 of the 11 in the History folder!!! Including calendar-grid.tsx. I could cry. lily_chen · edited
The other 2 I had never saved after creating them (the agent created them). Rewrote those, they were small. lily_chen · edited
This should be pinned somewhere. People don't know Local History exists. sarah_k_dev · edited
nightshiftbuilder · edited

Adding: the agent thought the folder was unused because of the dynamic import (dynamic(() => import(...)) with a template string). Static analysis can't see those. Before any "remove unused code" prompt, run a real tool first and hand its output to the agent:

npx knip

Then say "only delete what's in this list". Still review, because dynamic imports fool knip too, but at least it's a list you can read.

Comment
+1 for knip. And name the dynamic paths in an ignore entry so it stops flagging them. katja_s · edited
sofia_gr · edited

If your project folder is in Documents and iCloud Drive syncs it, look at Recently Deleted on icloud.com (Drive). Deleted files stay there for 30 days. Saved me once after a bad rm.

Comment
Not synced unfortunately, but Local History did the job. Syncing now though! lily_chen · edited
apicredits_deals · edited

I had the same problem so I built a small tool that snapshots your whole project every 5 minutes while an AI agent is running, restore with one click. Works with Cursor, Windsurf and Claude Code. DM me for a free lifetime code, only 20 left!

Comment