OmniscioGuidesClaude Code permission rules
Claude Code permission rules: copy-paste examples
Most permission problems are not a missing feature. They are one rule written in a shape that matches nothing, in a file that loses to another one.
This page opens with one small block you can paste, then explains the format and the rules of the road. The ten pages under it are complete blocks for the needs people ask about most: npm and tests, read-only exploration, secrets, git without push, MCP tools, web fetches, protected files, docker, the cloud CLIs, and subagents.
Checked against Anthropic’s Claude Code permission documentation. By the Omniscio team. Updated .
The smallest useful block
Three lists, one rule each. Save it as .claude/settings.json in a project, or as ~/.claude/settings.json for every project on the machine.
{
"permissions": {
"allow": ["Bash(npm run *)"],
"ask": ["Bash(git push *)"],
"deny": ["Read(.env)"]
}
}That block runs npm scripts without a prompt, asks before a push, and refuses reads of .env. Each of the ten pages under this one is a fuller version of the same idea, with what every rule matches and the mistake that breaks it.
The rule, in one line
Every permission rule has the same shape: a tool name, and optionally a specifier in parentheses.
| Rule | What it matches |
|---|---|
Bash | Every Bash command. Bash(*) means the same thing |
Bash(npm run build) | Exactly that command, and nothing after it |
Bash(npm run *) | npm run build, npm run test --watch, and bare npm run |
Read(./.env) | Reading that file; the same rule also blocks writing it through the file tools |
WebFetch(domain:example.com) | Fetches from that host |
mcp__github__get_* | The get_ tools of the github MCP server |
Agent(Explore) | The Explore subagent |
The specifier is the part people get wrong, because each tool reads its own specifier differently. Bash rules match the command text. Read and Edit rules match paths with gitignore syntax. WebFetch takes a domain: prefix. MCP rules match tool names. The pages below spell out the wildcards and limits for each case.
The tool name is its canonical name, not the label in the transcript. A rule written for a label such as Stop Task matches nothing; the canonical name is TaskStop. Anthropic’s tools reference lists the canonical names.
Deny, then ask, then allow
Rules are evaluated in one fixed order: deny, then ask, then allow. The first match decides, and specificity does not reorder them. A broad deny such as Bash(aws *) blocks a call that also matches the narrower allow Bash(aws s3 ls). The same holds between ask and allow: an ask rule prompts even when a more specific allow rule also matches.
An allow rule can never carve an exception out of a deny rule. If a tool is denied at any level, no other level can allow it — a project allow does not beat a user deny, because both deny lists are consulted first.
How a deny is written changes what happens to the tool:
- A bare tool name, such as
"deny": ["Bash"], removes the tool from Claude’s context entirely. Claude never sees it, and cannot try. - A scoped rule, such as
Bash(rm *), leaves the tool available and blocks the calls that match when Claude attempts them.
Ask rules are for the middle case: an action you want to see before it runs, rather than forbid. Anthropic’s own team example uses an ask rule for git push, and a deny rule for reads of .env.
What a wildcard matches
A * stands in for any text, including spaces. A rule with no * matches one exact command.
| You write | Matches | Does not match |
|---|---|---|
Bash(npm run build) | npm run build | npm run build --watch |
Bash(npm run *) | npm run build, npm run test --watch, npm run | npm install |
Bash(git log * main) | git log --oneline main, git log -5 main | git log main, git push origin main |
Bash(ls *) | ls -la, ls | lsof |
Bash(ls*) | ls -la, lsof | Anything that does not start with ls; the missing space is why it catches lsof too |
Three habits follow from that table:
- Put the
*after the subcommand. Ingit log --oneline main,gitis the program andlogis the subcommand. Claude Code matches everything before the first*as written, soBash(git log *)allows only git log, andBash(git *)allows every git command. An allow rule with a wildcard before the subcommand, such asBash(git * main), earns a startup warning. - A space before a trailing
*is part of the rule.Bash(ls *)requires the space, solsofdoes not match;Bash(ls*)matches it too. A trailing*with a space before it also matches the bare command, but only when it is the rule’s only wildcard:Bash(ls *)matchesls, whileBash(* --help *)does not matchnpm --help. :*is the other spelling of a trailing wildcard.Bash(ls:*)matches whatBash(ls *)matches. It is only recognized at the end: inBash(git:* push)the colon is a literal character.
Two more limits matter before you trust a rule:
- A Bash rule does not match the same program invoked another way.
Bash(curl *)stopscurl https://example.com, not/usr/bin/curl https://example.comorsh -c 'curl https://example.com'. In the same wayBash(rm *)does not stop/bin/rm, andBash(git push *)does not stopgit -C . push. Anthropic says plainly that these rules cover the invocation Claude usually produces and are not a security boundary around the program. - A compound command runs without a prompt only when every subcommand is allowed.
Bash(safe-cmd *)does not approvesafe-cmd && other-cmd. Anthropic recognizes&&,||,;,|,|&,&and newlines as separators.
Claude Code also strips a fixed set of wrappers before matching, so Bash(npm test *) matches timeout 30 npm test. The stripped wrappers are timeout, time, nice, nohup, stdbuf, the shell builtins command and builtin, and zsh’s noglob. Environment runners such as npx, docker exec and devbox run are not on the list, so a rule like Bash(npx *) approves whatever package name comes after it. Name the package: Bash(npx vitest *).
Where the block goes, and what wins
| Scope | File | Who it reaches |
|---|---|---|
| User | ~/.claude/settings.json | You, in every project on this machine |
| Shared project | .claude/settings.json | Everyone in the folder; commit it so teammates get it |
| Project local | .claude/settings.local.json | You, in this one project. Claude Code keeps it out of git when it creates the file |
| Managed | managed-settings.json and other managed sources | Everyone your organization deploys it to |
Three rules about precedence decide most surprises:
- Lists merge; they do not override. When two files both set
permissions.allow, Claude Code combines them. You cannot remove a teammate’s allow rule by writing a shorter list in your own file; you add to it. - Deny beats allow across every scope. If user settings allow something and project settings deny it, the deny wins. Swap the two files and the deny still wins.
- Managed settings sit on top. Nothing in your own files or in
--settingsoverrides a managed permission rule.
One trust step is easy to miss: allow rules and additionalDirectories in a project’s .claude/settings.json take effect only after you accept the workspace trust dialog for that folder. Deny and ask rules are not affected, because they only restrict. A claude -p or SDK session never shows the dialog, so a project’s allow rules do not apply there unless the folder was trusted before.
Path rules have their own anchor. A pattern starting with one slash, such as Edit(/src/**), is relative to the settings source that defines it — not to the filesystem root. In user settings, /path resolves under ~/.claude; in a file passed with --settings, it resolves beside that file. Use // for an absolute path and ~/ for one from your home directory.
Where a single developer’s files live, and how a managed file fits above them, are covered in the settings.json locations guide and the managed settings guide.
Confirm it took effect
Run /permissions. The dialog lists all permission rules and the settings.json file each rule comes from, which is the one place that tells you both what loaded and where it was written. You can open it while Claude is working; a rule you add or remove applies from Claude’s next tool call in the same turn.
Then cause the action and watch what happens. An allow rule means no prompt, apart from the calls an allow rule never pre-approves, such as writes to protected paths and reads from network paths. An ask rule means a prompt even in a mode that would otherwise approve the action. A deny rule means a refusal.
/status answers a different question. Its Setting sources line lists the settings files Claude Code loaded for the session, but not which file supplied which key. When a rule is dropped rather than applied, claude doctor lists the entries it rejected, and an interactive session can show the same thing as a Settings Warning at startup.
For one session only, the command line can carry the same rules: --allowedTools adds allow rules, and --disallowedTools adds deny rules. A deny rule from any settings file still blocks a tool the flag names as allowed.
The ten blocks
Each page is a complete settings.json block, what every rule matches and does not match, where the file goes, how to confirm it loaded, and the mistake that usually breaks it. If you only want fewer prompts, start with the npm block.
If nobody is at the terminal to answer a prompt at all, a setting refuses the call instead of waiting; the deny instead of prompting guide covers it.
Allow npm, test and build commands
Run scripts, tests and installs without a prompt, and still stop on a global install or a publish.
Read-only exploration
Remove the editing tools from the session and allow the read and git commands you trust.
Block .env and secrets
Deny reads of env files, key material and a secrets folder, and see the gap only a sandbox closes.
Allow git, stop at push
Status, diff, add and commit run; push asks, and force-push is refused.
MCP tool rules
Allow one server’s read tools, ask for a write tool, deny a server outright.
Allow web fetches by domain
Allow the documentation hosts you use, and see why a domain rule cannot stop curl.
Keep lockfiles and migrations safe
Deny rules that keep Claude out of lockfiles, migration folders, workflow files and generated code.
Docker without the prompt
Build and read without a prompt, ask before a container starts or an image is pushed, and refuse the prune.
Terraform, kubectl and aws
Read commands run, apply asks, destroy is refused, and the wildcard to avoid.
Control which subagents run
Deny one agent or the whole tool, and ask before a subagent runs on Opus or in a worktree.
The five mistakes that make a rule misfire
- A wildcard in allow before the subcommand.
Bash(git * main)approves every git subcommand that ends inmain, includinggit push origin main. Claude Code warns about it at startup. - A missing space before the trailing wildcard.
Bash(ls*)also matcheslsof, andBash(npm run*)is a different rule fromBash(npm run *). - A path rule in the wrong list.
Write(path),Glob(path)andGrep(path)rules are accepted but match nothing. WriteEdit(path)orRead(path)instead, or the bare tool name to match every use. - A user-settings path anchored where you did not expect.
Read(/secrets/**)in~/.claude/settings.jsonblocks~/.claude/secrets/**, not your project’ssecretsfolder. Use//or~/for a rule that should follow you into every project. - Expecting a deny to be a wall.
Bash(git push *)does not stopgit -C . push, and aReaddeny does not stopgrep -rthat names no file. For enforcement that does not depend on the command text, Anthropic points to sandboxing or a PreToolUse hook.
Build the block instead of typing it
If you would rather pick rules than spell them, the Claude Code permissions builder takes a tool, a specifier and a list, warns about the shapes above, and gives you a block to copy. It is the same syntax this page describes, assembled in the browser.
The permission modes — what each one asks by default — are a separate subject, covered on the permission modes page. Rules and modes stack: a rule decides individual tool calls, and the mode decides what is asked when no rule matches.
Where these answers come from
- Rule syntax, evaluation order, wildcards and the Bash limits: Configure permissions, read November 25, 2026.
- The four settings files and what wins: Settings files and precedence, same day.
- The keys and their types: Settings reference.
- Canonical tool names: Tools reference.
- A team file that uses these shapes: Example settings files.
Common questions
Do allow rules in settings.json merge or replace each other?
They merge. When the same list key appears in more than one settings file, Claude Code combines the lists, so each file can add entries without removing another file’s.
Can an allow rule override a deny rule?
No. Deny rules are evaluated first, the first match decides, and specificity does not change the order. An allow rule cannot carve an exception out of a deny rule.
What is the difference between deny and ask?
An ask rule makes Claude Code prompt before the call, even in a mode that would otherwise approve it. A deny rule blocks the call. A bare tool name in deny also removes the tool from Claude’s context entirely.
Is --allowedTools the same as permissions.allow?
For one session, yes: --allowedTools adds allow rules from the command line and writes nothing. permissions.allow in a settings file applies wherever that file is read, and lists merge across files rather than replacing one another.
Where do I see which rule did what?
/permissions lists every permission rule and the settings file each one came from. /status lists the settings files that loaded, and claude doctor lists entries Claude Code rejected.