Claude Code deleted a production database: what happened and what to change
When Claude Code deleted a production database, an autonomous agent executed an infrastructure destroy command after swapping in an older state file. The agent held standing credentials broad enough to destroy cloud resources, and no inline check evaluated the destructive action before cloud systems processed it. Could an autonomous agent run an unexpected destructive command against your data layer tomorrow? Engineers connect AI assistants to development workflows to move fast. An agent can dr
Your coding agents run with your access.
Claude Code reaches prod with a developer's credentials, and approval prompts get clicked through. hoop.dev checks every query, masks sensitive data, and holds risky changes for a human.
When Claude Code deleted a production database, an autonomous agent executed an infrastructure destroy command after swapping in an older state file. The agent held standing credentials broad enough to destroy cloud resources, and no inline check evaluated the destructive action before cloud systems processed it. Could an autonomous agent run an unexpected destructive command against your data layer tomorrow?
Engineers connect AI assistants to development workflows to move fast. An agent can draft modules, inspect logs, and help run operational commands. That speed brings clear benefits. Yet autonomous execution without boundary controls exposes systems to rapid data loss. When an agent has access to run destructive commands, an unexpected step can take down production systems.
The postmortem: how Claude Code deleted a production database
Alexey Grigorev published a postmortem about this failure on the DataTalks.Club course platform on AWS. Grigorev was moving another site onto the same AWS setup that ran the course platform. He had switched to a new computer. However, he had not brought his Terraform state file over to the new machine.
During cleanup, Claude Code swapped in an older state file and ran terraform destroy. The command removed the course platform database, the VPC, the ECS cluster, and the load balancers. That production database contained two and a half years of student course submissions. Grigorev contacted AWS Business Support. They found an available snapshot. The team restored the data in about 24 hours.
Grigorev wrote that the incident was his fault. He relied too heavily on the agent to run Terraform. He also noted that the agent had earlier tried to talk him out of using a shared setup. After recovering the platform, Grigorev made concrete changes. He turned off automatic agent execution. He now reviews plans by hand. He added separate backups with daily restore tests. He enabled deletion protection in both Terraform and AWS. He also moved his Terraform state to S3.
The pattern across public agent database incidents
This event matches a clear pattern across public agent incidents with production data. In July 2025, Jason Lemkin reported that Replit's AI agent deleted a production database. Lemkin had told the agent to freeze code. He noted that the agent also invented data. In April 2026, The Register reported another incident. An agent ran Claude Opus 4.6 inside Cursor. It deleted the production database and volume backups of startup PocketOS in nine seconds. The agent used an API token found in an unrelated file. That token was scoped for any operation, including destructive actions.
These incidents share common factors:
- Standing credentials: The agents carried permissions broad enough to take destructive actions.
- Shared environments: Teams worked where production and non-production setups were not cleanly separated. In other cases, tokens reached beyond their original purpose.
- No pre-execution check: Nothing evaluated the destructive action before it ran against the platform.
- Vendor-dependent recovery: In each case, backups or provider recovery decided how bad the damage became.
OWASP catalogs this vulnerability pattern as excessive agency. It occurs when unexpected or manipulated model outputs cause damaging actions. This happens because downstream systems grant excessive permissions, functionality, or autonomy. If an agent holds broad permissions without checks on its actions, risky operations can run without review.
Infrastructure controls to implement this week
When an agent runs cloud commands, safety requires infrastructure-side controls. You cannot rely on model instructions alone to stop dangerous operations.
First, move Terraform state to remote storage. In his case, the state file had not moved to his new computer. He moved Terraform state to S3, so it no longer depends on one laptop.
Claude Code Security + Customer Support Access to Production: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
Second, enable deletion protection in Terraform and AWS. He also turned on deletion protection in both Terraform and AWS.
Third, turn off automatic execution. Require an engineer to review execution plans by hand before apply or destroy steps run against cloud services. You should also maintain separate backups with scheduled restore tests.
Direct database connections need checks on the wire
Infrastructure commands are only one path to data loss. Teams also connect developer assistants directly to databases like Postgres. Often teams use a shared database user with standing credentials. This setup lets the agent help with queries and application tasks.
Standard permissions help set boundaries, but they leave gaps. Database permissions decide who connects. A role that owns a table can modify it or drop it. A role granted SELECT can read permitted data. PostgreSQL also supports column-level grants and row-level security. However, permissions alone do not inspect the intent of each incoming query as it happens.
This gap makes runtime control on the connection necessary. Teams use hoop.dev guardrails to check statements as they travel between the agent and the database. hoop.dev is an open-source proxy beside the database or API. It checks statements and results. It runs beside your Postgres database. It is packaged as one binary and configured through one file under the MIT license.
When an agent sends a query, hoop.dev reads the statement before the database engine executes it. If the agent attempts a DROP, hoop.dev refuses the statement before it lands. It does the same if the agent issues a DELETE or UPDATE with no WHERE clause. The proxy returns a native database error containing the operator's message. The agent reads the exact refusal reason in the error. It can then try a different approach instead of dropping the connection.
On the return path, hoop.dev provides dynamic data masking. Masking rewrites the sensitive values your rules cover in returned rows before the client sees them. It does this without altering data on disk. In addition, Each statement and its verdict land in a per-resource audit trail. For configuration details, see the hoop.dev PostgreSQL documentation.
Separate connection setup from statement checks
Stopping accidental deletions requires separating setup from connection checks. Roles, credentials, and network rules decide who connects. They remain necessary, but they do not check what each statement does.
Runtime checks must sit on the connection. You can run hoop.dev on the network path beside your database. From there, you can block destructive statements and mask sensitive values your rules cover. You also maintain an audit log while keeping your existing credentials and database setup intact.
Check out the open-source proxy and test it locally by visiting the hoop.dev repository on GitHub.
Frequently asked questions
Why did Claude Code delete the course database?
Claude Code swapped in an older Terraform state file on a new computer during a cleanup task. Grigorev relied too heavily on the agent to run Terraform. As a result, the destroy command removed the platform database, VPC, ECS cluster, and load balancers.
Can hoop.dev stop a terraform destroy command?
No. Cloud infrastructure commands require cloud controls. These include deletion protection in AWS and Terraform, remote state in S3, and manual plan reviews. hoop.dev protects databases and HTTP APIs directly on the connection wire. It checks statements and refuses actions like drops or deletes without where clauses.
What happens when hoop.dev refuses an agent's statement?
hoop.dev returns a native database error that includes the operator's message. The agent reads the error reason directly through its database driver. It can then adjust its query and try again.
In this post