Claude Code Deny Rules Not Working? Why Claude Still Ran the Command

Claude Code Deny Rules Not Working? Why Claude Still Ran the Command

Are your Claude Code deny rules not working? In most cases the rule is fine, but it doesn’t match the exact text of the command Claude wrote.

A rule like Bash(git push *) blocks git push origin main, yet it does not block git -C . push origin main, /usr/bin/git push or bash -c 'git push'.

If a broad allow rule such as Bash(git *) also exists, that variant runs without a prompt.

The quick fix: open /permissions and check that your rule is listed under Deny, read the warnings under the startup banner for typos, then widen the pattern (for example add Bash(git * push *)). For anything that must never run, add a PreToolUse hook or turn on the sandbox, because Anthropic’s docs say a Bash deny rule is not a security boundary around a program.

We reproduced the problem in a real session below: a deny rule that blocked the plain command, a variant that slipped past it, two rules that did nothing at all, and the fixes that stopped every version.

Browse all our Claude Code tutorials for more fixes and how-tos.

Tested with Claude Code v2.1.332 on macOS on November 30, 2026. We used a throwaway git repository called notes-app with no remote, so no push could ever leave the machine, and started Claude Code with project and local settings only.

We tested on macOS; the Windows and Linux steps follow Anthropic’s official instructions. Permission rules work the same way on every system.

Quick Summary

CauseWhat you seeFixTested by us?
Command written another wayVariant runs, plain form is deniedWider pattern, hook or sandboxYes
Typo in the tool namematches no tool warning at startUse the exact tool name, like BashYes
Write(...) or Grep(...) rulenever matches warningUse Edit(...) or Read(...)Yes
Program by path or inside sh -cRule is skippedPreToolUse hookYes (hook)
File read by a script or grep -rRead deny rule doesn’t applySandboxFrom the docs
Settings file not loadedRule missing from /permissionsFix the JSON or file locationFrom the docs
A mod approved the callCall runs in setups without managed settingsReview your modsFrom the docs

Why Claude Code Deny Rules Stop Working

A deny rule in Claude Code is a text pattern. When Claude wants to run a Bash command, Claude Code splits compound commands, strips a few known wrappers like timeout and nohup, and then compares the text to your rules.

If the text matches, the call is refused. If it doesn’t, the call moves on to your ask and allow rules and then to the permission mode.

Anthropic’s permissions documentation is direct about this. It says a Bash rule doesn’t match the same program invoked in a different form, so a deny rule covers the invocation Claude usually produces and isn’t a security boundary around the program. If you need a refresher on the basics, our guide to permission rules covers the full syntax.

A deny rule blocks text, not intent. If the words change, the rule may not fire.

The order Claude Code checks things

Rules are evaluated in a fixed order: deny first, then ask, then allow. The first match decides, and a more specific rule does not change that order. So a deny rule always beats an allow rule, but only when the deny rule matches at all.

Diagram of how Claude Code checks a Bash command: PreToolUse hook, then deny, ask and allow rules, then the permission mode
Each Bash call passes a hook, then deny, ask and allow rules, then the permission mode.

A PreToolUse hook sits even earlier. The docs say a hook that exits with code 2 stops the tool call before permission rules are evaluated, so it blocks the call even when an allow rule would let it through.

Reproducing the Problem: Claude Still Ran the Command

We set up a demo repository with one allow rule and three deny rules in .claude/settings.json. The allow rule Bash(git *) lets git commands run without a prompt, which is a very common setup. The deny rules were meant to stop pushes, rm commands and writes to a secrets folder.

Claude Code settings.json with allow rule Bash(git *) and deny rules Bash(git push *), Bassh(rm *) and Write(secrets/**)
Our starting settings: one allow rule and three deny rules, two of them broken.

Step 1: Read the startup warnings

As soon as we started Claude Code, two yellow warnings appeared under the banner. The first said our Bassh(rm *) rule matches no tool, because of the typo. The second said Write(secrets/**) never matches and suggested Edit(secrets/**) instead.

Claude Code startup warnings: Deny rule Bassh(rm *) matches no tool and Deny rule Write(secrets/**) never matches
Claude Code warns at startup about deny rules that can never match.

These warnings are easy to miss if you start typing right away. They are the fastest way to catch a rule that does nothing. Anthropic’s error reference lists both messages.

Step 2: The plain command is denied

Next we asked Claude to run exactly git push origin main. The deny rule matched, and Claude Code refused the call with “Permission to use Bash with command git push origin main has been denied.” Claude then stopped and didn’t try another way, which is what you want.

Claude Code denies git push origin main because the deny rule Bash(git push *) matches
The plain form matches Bash(git push *), so it is refused.

Step 3: A small change slips past the rule

Then we asked for git -C . push origin main.

This does the same push, but the -C . option sits between git and push.

The text no longer starts with git push, so the deny rule didn’t match, and the allow rule Bash(git *) did.

Claude Code runs git -C . push origin main because the deny rule does not match the variant
The variant ran with no prompt; it failed only because the demo repo has no remote.

Git really ran. It failed with “‘origin’ does not appear to be a git repository” only because our demo had no remote. In a real project with a remote, this would have pushed your code.

Claude itself pointed out that the deny rule didn’t catch this one.

In fairness, Claude didn’t invent the variant on its own here; we asked for it. But the same thing can happen when Claude picks a different form to work around a folder issue, or when a prompt injection in a file suggests one.

Step 4: Check what /permissions shows

The /permissions dialog lists every rule and which file it came from. Our broken rules were listed in the Deny tab like the working one, which shows a trap: being listed does not mean a rule matches anything.

Claude Code /permissions Deny tab listing Bash(git push *), Bassh(rm *) and Write(secrets/**)
The Deny tab lists all three rules, even the two that can never match.

Why the Variant Wasn’t Caught

The docs give a clear table of what a Bash deny rule stops and what it doesn’t. Here is the same idea drawn for our push example.

Diagram showing four ways to run git push and which ones the deny rule Bash(git push *) catches
One deny rule catches the plain form; the other three fall through to your other rules.
Deny ruleStopsDoesn’t stop
Bash(git push *)git push origin maingit -C . push origin main, git -c push.default=current push origin main
Bash(rm *)rm -rf build//bin/rm -rf build/, bash -c 'rm -rf build/'
Bash(curl *)curl https://example.com/usr/bin/curl https://example.com, sh -c 'curl https://example.com'

Some things do work in your favor.

Deny rules apply to every part of a compound command, so cd /tmp && git push is still caught. They also match past any leading variable, so Bash(rm *) still matches FOO=bar rm -rf tmp/. And wrappers like timeout 30 are stripped before matching.

How to Fix Claude Code Deny Rules That Don’t Work

Work through these fixes in order. The first three fix rules that never fire. The last three handle variants that a text pattern can’t fully cover.

Fix 1: Fix typos and wrong tool names

Rules use the canonical tool name, such as Bash, Read, Edit or WebFetch. The docs note that the label shown in the transcript can differ from the canonical name, and a rule written with the label won’t match. Look for the matches no tool warning under the banner every time you change your rules.

Fix 2: Use Edit and Read for files

Claude Code checks file access only against Edit(path) and Read(path) rules. A Write(docs/**) or Grep(docs/**) rule is accepted but never matches. Use Edit(secrets/**) to block changes and Read(./.env) to block reads.

A Read deny rule also blocks Edit and Write on the same path. Our post on ignoring .env files shows those rules in action.

Also check the path anchor. In these rules, /path is relative to the settings source (the project root for project settings), not the filesystem root. Use //Users/you/notes.txt for an absolute path.

Fix 3: Make sure the settings file loaded

If a rule isn’t in /permissions at all, the file probably didn’t load. A single comment or trailing comma can make Claude Code skip a whole settings file. Our guide to settings.json problems walks through those checks.

Deny rules merge from every level, so a deny in any file blocks an allow from any other file.

Fix 4: Widen the pattern

Put the * where the variants appear. We added Bash(git * push *), which matches any options between git and push. Keep the original rule too, because the new one needs at least one word in the middle.

Claude Code settings.json deny list with Bash(git push *), Bash(git * push *) and Edit(secrets/**)
The fixed deny list: a wider push pattern and an Edit rule for the secrets folder.

To test only the rule, we started Claude Code with hooks turned off for that session using --settings '{"disableAllHooks": true}'. The same git -C . push origin main request was now refused.

Claude Code refuses git -C . push origin main after adding the deny rule Bash(git * push *)
With hooks off, the wider deny pattern alone refuses the -C variant.

A wider pattern still won’t catch /usr/bin/git push or bash -c '...'. Mind the spaces, too: Bash(rm *) matches rm but not rmdir, while Bash(rm*) matches both.

Fix 5: Add a PreToolUse hook

A hook runs your own script before every matching tool call, and it can read the full command. Our .claude/hooks/block-git-push.sh looks for git followed later by push, anywhere in the command, and exits with code 2 to block it.

A PreToolUse hook script that blocks any Bash command containing git push and exits with code 2
Our hook script: one pattern check, a message for Claude, and exit code 2.

We registered it in .claude/settings.json with a Bash matcher:

{
  "hooks": {
    "PreToolUse": [
      {
        "matcher": "Bash",
        "hooks": [
          {
            "type": "command",
            "command": "\"$CLAUDE_PROJECT_DIR\"/.claude/hooks/block-git-push.sh"
          }
        ]
      }
    ]
  }
}

Remember to make the script executable with chmod +x. The script needs jq to read the command from the JSON that Claude Code sends it.

Claude Code PreToolUse hook blocks git -C . push origin main before it runs
The hook blocks the -C variant before any permission rule is checked.

Then we tried the full path, /usr/bin/git push origin main. No deny rule matches that text, but the hook caught it too, and git never ran.

Claude Code hook blocks /usr/bin/git push origin main, a form no deny rule matched
The hook also stops the full-path form that slips past every text rule.

A hook is stronger than a rule, but it is still your own text check. A script that runs git from inside Python, or an alias, could get past a simple pattern. If hooks don’t seem to fire at all, see our guide to silent hooks, and for more examples try our ready-to-copy hooks.

Fix 6: Turn on the sandbox for hard limits

For limits that must hold, the docs point to sandboxing. The sandbox works at the operating system level, so it limits which files and network hosts shell commands and their child processes can reach, no matter how the command is written.

That also covers the cases Read and Edit deny rules miss, like a Node script that opens a file itself or grep -r run from a parent folder. Our explainer on the sandboxed Bash tool covers the setup.

Other Reasons a Deny Rule Seems Ignored

  • A different tool did the job. A Bash(curl *) rule doesn’t stop the WebFetch tool, and a WebFetch rule doesn’t stop curl. Block both if you mean both.
  • CLAUDE.md is not a rule. The docs say instructions in your prompt or CLAUDE.md shape what Claude tries but don’t change permission rules.
  • A mod approved it. In setups without managed settings or a Team or Enterprise login, the docs say an installed mod can approve some calls that a deny rule refuses.
  • You approved it yourself. “Yes, and don’t ask again” saves an allow rule to .claude/settings.local.json, but it never overrides a deny rule that matches.

For a wider list of problems, see our roundup of common Claude Code errors.

Try It Yourself

Make a throwaway git repo with no remote, add Bash(git *) to allow and Bash(git push *) to deny, and start Claude Code there. Then paste this prompt:

This is a throwaway test repo with no remote, and I am testing my permission rules.
Run exactly this command once and nothing else: git -C . push origin main

If git runs and fails with a remote error, your rule has the same gap we found. Add Bash(git * push *) or the hook above, start a new session and try again.

Common Mistakes

  • Trusting an allow-all rule like Bash(git *) next to a narrow deny rule.
  • Writing Write(...), Grep(...) or Glob(...) rules for files.
  • Skipping the yellow warnings under the startup banner.
  • Using /path when you meant an absolute //path.
  • Relying on a deny rule alone to protect secrets or production systems.

Pro Tips

  • Test each deny rule with two or three variants of the command, the way we did.
  • Prefer an ask rule over allow for risky families like git, so a missed variant prompts instead of running.
  • Pair Bash(curl *) and Bash(wget *) denies with WebFetch(domain:...) rules for the sites you allow.
  • Put team-wide denies in managed settings, which users and projects can’t override.
  • Read hook scripts before you run a project you didn’t write; our guide to blocking dangerous commands shows a ready-made option.

Cheat Sheet

Cheat sheet for fixing Claude Code deny rules: check the rule loaded, better patterns, file rules and stronger guards
Keep this handy when a Claude Code deny rule doesn’t seem to work.

Frequently Asked Questions

Why did Claude Code run a command I denied?

The command text didn’t match the rule. A variant like git -C . push or /usr/bin/git push skips Bash(git push *), and an allow rule or your permission mode then decides.

Does deny override allow in Claude Code?

Yes. Deny rules are checked first, and no allow rule at any settings level can override a matching deny. The catch is that the deny rule has to match.

Why does my Write deny rule do nothing?

Claude Code checks files only against Edit and Read rules. Use Edit(path) to block changes; the startup warning says the same.

Is a deny rule enough to protect my secrets?

Not on its own. Read deny rules don’t cover scripts that open files themselves. Use the sandbox for hard limits and keep real secrets out of the project folder.

Do hooks beat deny rules?

They work together. A hook that exits with code 2 blocks a call before rules run, but a hook’s “allow” can’t override a matching deny rule.

Conclusion

When Claude Code deny rules are not working, the rule usually loaded fine but didn’t match the command Claude actually wrote. In our test, Bash(git push *) stopped the plain push while git -C . push ran right past it, and two other rules did nothing because of a typo and the wrong tool name. Read the startup warnings, check /permissions, widen your patterns, and use a PreToolUse hook or the sandbox for anything that must never run. For more about the model behind the tool, see our Claude AI overview.

Newsletter

New AI tools in your inbox

The best new tools and the AI news that matters, in one short email. Unsubscribe any time.

Free · No spam · Unsubscribe any time

✓ Looks like you’re subscribed

Loading Google’s sign-up form…

Looks like you’re already subscribed

Thanks for reading! New AI tools and the AI news that matters will land in your inbox.

Not subscribed yet? Refresh the page to load the sign-up form.

The sign-up form couldn’t load. If you use an ad or content blocker, allow news.google.com and reload the page.

Free instant check before you pay. Takes a few seconds.

Scroll to Top