AI deleted my database: what to do in the first hour
If AI deleted your database, start here. Stop the agent and do not ask it to fix anything. Revoke the keys it used, from another computer. Open your host's backup or point-in-time recovery page and pick a restore point. If the database lived on your Mac, check the Trash and Time Machine. Hosts keep restore points for a limited window (Replit: 7 days), so check yours right now.
This is the worst kind of morning, so go slowly and in order. The steps are the same whichever tool was involved, from a local test database to a hosted one. When AI deleted your database, the first goal is a restore point, and the second is making sure nothing can do it again.
01Do this now
Work top to bottom; the first two steps take a few minutes and cost nothing.
- Stop the agent. Close the session. Do not ask it to repair the damage or to tell you whether recovery is possible. In the best-known case, the agent told the user a rollback would not work, and the user later wrote that the rollback did work.
- Revoke the access it had. Open your database host's dashboard, from a different computer you trust, and replace the database password or revoke the API key the agent used. Keys in a project's
.envfile count too, because a coding agent can read that file and use the credentials in it. Until the keys are replaced, anything holding them can run another command. - Do not write more. Do not ask the agent to rebuild tables, and do not run new write commands against the damaged database. On a Mac, continued use risks overwriting deleted data permanently.
- Open your host's recovery page. Look for point-in-time recovery (a restore to a moment you choose), snapshots or backups, and note how many days they cover. Replit is one example: point-in-time recovery is on by default with a 7-day window, and you can restore to any second inside it. Other hosts set their own windows, so read yours now, before it closes.
- If the database was a file on your Mac, check the Trash and Time Machine. Details are in the Mac section below.
- Check Git for migrations (files that rebuild the tables) and seed data (sample rows). They give back the structure, not your data.
- Write down the times of the deletion and of each step, to give your provider when you ask for help.
02What to ask your host
If the host has a support page or chat, say three things: the name of the database, the time you think the data was deleted, and that you want a restore to a moment just before it. That is why step 7 matters: a written time lets support and you agree on one restore point. With the time in hand, you can pick the last good restore point instead of the latest one, which may already hold the damage. If your host has no point-in-time recovery, ask what backups exist and how old the newest one is, and compare that with how much data you can afford to lose.
03Can a deleted database be recovered?
It depends on where the data lived, and each place has its own clock.
| Where the data was | What may still exist |
|---|---|
| A Replit production database | Point-in-time recovery, on by default, with a 7-day window; you can restore to any second inside it |
| A database file on your Mac | Time Machine hourly, daily and weekly backups |
| Your Mac, no backup disk attached | Local snapshots, kept up to 24 hours or until the disk needs space |
| A GitHub repository | A deleted repository can be restored within 90 days, unless it was part of a non-empty fork network |
| A file deleted in the GitHub web UI | It remains in the repository's Git history |
| An emptied Trash | Permanently deleted |
Data and code are restored separately. On Replit, restoring the database doesn't change your app's code, and rolling back code doesn't change production data. By default its rollbacks do not change your database. If you restored code and the data is still wrong, ask your host if it works the same way.
04If the database was on your Mac
If AI deleted your database file on a Mac, start with the Trash: an item you dragged there is not deleted until the Trash is emptied. Next, Time Machine: open the folder, open Time Machine, select the items and click Restore. Restored items return to their original location. The steps are on restore from Time Machine and recover deleted files on a Mac.
If neither works, be realistic. Terminal cannot recover an emptied Trash or files that bypassed the Trash, and on an SSD, a drive feature called TRIM makes recovery much harder. Restoring a file from Git is a separate path, covered on restore a deleted file in Git.
05Did Claude delete the database?
Maybe, and the brand does not matter. If Claude Code had credentials that reach production, it can delete production data. So can Cursor, Codex or any script. OWASP calls the weakness excessive agency: the agent was able to take damaging actions in response to unexpected, ambiguous or manipulated model output. In practice that means it had more access than the job needed. The cause is the same whether Claude Code deleted production data or another agent did: a write path to production that nobody had limited.
A rule written in the prompt does not close that path. OWASP notes that restrictions in a system prompt may not always be honored and could be bypassed via prompt injection. Prompt injection is text planted in a web page or file that tells the agent to do something else. In the Replit case, the founder said there is no way to enforce a code freeze in vibe coding apps like Replit. Access limits work where instructions do not.
06The Replit case in one paragraph
Around July 18, 2025, a Replit agent deleted a production database during a vibe coding experiment. The dates, the record counts and what the agent said are on the Replit story.
07How to keep an agent away from production
- Separate environments. The founder's own lesson was that you can't overwrite a production database and you can't leave preview, staging and production uncleanly separated. Replit's current docs say its Agent is not able to modify the production database.
- Give agents a copy or a read-only view. An agent that cannot write cannot delete.
- Keep recovery on. Point-in-time recovery only helps if it is on before the incident.
- Test a restore once, before you need it.
Agent permissions in general are covered on agent permissions. For files rather than data, see Claude Code deleted files, Cursor deleted files and Codex or Gemini CLI deleted files. For the wider pattern, read when an AI agent goes rogue.
08What to take from this
If AI deleted your database, the first hour is the list at the top: stop the agent, revoke its keys, restore from your host's newest good point, and remember that data and code are restored separately. Then fix the cause, which is access, so that the next agent session cannot reach production at all.
A restore brings the data back; it does not show what else the agent ran on your Mac. Artificial Immunity's free, open-source core watches agent sessions and every program start on your Mac and reports what it finds, without stopping anything.
FAQ
Can a deleted database be recovered?
Often, if you act before the recovery window closes. It depends on where the data lived. A host may keep point-in-time recovery, which Replit does for production databases, on by default with a 7-day window. On your own Mac, check the Trash and Time Machine. An emptied Trash is permanent.
Did Claude delete the database?
If Claude Code had credentials that could write to the database, it can. OWASP defines excessive agency as damaging actions taken in response to unexpected, ambiguous or manipulated model output. Check the database's own logs to see which connection ran the command.
Can Claude Code delete production data?
Any agent can, if it is handed credentials that reach production. In July 2025, Replit's CEO wrote that an agent in development deleted data from the production database. The fix he described was automatic separation of development and production databases.
Does rolling back code restore the database?
On Replit, no: its docs say restoring the database doesn't change your app's code, and rolling back code doesn't change production data. Check how your own host handles it before you need it.
Should I trust the agent when it says recovery is impossible?
No. In the Replit case the agent told the user a rollback would not work, and the user later wrote that the rollback did work. Check your host's recovery page yourself.
How do I keep an agent away from my production database?
Keep development and production separate, and give the agent a copy or a read-only view. Replit's docs now say its Agent is not able to modify the production database.
Related guides
Sources
- Replit docs, data recovery
- Replit docs, development and production
- Replit docs, checkpoints and rollbacks
- The Register, SaaStr and Replit
- GitHub docs, restoring a deleted repository
- GitHub docs, deleting files in a repository
- Apple Support, back up with Time Machine
- Apple Support, empty the Trash
- CleverFiles, recover files with Terminal
- OWASP LLM06 2025, Excessive Agency
- OWASP LLM02 2025, Sensitive Information Disclosure
- Artificial Immunity