D3 · Claude Code › Cluster 3 · Permissions & Safety

3.2 · Allow / Deny / Ask Rules

Tool-scoped permission rules

CONCEPT Three lists, one syntax: Tool or Tool(specifier)

Where modes (3.1) set the baseline, permission rules make it precise. Every rule targets a tool and optionally narrows it with a specifier in parentheses. Rules live in the permissions block of a settings file (or you manage them live with /permissions):

RuleEffect
BashMatches all Bash commands (bare name = whole tool)
Bash(npm run build)Matches the exact command npm run build
Bash(npm run test:*) / Bash(npm run test *)Matches commands starting with npm run test (trailing wildcard)
Read(./src/**)Reads under <cwd>/src/ (gitignore-style path)
Read(./.env)Matches reading the .env file in the current dir
WebFetch(domain:example.com)Fetch requests to example.com
mcp__puppeteer__navigateOne tool from the puppeteer MCP server
🔑 Bash(ls *) (with the space) matches ls -la but not lsof — the space enforces a word boundary. Bash(ls*) matches both. The :* suffix is equivalent to a trailing  *, so Bash(npm run test:*) == Bash(npm run test *).

CONCEPT Deny wins — precedence is deny → ask → allow

Rules are evaluated in order: deny first, then ask, then allow. The first match determines the outcome, and rule specificity does not change the order. So a broad deny like Bash(aws *) blocks even a call that also matches a narrow allow like Bash(aws s3 ls) — a deny rule can't carry allowlist exceptions.

🚫 Deny wins across every settings scope too: if user settings allow a tool and project (or managed) settings deny it, the deny blocks it. If a tool is denied at any level, no other level — not even --allowedTools on the CLI — can re-allow it.
⚠️ A bare deny like Bash removes the tool from Claude's context entirely (Claude never sees it). A scoped deny like Bash(rm *) leaves the tool available and blocks only matching calls. Bash(*) is equivalent to bare Bash.
Rules are enforced by Claude Code, not the model. Instructions in your prompt or CLAUDE.md shape what Claude tries, but they never change what the harness allows. Read/Edit rules follow the gitignore spec: //abs, ~/home, /settings-relative, and path/./path = cwd-relative.

DIAGRAM A call is checked deny → ask → allow

flowchart TD A["Claude attempts Tool(args)"] --> D{"Matches a DENY rule?"} D -->|"yes"| BLOCK["🔴 Blocked — no override possible"] D -->|"no"| K{"Matches an ASK rule?"} K -->|"yes"| PROMPT["🟠 Prompt the user"] K -->|"no"| AL{"Matches an ALLOW rule?"} AL -->|"yes"| RUN["🟢 Run without asking"] AL -->|"no"| MODE["↩ Fall back to the permission mode's default"] classDef ok fill:#d4edda,stroke:#28a745,color:#155724; classDef gate fill:#ffe8cc,stroke:#ff9f40,color:#9a4a0a; classDef bad fill:#f8d7da,stroke:#dc3545,color:#721c24; class RUN ok; class PROMPT gate; class MODE gate; class BLOCK bad;

CODE A realistic permissions block

{
  "permissions": {
    "allow": [
      "Bash(npm run *)",
      "Bash(git commit *)",
      "Read(./src/**)",
      "WebFetch(domain:docs.claude.com)"
    ],
    "ask": [
      "Bash(git push *)"
    ],
    "deny": [
      "Bash(curl *)",          // block network shell tools
      "Read(./.env)",
      "Read(./.env.*)",
      "Read(./secrets/**)"
    ]
  }
}
Pattern to remember: allow the safe routine (build/test), ask on the risky-but-needed (git push), deny the never-OK (reading .env, raw curl). Because deny beats allow, the Bash(curl *) deny holds even if a broader Bash allow exists.

TRADE-OFFS Broad allow vs. explicit rules

✅ Narrow, explicit rules

  • Least privilege — only the exact commands you meant
  • Check into version control, share across the team
  • Deny rules give a hard, un-overridable boundary

⚠️ Broad allow like Bash or Bash(*)

  • Fewer prompts, but grants arbitrary shell
  • Argument-constraining patterns (Bash(curl example.com *)) are fragile — options, redirects, and variables slip past
  • Better: deny the tool and use a scoped tool like WebFetch(domain:…)

EXAM TRAPS

Trap: "A more specific allow beats a broad deny." → Never. Precedence is deny → ask → allow and specificity is ignored. Bash(aws *) in deny blocks Bash(aws s3 ls) even with an explicit allow for it.
Trap: "Putting the rule in CLAUDE.md enforces it." → No. Memory shapes intent; only /permissions, settings rules, a permission mode, or a PreToolUse hook enforce. Rules are enforced by the harness, not the model.
Trap: "Bash(ls*) and Bash(ls *) mean the same." → The space matters. Bash(ls *) requires a word boundary (matches ls -la, not lsof); Bash(ls*) matches both.
Trap: "A user-level allow overrides a project-level deny." → Deny from any scope is evaluated before allow from any scope, so the deny wins. If denied anywhere, it stays denied.

PRACTICE

Q1 · You allow Bash(aws *) but deny Bash(aws s3 rm *). Can Claude run aws s3 rm s3://bucket/x?

No. Deny is checked first and wins regardless of the broader allow. The aws s3 rm command is blocked; other aws commands still run via the allow.

Q2 · Write a rule set that lets Claude read source but never read secrets, and lets it fetch only the docs site.

allow: ["Read(./src/**)", "WebFetch(domain:docs.claude.com)"] and deny: ["Read(./.env)", "Read(./secrets/**)"]. The deny guarantees secrets stay unreadable even if a broader Read allow is added later.

Q3 · Why is Bash(curl https://safe.com *) a weak way to restrict curl to one host?

Argument patterns are fragile: -X GET before the URL, https vs http, redirects, or a variable like $URL all evade it. Prefer denying Bash(curl *) and granting WebFetch(domain:safe.com), or use a PreToolUse hook.