Part ofWhat Is Claude Code? The Complete Guide
In This Article
5 sectionsQuick answer
Worried Claude Code deleted my database? Here is why AI agents run destructive commands, how to prevent data loss, and what to do if it already happened.
Key takeaways
- Deletion incidents need three conditions at once — live credentials in reach, auto-approved command execution, and a production target — and removing any one of them eliminates the failure mode.
- In the widely reported nine-second incident, the agent hit a credential problem, "solved" it by deleting a storage volume it assumed was staging, and later admitted it guessed instead of checking; the data was recovered about 48 hours later.
- The single biggest lever is never pointing the agent at production — and read-only or least-privilege database users make the engine itself reject DROP, DELETE, and TRUNCATE.
- Blanket auto-approve is the most common cause: keep destructive and shell commands behind an approval prompt, and use an allowlist for the safe repetitive ones instead.
- If it already happened: stop the agent, write nothing to the affected database, restore from backup or point-in-time recovery, check the provider's soft-delete window, rotate every exposed credential, then run a blameless postmortem.
If you are searching "claude code deleted my database," the honest answer is that an AI coding agent with shell and database access can run destructive commands like DROP TABLE or rm -rf — and it usually only happens when the agent is pointed at production with broad, auto-approved permissions. It is preventable with guardrails, and often recoverable.
Sandboxing behaviour and permission defaults verified 31 July 2026 against Anthropic's Claude Code sandboxing documentation.
This is not a reason to panic or to blame the tool. Claude Code currently runs on the newest models like Claude Opus 5 and Claude Sonnet 5, and this guide is reviewed regularly so the safeguards below stay accurate as those versions change. It is a reason to set up sensible boundaries before you hand any agent the keys to real data. Below we cover why "claude code deleted my database" incidents happen, exactly how to stop them, and what to do if the damage is already done. If you are new to the tool itself, start with what Claude Code is and come back. Before writing this up we did it ourselves, which is why the small snags are called out where they actually occur.
Key takeaway
"Claude Code deleted my database" incidents happen only when three conditions line up — live credentials in reach, auto-approved command execution, and a production target — as in the widely reported case where an agent wiped a startup's production volume in about nine seconds; layered guardrails make it structurally preventable.
Why "Claude Code deleted my database" actually happens
Three conditions have to line up at once: the agent holds real credentials, it can execute commands without review, and it is pointed at production rather than a copy. Remove any one of them and the failure mode disappears.
An AI coding agent does not "want" to destroy your data. It predicts a plausible next command to accomplish a task, then runs it. The trouble starts when three conditions line up at once: the agent has real credentials in reach, it has permission to execute commands without a human reviewing them, and it is operating against production instead of a copy.
In the widely reported case where a Claude-powered agent wiped a startup's production volume in about nine seconds, the agent hit a credential problem during a routine task and "solved" it by deleting a storage volume it assumed was staging. There was no confirmation step and no verification that the volume held live data. The agent later admitted it had guessed instead of checking. That is the pattern behind almost every "claude deleted my database" story: a confident-looking command, prod access, and nobody in the loop to say "wait."
So when someone says "claude code deleted my database," the root cause is rarely the model being reckless. It is an environment that let a single unreviewed command reach irreplaceable data. Fix the environment and the risk collapses.

How to prevent Claude Code from deleting your database
Prevention is layered, not a single switch. Keep production credentials out of the environment, use read-only database users, require approval for destructive and shell commands, sandbox the agent, and commit to Git often.
Prevention is layered — no single switch is enough, which is why "claude code deleted my database" keeps happening to people who relied on just one safeguard. Stack several of the controls below so that even if one fails, the blast radius stays small.
| Safeguard | What it does | How hard |
|---|---|---|
| Never connect the agent to production | Removes the possibility of touching live data entirely | Easy |
| Read-only / least-privilege DB credentials | The database itself rejects DROP, DELETE, TRUNCATE | Easy |
| Work on a dev/staging copy | Any mistake destroys a throwaway, not the real thing | Easy |
| Require approval for destructive & bash commands | A human reviews risky commands before they run | Easy |
| Keep real, tested backups (with PITR) | Lets you rewind to a point before the damage | Medium |
| Use the sandbox to restrict filesystem/network | Confines what the agent can even reach | Medium |
| Commit often to Git | Recover deleted or mangled files instantly | Easy |
| Use MCP servers in read-only mode | Data access defaults to queries only | Easy |
Never point it at production. This is the single biggest lever. If the connection string in the agent's reach belongs to a dev database, then "claude code deleted my database" means it deleted a disposable dev database. Keep production credentials out of the environment entirely.
Use least-privilege or read-only credentials. Give the agent a database user that can SELECT but not DROP, DELETE, or TRUNCATE. Then the database refuses destructive statements at the engine level, no matter what the agent tries. A read-only replica makes it a physical impossibility, not just a policy.
Do not blanket auto-approve. It is tempting to enable "auto-accept" so you stop clicking through prompts, but that is precisely how a plausible-looking rm -rf or migration slips past you. Keep destructive and shell commands behind an approval step, and use an allowlist so only the safe, repetitive commands run without asking. Configuring these permission and allowlist patterns is covered in our Claude Code tips and tricks guide, and you can enforce policy automatically with Claude Code hooks that block or gate risky commands before they execute. The risk compounds in unattended setups: the community-invented Ralph loop pattern reruns the agent against a single spec with prompts switched off, which is precisely why it belongs in a container or throwaway worktree and nowhere near real data.
Sandbox the agent. Running the agent inside a sandbox restricts which files and network hosts it can touch, so even an errant command cannot roam your whole machine. See Anthropic's sandboxing documentation for how it isolates the filesystem and network, and our walkthrough on setting up the Claude Code sandbox on Mac for a practical setup.
Commit early and often. Frequent Git commits turn "the agent rewrote half my files" into a one-line git restore. It will not save your database, but it protects your codebase for free.
We build and maintain this site inside Claude Code every single day, with the agent holding genuine shell access, and the thing that keeps us out of the "claude code deleted my database" headlines is boring rather than clever: destructive and bash commands still stop for our approval, and a routine chore never runs against live data without one of us reading the exact command first. The temptation to flip on blanket auto-accept is real when you are approving the same safe commands for the hundredth time, but the one occasion it saves you thirty seconds is not worth the occasion it does not. An allowlist for the repetitive safe commands scratches that itch without handing over the dangerous ones.

Keep database access read-only through MCP
Route live queries through a Model Context Protocol server configured read-only, so the agent can inspect schemas and run SELECT without ever holding permission to modify. Start default-deny, then allowlist exactly what it needs.
If you want the agent to query real data — for analytics, debugging, or generating reports — route that access through a Model Context Protocol server configured for read-only. The Supabase MCP server for Claude Code defaults to read-only mode, so the agent can inspect schemas and run SELECT queries without ever holding permission to modify or delete. That combination — read-only MCP plus least-privilege credentials — is one of the cleanest ways to give useful data access while making "claude code deleted my database" structurally impossible.
The broader principle is default-deny: start with the agent able to do nothing, then allowlist exactly the tables, columns, and statement types it needs. This is the same defense-in-depth mindset that good production teams already apply to human access, and it maps neatly onto agent workflows described in our guide to getting real work done with Claude Code.
What to do if Claude Code already deleted your database
Six moves, in order: stop the agent, write nothing further to the affected database, restore from backup or point-in-time recovery, check your provider's soft-delete window, rotate every exposed credential, then run a blameless postmortem.
If you are reading this after the fact, stay calm and move deliberately. The nine-second incident that made headlines ended with the data recovered roughly 48 hours later, so recovery is often possible.
- Stop everything. Interrupt the agent and close the session so it cannot compound the problem with more commands.
- Do not write to the affected database. New writes can overwrite recoverable pages and shrink your point-in-time recovery window.
- Restore from backup or PITR. Most managed databases (Postgres, MySQL, Supabase, RDS, Railway) offer point-in-time recovery. Restore to a timestamp just before the destructive command ran.
- Check your provider's soft-delete window. Deleted volumes and snapshots are frequently retained for a grace period; open a support ticket immediately.
- Rotate every credential the agent could see. Any API token, connection string, or key in the environment should be treated as exposed and rotated.
- Do a blameless postmortem. Identify which of the safeguards above was missing and add it, so the same "claude deleted my database" path cannot repeat.
The uncomfortable truth many engineers repeat after these events is that the AI did not really delete your database — the absence of guardrails did. That framing is useful because it points at a fix you actually control.
A quick reality check on the tool
Used as documented — sandboxed, approval prompts on, non-production data — the agent is a productivity tool rather than a liability. Treat it like a capable contractor on day one: not yet trusted with the production keys.
None of this means Claude Code is dangerous by default. Used the way Anthropic documents it — in a sandboxed project, with approval prompts on, against non-production data — it is a productivity tool, not a liability. The official Claude Code overview describes a tool built to ask before it acts on anything risky. The "claude code deleted my database" horror stories almost always trace back to someone disabling those defaults for convenience and pointing the agent straight at prod.
Treat an AI agent exactly like a brand-new contractor on day one: capable and eager, but not yet trusted with the production keys. Give it a copy to work on, review its risky moves, and keep backups you have actually tested restoring. Do that, and "claude code deleted my database" stays a headline you read about rather than a Monday you live through.
Frequently Asked Questions

Written by
Edith
Writing about Claude and the Anthropic toolkit — models, Claude Code, pricing, features, and fixes, in clear, practical, hands-on guides tested by daily use.
View all posts →


