skip to content

A Claude Code settings file denies `Bash(aws *)` and allows `Bash(aws s3 ls)` — what happens when Claude runs `aws s3 ls`, and why?

level: seniorimportance: must knowfreq 22%

answer

  1. three lists, fixed order
  2. first match decides
  3. specificity buys nothing
  4. deny anywhere beats allow anywhere

basics

~20 s

The call is blocked: Claude Code checks deny rules, then ask, then allow, and the first match decides regardless of specificity, so an allow rule can never carve an exception out of a matching deny.

solid answer

~40 s

It is blocked. Claude Code evaluates `permissions.deny` first, then `permissions.ask`, then `permissions.allow`, and the first match decides; how specific a rule is does not change that order. `Bash(aws *)` matches `aws s3 ls`, so the narrower allow is never reached. The same holds between ask and allow: a matching ask rule prompts even when a more specific allow matches. Across sources, a deny at any level wins: a user-level deny blocks a project-level allow, and `--allowedTools` cannot override a deny from settings, while `--disallowedTools` adds deny rules for the session. When no rule matches, the permission mode decides. To allow read-only AWS calls, drop the broad deny, allow the read commands you want, and deny the destructive ones by name.

go deeper

for a junior

Recall the order: deny first, then ask, then allow, and the first matching rule decides the outcome.

for a middle

Explain why specificity is irrelevant, how ask beats allow the same way, and that the permission mode decides when no rule matches.

for a senior

Show the cross-source picture: a deny from any file or flag wins, --allowedTools cannot reopen it, and the design that replaces a broad deny with narrow ones.

for a principal

Use deny-first to build a baseline: centrally owned denies nobody can override, with allows left to teams, and decide where negation carve-outs belong.

## The evaluation order Claude Code holds permission rules in three lists under the `permissions` object: - `permissions.deny`: block the tool use. - `permissions.ask`: prompt for confirmation every time. - `permissions.allow`: run without asking. For every tool call, Claude Code checks the lists **in that order: deny, then ask, then allow**. The first rule that matches determines the outcome, and **rule specificity does not change the order**. There is no longest-match or most-specific-wins logic of the kind found in some firewalls. ## Walking through the example ```json { "permissions": { "allow": ["Bash(aws s3 ls)"], "deny": ["Bash(aws *)"] } } ``` 1. Claude asks to run `aws s3 ls`. 2. Claude Code checks deny: `Bash(aws *)` matches, because everything before the `*` (`aws `) matches and the `*` covers `s3 ls`. 3. The call is blocked. The allow list is never consulted. An allow rule **cannot carve an exception out of a deny rule**. The same precedence applies between ask and allow: with `Bash(git push *)` in ask and `Bash(git push origin main)` in allow, `git push origin main` still prompts. ## When nothing matches Rules are a layer over the **permission mode**. If no rule matches a call, the mode decides whether it runs, prompts, goes to a classifier or is denied. Rules also interact with modes in fixed ways: - An `ask` rule prompts even in a mode that would otherwise approve the call, such as `acceptEdits` or `bypassPermissions`; in `dontAsk` mode a matching ask rule denies instead. - `allow` rules keep working in `dontAsk`, which is why that mode is usable at all. ## Precedence across settings sources Rules arrive from several places: managed settings, user settings, project and local settings, command-line flags, and rules added in the session. The deny-first logic spans them all: | Situation | Result | | :- | :- | | User settings allow, project settings deny | **Blocked**: deny is evaluated first, from any scope | | Project settings allow, user settings deny | **Blocked**: same reason, in reverse | | `--allowedTools` names a tool a settings file denies | **Blocked**: the flag only adds allow rules | | `--disallowedTools` adds a rule | **Added restriction** for that session | | Managed settings deny | Nothing else, command line included, can allow it | In short, **if a tool is denied at any level, no other level can allow it**. Which settings file wins for other keys is a separate topic; for permission rules, a deny anywhere is enough. ## Bare tool names against scoped rules A deny rule naming only a tool, like `Bash` or `WebFetch`, **removes the tool from Claude's context**, so Claude never sees it. A scoped deny like `Bash(rm *)` leaves the tool available and blocks matching calls when Claude attempts them. Tool-name globs in deny, such as `"mcp__*"`, behave like bare names. ## The one carve-out: path negation For `Read` and `Edit` deny or ask rules, a pattern starting with `!` is a gitignore negation that carves paths out of rules listed before it **in the same source**. `Read(*.env)` followed by `Read(!sample.env)` in one file's deny list blocks every `.env` file except `sample.env`. The carve-out cannot reach a deny from another settings file, and it applies only to `Read` and `Edit` path patterns. ## Expressing "read-only AWS only" Since an allow cannot punch through a deny, invert the design: - Remove the broad `Bash(aws *)` deny. - Allow the read commands you want, such as `Bash(aws s3 ls *)`. - Deny the destructive ones explicitly, such as `Bash(aws s3 rm *)`. - Let everything else fall through to the mode, which prompts in Manual mode. Remember that Bash rules match command text, so they guide the common spelling rather than seal the program off. A PreToolUse hook can add custom logic, but its allow does not override a matching deny or ask rule either. ## Auditing a rule set When reviewing a team’s settings, read the deny list first and ask, for every allow, whether a deny or ask rule elsewhere already shadows it. A shadowed allow is dead configuration that misleads the next reader; `/permissions` shows every rule with the file it came from, which makes the shadowing visible. ## Why interviewers ask People bring firewall or CSS intuitions, where the most specific rule wins. Claude Code does the opposite, and a candidate who knows that writes narrow denies and broad-enough allows instead of hoping an exception will work.

  • Can `claude --allowedTools "Bash(rm *)"` re-enable `rm` for one session when a settings file denies it?
    No. `--allowedTools` only adds allow rules for that session, and deny rules are evaluated before allow rules from every source. A deny in any settings file, managed settings included, still blocks the call. `--disallowedTools` works the other way and adds deny rules beyond what the settings define.
  • How do you block every `.env` file except a checked-in `sample.env`?
    Use a gitignore negation in the same deny list: `Read(*.env)` followed by `Read(!sample.env)`. A `!` pattern carves paths out of the `path` or `./path` rules listed before it in the same source only. It cannot cancel a deny from managed settings or another file, and a `!` rule listed first carves nothing out.

  • The more specific rule wins, so the narrow allow lets aws s3 ls run
  • An allow rule can carve an exception out of a broader deny
  • --allowedTools overrides a deny from settings for one session
  • A project allow beats a user-level deny because project settings are closer
  • Whichever list comes first in the JSON file is checked first