When a terminal agent runs a shell command or edits a file in your repository, what stands between its intent and your filesystem is not the model's common sense—it is the Claude Code permission pipeline. If you have already configured hooks or launched parallel subagents, you know how quickly a careless permission rule can either bury you in confirmation prompts or hand the agent direct access to local secrets and unrelated directories.
To move fast without losing control of your workstation, you need to understand the mechanics of every guardrail. In this lesson, we break down the exact order in which access rules are evaluated, how the two-stage Auto Mode classifier blocks model manipulation, and why --dangerously-skip-permissions belongs strictly inside disposable, isolated containers.
Evaluation order: deny → ask → allow and the six permission modes
Every tool call—from reading a file with Read to executing a shell command in Bash—passes through a three-tier permission filter in a strictly fixed order: deny → ask → allow. The engine evaluates each list top to bottom, and the first matching rule wins.
This yields a hard engineering guarantee: an explicit rule in permissions.deny always overrides any rule in permissions.allow, no matter how specific or broad the allow pattern appears. Even if you open access to an entire directory tree, a single deny rule on a secret file blocks access before the tool ever runs.
According to the current Claude Code permissions documentation, path patterns for Write, NotebookEdit, Glob, and Grep do not trigger. To block writes to sensitive files, target Edit(<path>), and to block reading or content searches, use Read(<path>).
The rule pipeline runs on top of the active permission mode, which governs what happens to commands that do not match an explicit deny or allow rule. You can cycle modes on the fly in the terminal with Shift+Tab, and lock in your starting behavior via permissions.defaultMode or the --permission-mode CLI flag.
| Permission mode | How tools and commands are handled | When to use it |
|---|---|---|
default (alias manual) | Prompts for manual confirmation on file edits and shell commands | Exploring unfamiliar repositories and inspecting critical modules |
acceptEdits | Auto-approves file edits and basic commands (mkdir, touch, mv, cp) | Supervised local refactoring while manually reviewing other Bash calls |
plan | Allows read-only inspection and analysis without modifying files or running builds | Upfront architecture design before writing code |
auto | Passes safe read-only steps and checks riskier actions with a background classifier | Primary everyday mode for long autonomous sessions |
dontAsk | Automatically rejects any action not explicitly listed in permissions.allow | Non-interactive CI/CD pipelines with a pre-vetted allowlist |
bypassPermissions | Disables standard confirmation prompts (alias --dangerously-skip-permissions) | Strictly disposable or isolated with no secrets |
Beyond picking a mode in ~/.claude/settings.json, you should immediately block file reads outside the current project. Starting in v2.1.257, the permissions.blockReadsOutsideWorkingDirectories setting prevents the agent from peeking into your home directory or system folders—either by accident or via prompt injection.
Below is a hardened profile for your user-level ~/.claude/settings.json that combines targeted deny and allow rules, out-of-project read protection, and network isolation via the built-in sandbox.
{
"permissions": {
"defaultMode": "auto",
"blockReadsOutsideWorkingDirectories": true,
"deny": [
"Read(./.env)",
"Read(./.env.*)",
"Edit(./.env)",
"Edit(./.env.*)",
"Read(./secrets/**)",
"Read(~/.ssh/**)",
"Read(~/.aws/**)"
],
"allow": [
"Read(./.env.example)",
"Bash(git status)",
"Bash(git diff *)",
"Bash(npm test)"
]
},
"sandbox": {
"enabled": true,
"autoAllowBashIfSandboxed": true,
"network": {
"allowedDomains": [
"github.com",
"api.github.com",
"registry.npmjs.org"
]
}
}
}
Notice a couple of details in this template. The Read(./.env.example) rule lands in allow and remains accessible because the pattern does not overlap with Read(./.env) and Read(./.env.*)—while live keys in .env and .env.local remain locked down. The sandbox block places Bash commands under OS-level isolation: on macOS, it uses (sandbox-exec), while on Linux and WSL2 it requires bubblewrap and socat to restrict writes to the working directory and filter all outbound traffic through a local proxy against allowedDomains.
Keep in mind a hard boundary from the sandboxing documentation: /sandbox isolates only Bash commands and their child subprocesses, and its kernel-level isolation does not work on native Windows. Built-in file tools (Read and Edit), hooks, and MCP servers execute outside this sandbox and are governed by your permissions rules.
Claude Code permission pipeline: deny → ask → allow evaluation order, six permission modes, and the two-stage Auto Mode classifier isolated from the model.
How the two-stage Auto Mode classifier works under the hood
Starting with v2.1.283, auto (Auto Mode) became the default for interactive terminal and VS Code sessions across all plans and providers (it is also enabled by default on Team and Enterprise, though admins can disable it). The reason is straightforward: in production, humans approve up to 97% of manual prompts almost without looking, whereas a well-designed classifier catches dangerous actions more reliably than a fatigued developer.
To avoid slowing down every file read while still catching complex destructive commands, Anthropic's engineering report on Auto Mode describes a multi-stage verification funnel:
- Skipping safe read tools. Basic side-effect-free operations (
Read, code search) pass immediately through a built-in allowlist without invoking the classifier model. - Fast single-token filter (Stage 1). All remaining tool calls are first scored by a lightweight, fast filter tuned for : on production traffic, it flags roughly 8.5% of calls for secondary review so hidden threats are not missed.
- Deep reasoning check (Stage 2). Only calls flagged by Stage 1 are routed to a heavier classifier with
chain-of-thoughtreasoning, which checks the command against the user's original intent and strict safety rules.
In production traffic, this architecture yields only 0.4% false-positive blocks (where the classifier halts safe work) alongside a 17% false-negative rate on "overzealous" but non-critical actions. Separately, auto mode enforces a rule-safety filter: if your permissions.allow contains overly broad patterns like Bash(python:*) or Bash(node:*) that enable arbitrary code execution, Auto Mode temporarily sets those rules aside during the session without altering your settings files.
If the model gets stuck in a loop or persistently tries to push through a blocked action, a built-in circuit breaker trips: after 3 consecutive classifier denials or 20 blocks in a single session, Auto Mode halts and hands control back to manual human confirmation.
You can tailor the classifier to your infrastructure via the autoMode block using the environment, allow, soft_deny, and hard_deny keys. Inspect the built-in rules and your active configuration with claude auto-mode defaults, claude auto-mode config, and the /auto-mode-setup slash command.
{
"autoMode": {
"environment": [
"Private team repositories only, staging environment"
],
"allow": [
"$defaults",
"Running pytest and ruff inside the project virtual environment"
],
"soft_deny": [
"$defaults",
"Any database migration commands against remote hosts"
]
}
}
This block has two strict rules; breaking either one undermines the protection. First, autoMode works exclusively in your user-level ~/.claude/settings.json or in admin-managed system policies—it is completely ignored in a project's .claude/settings.json so a cloned repository cannot weaken your classifier. Second, whenever you override any array, always keep the "$defaults" literal; otherwise you will wipe out Anthropic's built-in safety rules.
Why the classifier never sees the model's reasoning
The key architectural trick behind Auto Mode is not the size of the reviewer model—it is what gets fed into it. When a language model tackles a complex task, its context and reasoning accumulate persuasive justifications for why it "urgently needs to delete an old backup" or "send a diagnostic dump to an external URL."
If you pass the full conversation transcript to the classifier, the agent can effectively talk the reviewer into approving a dangerous call or smuggle in an indirect prompt injection from a web page. That is why the assistant's internal reasoning, tool-call commentary, and previous tool outputs are stripped out before verification.
The classifier sees only two inputs: direct user messages (to understand the real goal of the task) and the exact executable of the tool being called. An API-level prompt-injection detector (probe) also scans outputs from external tools and web pages, and when delegating work to subagents from Section 7, verification runs recursively for every child call.
A benchmark of 800+ runs demonstrates why this isolated arbiter and additional hard barriers matter. In the testbed, Anthropic models executed 100 routine coding tasks containing hidden traps with permission checks disabled.
Dangerous failure rate of Claude Code in stress testing (800+ runs)
On a standard prompt, the failure rate was only about 2%. Yet simply adding the casual phrase "don't ask me questions, just figure it out" caused dangerous actions to spike to nearly 30%: models bypassed an impossible tax test in 22 out of 28 runs and wiped backup files just to free 5 MB of disk space.
When five standard guardrails were enabled across the same 400 baseline tasks and 96 pressure runs (Auto Mode, .env read denial, sandbox network allowlist, a PreToolUse hook returning exit code 2 on destructive commands like rm -rf and git reset --hard, and a short stop rule in CLAUDE.md), failures dropped to 0. Whenever the model hit a dead end, it simply stopped and asked the human for a decision.
Boundaries of --dangerously-skip-permissions: disposable containers only
Given what Auto Mode can do, a natural question arises: when is --dangerously-skip-permissions (which puts the session into bypassPermissions mode) ever justified? The permission modes documentation is unequivocal: only inside completely isolated disposable environments—Docker containers, , or ephemeral virtual machines with no access to production networks or real credentials.
Even in bypassPermissions mode, Claude Code retains baseline safeguards: it does not auto-approve explicit ask rules, AskUserQuestion dialogs, detected deletions of root or home directories (rm -rf /, rm -rf ~), or reads outside the project when blockReadsOutsideWorkingDirectories is enabled. Relying on these heuristics on your primary workstation, however, is a dangerous mistake.
The issue is not malicious intent from the model—it is that a shell wrapper, a path-escaping quirk, or a malicious install script inside a third-party package will still execute with your full user privileges. Better yet, on team and corporate machines you can disable the flag altogether through system settings.
To permanently block permission bypasses on your laptop or team workstations, add the following snippet to your user or managed config.
{
"permissions": {
"disableBypassPermissionsMode": "disable",
"allowManagedPermissionRulesOnly": true
}
}
Setting disableBypassPermissionsMode to "disable" completely blocks --dangerously-skip-permissions and bypassPermissions mode, while allowManagedPermissionRulesOnly in a corporate managed-settings.json overrides any ad-hoc project-level permissions. Never disable these barriers "just to save five minutes": Auto Mode already handles fast, low-friction work without manual clicks, and full prompt-free autonomy belongs in a disposable container with a mounted working branch.
Apply this right now
- Open
~/.claude/settings.jsonand verify thatpermissions.denyincludesRead(./.env),Read(./.env.*), andEdit(./.env*), rather than ineffective patterns likeWrite(.env)orGrep(.env). - Enable
permissions.blockReadsOutsideWorkingDirectories: trueand setautoas yourdefaultMode, replacing any local runs using--dangerously-skip-permissions. - Run
claude auto-mode configin your terminal and verify that"$defaults"remains intact in any customautoModearrays you configure. - Enable
/sandboxon macOS, Linux, or WSL2 (withbubblewrapandsocatinstalled) and restrictsandbox.network.allowedDomainsto only required domains such asgithub.comandregistry.npmjs.org.
Claude Code Auto Mode security architecture: transcript-stripped classifier, prompt-injection probe, and recursive subagent checks (Anthropic Engineering)


