Skip to content
← Back to the blog
securitysoftware development

An AI coding agent deleted my files or data: what now?

What to do right after an AI agent deletes files or database data, how to recover from git, checkpoints and backups, and settings that prevent a repeat.

By Devonauts Team5 min read
Leer en español →
White keyboard keys spelling the word DELETE on a coral background

If an AI coding agent deleted files or data, stop it immediately and don't run anything else that writes to the disk or the database. Then recover from the closest copy: git for tracked files, the tool's checkpoint for edits it made itself, your editor's local history or computer backups for untracked files, and your database provider's backups for data. Files removed with a terminal command like rm skip the Trash, so the copy you have before the deletion is the one that counts.

This guide covers the first ten minutes, how to get files back in each situation, what to do when it was database data, and the settings in Cursor and Claude Code that make a repeat much less likely.

What do I do in the first ten minutes?

  1. Stop the agent. Use the stop button in Cursor or press Esc in Claude Code. Don't approve any pending command.
  2. Don't "fix" it yet. No new prompts, no reinstalling packages, no restoring an old backup over the top. Every write can make recovery harder.
  3. Copy the evidence. Scroll the chat and copy the exact commands the agent ran, with the time. That tells you what was deleted and where.
  4. Work out the scope. Was it files in your project, files outside it, rows in a database, or something in a cloud account such as storage buckets?
  5. If live customer data is affected, consider pausing the app or disabling sign-ups and writes while you recover, so new data doesn't mix with what you restore.

How do I get deleted files back?

Work down this list. Most cases end at the first or second step.

The files were tracked by git

Run git status. Deleted files show as deleted:. To bring them back:

git restore path/to/file.ts     # one file
git restore .                   # everything deleted or changed since the last commit

If the deletion was already committed, find the commit that removed the file and restore it from the one before:

git log --diff-filter=D --summary -- path/to/file.ts
git checkout <commit>~1 -- path/to/file.ts

The whole folder is gone, including .git

If you pushed to GitHub or another remote, clone it again. You lose only what was never pushed. If you never pushed, skip to the next steps.

The files were never committed

  • The tool's own undo. Cursor's Restore Checkpoint returns files the agent edited during the session. Claude Code's /rewind does the same for its file edits, but its checkpointing docs state that files deleted or moved through shell commands are not tracked.
  • Editor local history. VS Code-based editors keep copies of files you saved, in the Timeline view. Open a file with the same name and check its timeline.
  • Computer backups. Time Machine, Windows File History, or a cloud folder's version history if the project sits in one.
  • Builder sync. If the app came from Lovable, Bolt or similar with GitHub sync, that repository may still have the file.

What if the agent deleted data in the database?

Code and data recover separately. Restoring the code won't bring back a dropped table.

First, check what actually happened. Sometimes the agent deleted rows only in a local or test database, or a migration failed halfway. Look at the SQL it ran and check the live tables before assuming the worst.

If production data is really gone, it comes down to backups. On Supabase, according to its backups documentation:

PlanDaily backups keptPoint-in-time recovery
FreeNot included; Supabase recommends regular exports with supabase db dumpNot available
ProLast 7 daysPaid add-on
TeamLast 14 daysPaid add-on
EnterpriseUp to 30 daysPaid add-on

Two traps. Database backups don't include files stored through Supabase Storage, only their metadata. And restoring a backup takes the whole database back to that moment, so anything written since is lost unless you export it first. Our guide to Supabase backups covers the options in more depth.

This is not a theoretical risk. In July 2025, a widely reported incident involved Replit's agent deleting a company's production database during a declared code freeze. The common thread in these stories is an agent that had live credentials and permission to run destructive commands.

How do I stop it from happening again?

Rules in a prompt or instruction file help, but they're advice to the model. Settings are what actually block things.

In Cursor

Cursor's run modes, under Settings > Agents > Approvals & Execution, decide what runs without asking. Avoid Run Everything, which runs every tool call without checks. Keep File-Deletion Protection on, which stops the agent from deleting files automatically, including rm commands, and External-File Protection, which stops it from changing files outside the workspace. Don't treat .cursorignore as protection: Cursor's docs say terminal and MCP tools can still reach ignored files.

In Claude Code

Stay in Manual or auto mode, and use the bypass mode only inside an isolated container or VM. Add deny rules for commands you never want run. Deny rules block in every mode:

{
  "permissions": {
    "deny": [
      "Bash(rm -rf *)",
      "Bash(git push --force *)",
      "Read(./.env)"
    ]
  }
}

Put it in .claude/settings.json so it applies to everyone working on the project.

Everywhere

  • Keep production keys off the machine the agent uses. Point local development at a separate test database. An agent can't drop a table it can't reach.
  • Commit and push often. Every push is an off-site copy.
  • Own a backup. Even on a paid plan, a scheduled export you keep elsewhere protects you from both agent mistakes and account problems.
  • Use a staging setup for migrations, so they run somewhere harmless first. See do you need a staging environment.

Quick answers

Can I recover files deleted with rm? Not from the Trash. Look for a git copy, an editor history entry, or a system backup. File recovery tools sometimes work, but stop writing to the disk first.

Will Cursor's checkpoint restore deleted files? It restores files the agent modified during the session. For deletions done through terminal commands, use git or backups.

Is it safe to let the agent run migrations? Against a test database, yes. Against production, only after you've read the SQL and have a fresh backup.

Should I report it to my users? If personal data was lost or exposed, you may have legal duties to notify. That depends on where you and your users are, so check with a lawyer.

Need help recovering?

If the data or code is partly back but the app no longer matches it, our guide on undoing an agent's changes covers the code side. For hands-on help, see our Cursor project help or our software maintenance and support page for ongoing backups and monitoring, or contact us 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.