GenovaFlow GenovaFlow Services Blog Get my price in one call Get my price
Claude Code

Claude Code Permissions: Allow, Ask and Deny Rules That Work

Cover image for the article Claude Code Permissions: Allow, Ask and Deny Rules That Work, with a screenshot from the article

Claude Code checks deny, then ask, then allow, and the first match wins

Claude Code checks permission rules in one fixed order, deny first, then ask, then allow, and the first match decides the outcome, so a narrow allow rule can never rescue a call that a broader deny rule already blocks (see the Claude Code permissions docs). Six permission modes sit on top of those rules. The catch is that a Bash deny rule matches the command text Claude writes, not the program, so it is a speed bump and not a wall.

The three rule types do what their names say. Allow rules let Claude use a tool without asking, ask rules prompt every time, and deny rules block the tool. The docs give a concrete case: a deny rule Bash(aws *) blocks every matching call, including one that also matches a narrower allow rule Bash(aws s3 ls), and specificity never changes the order.

The Claude Code permissions page paragraph stating rules are evaluated deny, then ask, then allow
Evaluation order as the docs state it.

Two details from the same page are worth knowing before you write a single rule. A bare tool name in a deny rule, such as Bash, removes the tool from Claude's context entirely, while a scoped rule such as Bash(rm *) leaves the tool in place and blocks matching calls. And the rules are enforced by Claude Code itself, not by the model, so a line in your prompt or in CLAUDE.md shapes what Claude tries to do but changes nothing about what Claude Code allows.

That second point decides where the rules belong. If you want Claude to stay out of a folder, an instruction in a text file is a request, while a deny rule is enforcement. Our guide to how to use Claude Code covers the instruction side, and this post covers the enforcement side.

If your team runs Claude Code on real repositories and you are unsure what it can reach, we can review the setup with you. Book a call with GenovaFlow AI

Six permission modes decide what runs without asking

The mode sets the baseline for what Claude may do before any rule is consulted, and the permission modes page lists six of them. Press Shift+Tab during a session to cycle default, then acceptEdits, then plan, with the optional modes after plan, or start a session with claude --permission-mode plan.

ModeWhat runs without asking
default (shown as Manual)Reads only
acceptEditsReads, file edits, and common filesystem commands such as mkdir, touch, mv and cp inside the working directory
planReads, plus classifier approved commands when auto mode is available
autoEverything, with background safety checks
dontAskFile reads in working directories and pre approved tools; anything that would prompt is denied
bypassPermissionsEverything

Rules and modes interact in two ways that surprise people. Deny rules block in every mode, including bypassPermissions, while allow rules have no effect in bypassPermissions at all, according to the permission modes page. The same page says that entering auto mode drops broad allow rules such as Bash(*) and wildcarded interpreters such as Bash(python*), and that auto mode pauses and goes back to prompting after the classifier blocks an action 3 times in a row or 20 times in total.

The flag people reach for to stop the prompts is --dangerously-skip-permissions, which the docs describe as equivalent to bypassPermissions. The docs say to use it only in isolated environments such as containers and VMs, and Claude Code refuses it as root or under sudo on Linux and macOS (permission modes page). If your goal is fewer prompts on a normal laptop, a short allow list is the safer route, which is what the next section builds.

Rules are Tool or Tool(specifier), and the star belongs after the subcommand

Every rule has the form Tool or Tool(specifier), and for Bash the specifier is the command text with * standing in for any text, per the permissions docs. A rule with no star matches one exact command, so Bash(npm run build) allows that command and nothing else.

Where you put the star limits the rule. The docs warn to put it after the subcommand, because everything before the first star is matched as written: Bash(git log *) allows only git log commands, while Bash(git *) allows every git command (permissions docs). Claude Code also warns at startup about an allow rule with a star before the subcommand, such as Bash(git * main).

Compound commands are handled safely. The recognised separators are &&, ||, ;, |, |&, & and newlines, and every subcommand must be allowed for the whole command to run without a prompt, so Bash(safe-cmd *) does not permit safe-cmd && other-cmd (permissions docs). A fixed set of wrappers is stripped before matching, namely timeout, time, nice, nohup and stdbuf plus a few shell builtins, so a rule for npm test * also covers timeout 30 npm test. Runners such as npx, docker exec and devbox run are not stripped, which means a rule like Bash(devbox run *) matches whatever follows run.

Here is a starting file built from that syntax. It is an example we assembled from the documented rule forms, not a configuration from a test run, so adjust the commands to your project.

text
{
  "permissions": {
    "allow": [
      "Bash(npm run *)",
      "Bash(git log *)",
      "Bash(git diff *)"
    ],
    "ask": [
      "Bash(git push *)"
    ],
    "deny": [
      "Read(./.env)",
      "Read(./.env.*)"
    ]
  }
}

The two deny lines for .env files come straight from the example in the settings docs, which pairs them with allow rules for lint and test commands. Run /permissions afterwards to see every rule and the file it came from.

A Bash deny rule stops the usual form of a command, not every form

A Bash rule matches the command text Claude writes after splitting compound commands and stripping wrappers, and it does not match the same program invoked in a different form. The permissions docs say so directly: a deny or ask rule covers the invocation Claude usually produces and is not a security boundary around the program.

The Claude Code permissions page table listing which commands Bash(curl *), Bash(rm *) and Bash(git push *) stop and which they do not
The official permissions page lists the invocations a Bash deny rule misses.

The docs list the gaps. Bash(curl *) stops curl https://example.com but not /usr/bin/curl https://example.com or sh -c 'curl https://example.com'. Bash(rm *) stops rm -rf build/ but not /bin/rm -rf build/ or bash -c 'rm -rf build/'. Bash(git push *) stops git push origin main but not git -C . push origin main (permissions docs).

In practice that changes how you use deny rules. They are good at catching the obvious mistake, which is the form Claude produces almost every time, and they are the right place for file rules such as the .env reads above. They are the wrong place to rely on for something that must never happen, such as a push to production or a network call carrying secrets.

For those cases the docs point to two other layers. Sandboxing gives filesystem and network enforcement that does not depend on the command text, and a PreToolUse hook lets you inspect the full command with your own logic before it runs (permissions docs).

Rules live in four settings files, and a deny in any of them wins

Permission rules follow the same precedence as every other setting. Claude Code reads four sources, which the settings docs list as the user file ~/.claude/settings.json, the shared project file .claude/settings.json, the personal project file .claude/settings.local.json, and managed settings from an organization. Precedence runs managed, command line, local project, shared project, then user.

Permission lists do not replace each other across files; the docs say list keys such as permissions.allow are combined, so each file can add entries without removing another file's (settings docs). Deny is the exception to any idea of an override. If a tool is denied at any level no other level can allow it, so a user level deny blocks a project level allow, and a managed deny cannot be undone by --allowedTools (permissions docs).

Two behaviours matter for teams. Allow rules in a committed .claude/settings.json wait until each teammate trusts the folder, while deny and ask rules apply right away, and the values auto and bypassPermissions for permissions.defaultMode are ignored when they come from project or local files (settings docs). Run /status to see which settings sources loaded, and claude doctor to list entries Claude Code rejected.

Add the sandbox when a rule has to hold

The sandbox is an operating system boundary around the shell commands Claude runs and the processes they start, built on Seatbelt on macOS and bubblewrap on Linux and WSL2, and it is off by default (see the sandboxing docs). Turn it on with /sandbox or by setting sandbox.enabled to true in a settings file. The enforcement comes from the open source sandbox runtime package, which restricts filesystem and network access for a process at the operating system level without a container.

It covers Bash, PowerShell and Monitor commands only. Claude's file tools, MCP servers and hooks run outside it, and by default reads of most of the machine, including ~/.ssh, are allowed unless you deny them (sandboxing docs). That is why the docs recommend using permissions and the sandbox together: permissions decide which tools and paths Claude may touch, and the sandbox limits what a shell command can reach even if the command text slips past a rule.

If you are rolling Claude Code out to a team and want help deciding which rules, modes and sandbox settings fit your repositories, our custom AI agents service is where that work happens. For the cost side of running Claude Code all day, see how to cut Claude Code token usage, and for the other guides in this category browse the Claude Code section.

Questions people ask

What is the difference between allow, ask and deny in Claude Code?

Allow rules let Claude Code use a tool without manual approval, ask rules prompt for confirmation every time, and deny rules block the tool. They are checked in the order deny, then ask, then allow, and the first match decides. Specificity does not change that order, so a broad deny rule beats a narrower allow rule. Details are in the permissions docs.

Which rule wins if allow and deny both match?

Deny wins. Claude Code evaluates deny rules first, and if a tool is denied at any settings level no other level can allow it. A deny rule such as Bash(aws *) blocks a call even when a narrower allow rule like Bash(aws s3 ls) also matches, as the permissions docs explain.

What does dangerously skip permissions do?

The flag --dangerously-skip-permissions starts Claude Code in bypassPermissions mode, which runs everything without prompts. Deny rules still block, and allow rules have no effect. The docs say to use it only in isolated environments such as containers and VMs, and it is refused as root or under sudo on Linux and macOS (permission modes page).

Where do Claude Code permission rules live?

In the permissions block of a settings file: ~/.claude/settings.json for you everywhere, .claude/settings.json for a project you commit, .claude/settings.local.json for personal overrides, or managed settings from an organization. Run /permissions to see each rule and the file it came from (settings docs).

Does a deny rule on Bash(curl *) stop every curl call?

No. It stops curl https://example.com but not /usr/bin/curl https://example.com or sh -c 'curl https://example.com'. The docs say a Bash rule is not a security boundary around the program. For enforcement that ignores the command text, add the sandbox or a PreToolUse hook (permissions docs).

Sources

  1. Configure permissions, Claude Code Docs
  2. Choose a permission mode, Claude Code Docs
  3. Settings files and precedence, Claude Code Docs
  4. Sandboxing, Claude Code Docs
  5. Anthropic sandbox runtime repository, GitHub