Skip to content
Agentic Control Plane
Incident series · Part 1 of 9
Stop Your Agent From… →

Stop your AI agent from running `rm -rf` on your files

David Crowe David Crowe · · 5 min read
governance defense-in-depth tool-policy filesystem-safety
Share X HN LinkedIn

Run agents? ACP lets you see, control, and price every tool call they make — allow/ask/deny policy, per-session cost, and a full audit log for Claude Code, Cursor, Codex, and OpenClaw, in one command:

macOS · Linux · WSL
curl -sf https://agenticcontrolplane.com/install.sh | bash
Windows · PowerShell
irm https://agenticcontrolplane.com/install.ps1 | iex

Getting started →  ·  see your first governed call →  ·  free up to 5 agents

A developer reported on the Cursor forum that the agent ran rm -rf on the wrong directory during a session. The command ran. The files were gone. Nothing asked for confirmation. The model wrote the command and the shell ran it.

You can prevent this. Install a hook that checks every shell command before it runs, then add one rule.

Why the agent can do it

Cursor, Claude Code, Codex CLI and most custom agents run shell commands as you. If your shell can run rm -rf $HOME, so can the agent. The operating system can’t tell a command you typed from one the model wrote.

The agent doesn’t need to be malicious. It can misread a directory layout, or build a path from a variable that turned out to be empty. Then it runs the command.

rm -rf is one example. dd overwrites disks. shred wipes file contents. find . -delete walks a tree and deletes. mkfs formats partitions. git clean -fdx throws away uncommitted work. None of them can be undone. Your home directory holds months of local config and uncommitted work, and some of it exists nowhere else.

Prompting won’t fix it

A prompt makes a bad command less likely. It doesn’t stop one. What stops it is code that runs before every command, whatever the model wants.

Step 1: Install the hook

For Cursor, Claude Code or Codex CLI:

curl -sf https://agenticcontrolplane.com/install.sh | bash

The installer finds which AI clients you use. It writes a hook script at ~/.acp/govern.mjs and registers it with the client’s PreToolUse / PostToolUse hooks. After that, every shell command goes through the hook before it runs. Restart your AI client.

The hook is a local file. Anyone who can edit your client’s settings can switch it off, and so can a setting like disableAllHooks in Claude Code. If the hook can’t reach ACP, the Claude Code plugin lets an interactive session continue with a loud UNGOVERNED banner. Background and subagent sessions are blocked until ACP answers. The shared hook that Cursor and Codex use fails open unless you run echo closed > ~/.acp/failmode.

What the floor already does

You haven’t written a rule yet, and the safety floor already covers the worst cases:

  • Always blocked, no approval possible: rm -rf of your home directory, the root filesystem or a system directory such as /etc or /usr. Also mkfs, dd onto a raw disk, fork bombs and shutdown.
  • Held until you approve: a recursive delete of a path outside your working directory (an absolute path, ~/... or ../...). Also force-push, destructive SQL passed to a database client such as psql, and curl | sh.

In Claude Code, a hold shows up in the session and you approve it there. On other harnesses, the call is blocked in the agent and waits on the Approvals page in the console and in an approval email. Approve it, then ask the agent to retry.

The floor doesn’t cover deletes inside your project. rm -rf src, git clean -fdx and git reset --hard are recorded but run. A path built from a variable, like rm -rf $DIR, isn’t caught either. Those need a rule.

A new workspace starts in audit mode, where your own rules record but don’t block. The floor applies in every mode.

Step 2: Ask before rm, and block it when nobody is watching

ACP names each call by the first program in the command: Bash.rm, Bash.dd, Bash.git, Bash.curl. You set a rule on that name. The most specific name wins.

The quickest way is a slash command in your agent:

/acp-ask Bash.rm

That sets rm to ask first in interactive sessions. Run /acp-enforce to switch the workspace from audit to enforce, so your rules block.

For agents with nobody at the keyboard, open the console at cloud.agenticcontrolplane.com, go to Policies, then Agents, pick background, and set Bash.rm to Never. Add Bash.shred the same way. Slash commands only write interactive-session rules, so the unattended rule is a console job.

If you installed with --local, edit ~/.acp/policy.json instead:

{
  "default": "allow",
  "rules": {
    "Bash.rm": "ask",
    "Bash.shred": "ask"
  }
}

Local rules have no tiers. A deny applies to every session.

Now an interactive rm waits for you, and an overnight run can’t delete anything with rm.

Step 3: Check the log

Every governed call is written to the log whatever the decision. A blocked rm -rf is there with the full command, the agent, the session type and the reason. Open Activity in the console, or run tail -f ~/.acp/audit.jsonl in local mode. That file lives on your own machine, so treat it as a record, not proof.

What this takes

  • The curl command: about 30 seconds.
  • The rule: about 2 minutes.

What it won’t catch

  • A command run through a tool that isn’t a shell command, such as an editor action or an MCP tool. The floor reads shell command text only.
  • A delete hidden in a script file the agent wrote and then ran.
  • Anything you’ve switched off. An owner or admin can turn the floor off on the Policies page.
  • Backups. The hook stops the deletion. It can’t restore anything.

The shell is one tool of many. The Tool Surface Index groups the rest by blast radius, and getting started covers the install in more detail.

AgenticControlPlane.com

Share X HN LinkedIn
Get the next data drop
What agents actually cost, new tool-surface captures, and the occasional incident post-mortem — sent when we publish something worth your inbox, not on a schedule. Unsubscribe anytime.
Share: Twitter LinkedIn
More in Stop Your Agent From…
  1. 1. Stop your AI agent from running `rm -rf` on your files · you are here
  2. 2. Stop your AI agent from deleting your production database
  3. 3. Stop your AI agent from deleting files outside your project
  4. 4. Stop Your AI Agent From Force-Pushing and Rewriting Git History
  5. 5. AI coding agents leaking .env secrets: stop it in 3 steps
  6. 6. Stop your AI agent from leaking PII through tool calls
  7. 7. Stop your AI agent from burning through your API budget
  8. 10. Stop an AI agent from escalating IAM permissions on AWS, GCP and Azure
  9. 12. Make Your AI Coding Agent Ask Before It Runs Commands Over ssh
Related posts

← back to blog