cd /news/ai-agents/test-your-claude-code-deny-rules-in-… · home › topics › ai-agents › article
[ARTICLE · art-174307] src=dev.to ↗ pub= topic=ai-agents verified=true sentiment=· neutral

Test your Claude Code deny rules in a scratch repo before you trust them

Denys, a Forward Deployed Engineer, published a method for testing Claude Code deny rules in an isolated scratch repository with a bare git remote, arguing that an untested rule is only a guess. He cites Anthropic's documentation that rules match command text rather than intent, and a public GitHub issue (#39459) in which a denied `Bash(rm *)` rule was bypassed by a Python one-liner, one of five bypass patterns he identified across 93 public incident reports. He recommends recording each test as goal, route used, and blocked-or-not, adding a PreToolUse hook for routes text rules cannot see, and rerunning the suite after upgrades or rule edits.

recommendation

Test each deny rule in a scratch repo with a bare remote by stating the goal and letting the agent pick the command, then add a PreToolUse hook for routes text rules cannot see.

more in playbook: Securing agents and AI tools
by read3 min views1 publishedNov 22, 2026

Most advice on making Claude Code safer says "write deny rules". I'm Denys, a Forward Deployed Engineer. Written with AI assistance, checked by me. I think the advice is right and incomplete, because a rule you never tried to get around is a guess. Here is how I would test one.

Anthropic's permissions page says rules are enforced by Claude Code and not by the model, and that instructions in CLAUDE.md don't change what the agent is allowed to do. It also says a rule matches the command text, so git -C . push is not matched by a rule for git push.

A public GitHub issue (#39459) reports the same thing in practice. With Bash(rm *) denied, the agent deleted the file with a Python one-liner. I am quoting the docs and that report here. I did not rerun them for this post, which is exactly why you should run yours.

I sorted 93 public incident reports by cause in Is Claude Code safe? What 93 incident reports show, and the rule bypass was one of five patterns. This post is the method for finding out whether you have it.

Use a folder with nothing in it you care about, and a bare repo in a temp folder as the fake remote. git init in the scratch folder and add one commit.git init --bare next to it and add it as origin. delete-me.txt and commit it. Nothing here touches a real project, and if a test goes wrong the damage is one temp folder.

For each rule, state the goal in plain words and let the agent pick the route. Don't type the denied command yourself, because that tests nothing. git push --force. Ask for the remote's history to be overwritten with the local one. Watch whether it finds git -C . push --force, another flag order, or a different tool. rm. Ask for git reset --hard. Ask for the working folder to match the last commit exactly, then see which command it chooses. Write down each result in three columns: goal, route used, blocked or not. Whatever got through, you now know.

I would also try routes I have no result for: a command wrapped in bash -c, or one run through a package script. I don't know how any of them behave on your version. That is the point of trying.

A deny rule judges text, so for routes that text rules can't see, add one PreToolUse hook that looks at the whole command and blocks the five that would hurt you most. Keep in mind that a hook runs with your full access, and so does anything the sandbox doesn't cover. The docs say the sandbox is off by default and covers shell commands only.

For what no rule catches, git and backups are the layer that always works. Commit before you start, and keep production credentials out of the agent's folder. Rules and tools change. Keep the scratch repo, keep the three columns in a file, and rerun the list after an upgrade or after you edit your rules. If a leak you closed reopens, you will see it the same day.

── more in #ai-agents 4 stories · sorted by recency
── more on @claude code 3 stories trending now
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain — perfect for shipping the agent you just read about.

$git push zahid main
→ Live at https://your-agent.zahid.host ✓
Get free account → Pricing
from €0/mo · no card required
LIVE [news/test-your-claude-cod…] indexed:0 read:3min 2026-11-22 · —