DEV Community

JEONSEWON for Boxdawn

Posted on AI-assisted

I ran 107 commands from real Claude Code incident reports through my pre-run check. Here is where it stays silent.

AI coding agents run shell commands on your machine. Most of the time that is fine. Sometimes it is rm -rf in the wrong folder, a dropped production table, or a git reset --hard over a day of uncommitted work. Public Claude Code issue reports have plenty of these.

I build guard, a pre-run check for Claude Code and GitHub Copilot CLI. This post is about what it does with the commands from those reports, and mostly about the ones it gives no decision on.

Three answers, and no "allow"

guard reads each shell command before it runs and gives one of three answers.

  • Deny. rm -rf ~ reaches outside the project, so it does not run.
  • Ask. git reset --hard discards uncommitted work, so you are asked first, with that reason attached. Reading a secret file like .env through a shell command is asked too.
  • No decision. npm test gets nothing. guard says nothing, and your agent's own permission settings decide what happens next.

It never answers "allow": it only ever adds a deny or a question. Your permission settings still decide everything else, so they still matter after you install it.

107 commands from incident reports

I collected commands quoted in public anthropics/claude-code issue reports about destructive commands: 107 commands from 83 reports. On guard 0.4.11:

Decision Count
Deny 24
Ask 52
No decision 31

Before you read anything into that: this is the list I wrote guard's rules against. It describes this list. It is not a catch rate for incidents guard has never seen, and I don't have that number yet.

How it was run: the commands were judged, not run, in one made-up project folder. Where a report didn't say which shell, I tried Bash and PowerShell and counted the stronger result. Some entries are fragments or contain placeholders like <repo>, entered as the reporter wrote them, so a few would be judged differently written out in full.

The 31 with no decision

"No decision" does not mean nobody was asked. Claude Code's own permission check may still have stepped in. It means guard had nothing to say. Here are the groups I have written up so far.

Databases: the SQL never reaches the shell

Six lines came from five reports. Three are bare SQL (DROP DATABASE, DROP SCHEMA CASCADE, DROP TABLE poc_staging), two are subcommands with the program name missing (migrate:fresh, doctrine:fixtures:load --no-interaction), and one is prisma db push.

The reports show the SQL but not what sent it. guard reads shell command lines, and a bare DROP TABLE is not one. When I wrap the same SQL in psql -c myself, it is denied, but I built that form; if the SQL went through a database tool or an MCP server, guard never sees the call. Written in full, the two fragments are asked. prisma db push is an everyday schema command with no rule; in that report the data went when Prisma offered a reset and the session accepted it.

Scripts: the damage was inside the file

Four lines from three reports share one shape. The agent ran a script, and the line that did the damage was inside it.

  • timeout 60 node postmessage-bench.mjs: the script called process.kill(-1, SIGKILL) and killed every process the user owned.
  • bash /tmp/.../test-lib-demo.sh: inside it, trap 'rm -rf "$_HT_HOME"' EXIT, and _HT_HOME had become $HOME.
  • & "...\junction-test.ps1": a failed Push-Location inside the script left git clean -xdff running at the workspace root.

guard reads the command line. It does not open the script file, and in all three the command line only said "run this script". The reporter of the third one had a deny rule for git clean -f* and their own pre-tool hook. Neither matched, because the tool call was a script path. I don't have a good answer here. Asking on every script run means asking all day, and reading the file means trusting something that can change between the check and the run.

Docker: some cleanup is asked, some is not

Two lines are Docker cleanup. docker network prune -f removed unused networks across the whole daemon, including other projects' networks on the same machine; in that report the user ran it after the agent called it optional and safe. docker stop n8n && docker rm n8n removed a container with no volume mount, and the workflows, credentials and history inside it were gone.

On 0.4.11, docker volume rm is asked, and docker system, volume and image prune are asked. docker network, container and builder prune, and docker rm of a container, get no decision. So "guard asks about docker prune" would be too broad.

Inside the project folder

guard looks at where a delete lands more than what it deletes. Inside the project folder, rm -rf build and rm -rf src both get no decision, and your permission settings decide. Outside it, rm -rf ../other-project and rm -rf ~ are denied. My reasoning was that asking on every delete inside the project would train you to click yes on node_modules and build until the question means nothing. The cost is that src is in the same bucket, and I haven't solved that.

What I'd like to hear

If an agent has deleted something of yours, I'd like to know the command and how it got sent. The reports often leave out the part that matters: was it a shell line, a script, a database tool? And if you use guard, tell me which "no decision" you would want turned into a question.

guard is free and source-available (FSL-1.1-ALv2). Claude Code on Windows, macOS and Linux. GitHub Copilot CLI is tested on Windows only so far.

Repo: https://github.com/boxdawn/guard

I wrote this with help from an AI assistant, which I also used to draft and check the numbers against guard's code. The measurements were run with it under my direction, and the decisions in this post are mine.

Top comments (4)

Collapse
 
itsvicmoreno profile image
Vic Moreno •

On the script gap, a possible middle ground: ask only when the script is untracked or differs from HEAD, and stay silent on scripts already committed. That keeps the question for scripts an agent just wrote or edited, which no human has seen yet, instead of every run. It does not close the window between the check and the run, but it turns "asking all day" into "asking on new code". Would that still be too noisy for how people actually run agents?

Collapse
 
jeonsewon profile image
JEONSEWON Boxdawn •

Thanks, that's a better split than the two I had. I went back to the three reports: in all of them the agent had written the script itself earlier in the same session. So your rule would have asked on all three, with one catch. Two of them weren't in the repo at all: one was under /tmp, one in the subagent's scratchpad folder. So "untracked" has to include "not in any repo", or those slip through.

On noise: in the third report, the same subagent wrote two corrected versions of the script eight minutes later. Under your rule each of those would be asked too, which is arguably right, but it's where the count goes up. Asking once per file content instead of once per run might soften that. I don't have numbers yet on how often agents write and rerun scripts in a normal session, so I can't say how noisy it gets.

The case it leaves open is a committed script that does damage with the wrong arguments or environment. I'd guess that's the smaller group.

Collapse
 
itsvicmoreno profile image
Vic Moreno •

Keying the prompt on a hash of the file content sounds like the right fix: each corrected version gets asked once, a rerun of the same bytes never. For the /tmp and scratchpad cases, "outside the repo root" is easier to test than "untracked", since git status says nothing about files outside the work tree. Agreed the committed-script case is the smaller group, and it is the one a diff review has a chance to catch.

Thread Thread
 
jeonsewon profile image
JEONSEWON Boxdawn •

We went a different way for now. Since 0.4.13, guard opens a shell script the agent runs (PowerShell scripts since 0.4.14) and checks the commands inside with the same rules. If it holds something guard would block on the line, guard asks before it runs. It reads the file every time, so a corrected version gets checked on its new content and a rerun of the same file gets the same decision. A new script with ordinary commands in it doesn't get a question just for being new.

Fair point on git status, it can't see outside the work tree. Agreed on the committed-script case too. That's the one where a diff review earns its keep.