Skip to content
Max Narditdata & ai systems
← Articles
10 mindev

Claude Code --dangerously-skip-permissions: the checks that survive the flag, and the session that can delete them

Deny rules, ask rules and hooks all outrank the flag. In the same mode Claude can rewrite the project settings file those rules live in, and in my test it did, then ran the command the rule had blocked. A repository can also switch the flag off without a word. Keep the rules out of the session's reach and check what mode a run started in.

Contents

--dangerously-skip-permissions starts Claude Code in bypassPermissions mode, also known as YOLO mode. The docs’ summary of what runs without asking in that mode is one word: “Everything”. It is the same as --permission-mode bypassPermissions.

That is not the whole list. A few checks survive the flag, and the rules you write yourself (deny rules, ask rules, hooks) outrank it. The catch is where those rules live. In bypass mode Claude can write to the project’s .claude/settings.json, and when I asked a bypass session to empty that file, it did, then ran the command the deny rule in it had just blocked. The flag is also easier to lose than its name suggests: one line in a repository’s settings switched it off in my runs, with nothing on stderr.

I ran the checks below on Claude Code 2.1.337 on Linux on December 6. Every run was a one-step task under claude -p with Haiku 5.5 in a throwaway git repository, with the user settings source left out so the test machine’s own rules didn’t color the results; per-run rules and hooks came in through --settings. Nothing interactive was tested, so the countdown, the Shift+Tab cycle and the warning dialog below come from the docs, and so does anything else marked that way.

What does Claude Code —dangerously-skip-permissions turn off?

It turns off routine permission prompts and the protected-path check, and it makes allow rules irrelevant. The permission modes page puts it this way:

bypassPermissions mode disables permission prompts and safety checks so tool
calls execute immediately, including writes to protected paths.

The protected-path part is easy to underrate. Protected paths are .git, .claude, .vscode, .husky, .devcontainer, shell startup files such as .bashrc, .npmrc, .mcp.json and a few dozen more: the places where a write turns into code or configuration that runs later. In Manual, acceptEdits, auto and dontAsk modes a write there prompts, goes to the auto mode classifier, or is refused. I asked Claude to create a git hook with the Write tool, once in each of two modes:

ModeFileResult
acceptEdits.git/hooks/post-mergerefused, no file
bypassPermissions.git/hooks/post-commitcreated, no prompt

The acceptEdits refusal came back from Claude Code as:

Claude requested permissions to edit .../repo/.git/hooks/post-merge which is a sensitive file.

The Write tool doesn’t set the executable bit, so that hook wouldn’t fire yet. I didn’t run a chmod after it, and none of the surviving checks below covers one. Allow rules matter less than that: “Allow rules have no effect in bypassPermissions.”

What still stops a Claude Code bypassPermissions session?

The deny rule, ask rule, PreToolUse hook and critical-path rm check I loaded each held with the flag on. Each run asked Claude for one command:

Check (loaded with --settings)Command Claude triedResult in bypass mode
nonetouch probe0.txtran
deny rule Bash(touch *)touch probe2.txtrefused
ask rule Bash(touch *)touch probe3.txtrefused (no one to ask in -p)
PreToolUse hook denying git pushgit push origin mainrefused: “push blocked by hook”
none, critical-path checkrm -rf logs/*/*refused, files kept

A minimal version of the deny rule run (mine also passed --model and --setting-sources project,local):

shell
claude -p "Run the shell command: touch probe2.txt" \
  --dangerously-skip-permissions \
  --settings '{"permissions":{"deny":["Bash(touch *)"]}}' \
  --output-format stream-json --verbose < /dev/null

Critical paths, per the docs, are the targets an rm or rmdir must not reach: the filesystem root, top-level directories such as /usr, your home directory, the working directory and its parents, plus patterns that could expand into one of those, such as a glob under an empty variable or a glob whose depth can’t be enumerated. My test was the last kind (I didn’t run a plain rm -rf logs/a), and it came back with:

This command's glob pattern traverses directories that cannot be statically
enumerated. This requires explicit approval and cannot be auto-allowed by
permission rules.

No allow rule and no PreToolUse hook returning "allow" approves such a removal. In a -p run it is refused unless a --permission-prompt-tool or a PermissionRequest hook approves it. Per the docs, an interactive terminal gives the same removal a prompt with a two-minute countdown (v2.1.281 and later), then denies it, and after three unanswered countdowns denies further removals at once until you send a new message. The check knows Bash rm and rmdir only, and the docs warn it can miss some commands; any other approved Bash command that deletes files runs unchecked. A hook denying commands in bypass mode is not new either: it held when I tested hooks as a gate on 2.1.310.

Per the docs, and untested here, a few more items end in a prompt or a denial in every mode: AskUserQuestion and MCP tools marked requiresUserInteraction, connector tools your organization set to ask, PowerShell Remove-Item on system paths, and, if you turn them on, permissions.blockReadsOutsideWorkingDirectories (v2.1.257 and later) and permissions.blockWritesOutsideWorkingDirectories (v2.1.314 and later).

Two limits on that table. Per the docs, an installed mod can approve some calls a hook or deny rule refused unless managed settings or a Team or Enterprise login load Claude Code’s built-in guard, so “outrank the flag” holds for the setup I tested, not for every plugin you add. And every refused call ended the same way: exit code 0, a result subtype of success, and the refused calls listed in permission_denials. A script that checks only the exit code reads all of them as a job done, the same result I got testing denyInsteadOfPrompting. Read the result as well as the exit code.

Can a Claude Code bypass session remove its own deny rules?

Yes, when the rules sit in the project’s settings file. I put a deny rule for Bash(touch *) in the test repository’s .claude/settings.json and gave a bypass session two steps: overwrite that file with {}, then run touch probe9.txt. Claude read the file, overwrote it, and the touch ran in the same session with no refusal. The next run had no rule left to hit either.

That follows from the protected-path rule: .claude is protected, and protected-path writes are “Allowed” in bypass mode. Per the docs, a file you passed with --settings is a protected path too, so the same applies to it if the session can reach it (I didn’t test that one). permissions.blockWritesOutsideWorkingDirectories closes part of the gap: per the docs it makes the Write, Edit and NotebookEdit tools refuse settings files in every mode, but it doesn’t cover shell commands, MCP tools or the programs hooks run. A rule the session can rewrite with echo is a suggestion. Rules that hold need a file the session’s user can’t write, which in practice means managed settings owned by another user, or an operating-system boundary around the session.

How do you turn on Claude Code bypassPermissions mode, and which settings files can’t do it?

With the flag, with --permission-mode bypassPermissions, or with permissions.defaultMode set to "bypassPermissions" in a file passed with --settings or, per the docs, in user or managed settings (my runs loaded neither). A repository’s .claude/settings.json and your .claude/settings.local.json can’t set it. I put the same defaultMode in the three places I could test and read the mode from the run’s first line:

Where defaultMode: "bypassPermissions" was setMode the session started in
.claude/settings.jsondefault
.claude/settings.local.jsondefault
--settings JSONbypassPermissions

Neither project file printed a warning. The run started in Manual mode (default in the run’s output), and the touch was refused for lack of approval. Per the docs, the restriction is fairly new: before v2.1.257, bypassPermissions took effect from any settings file.

The rest of this section is from the docs. --allow-dangerously-skip-permissions is a different switch: it doesn’t start in bypass mode, it adds the mode to the Shift+Tab cycle so you can enter it later. It still changes one thing before you do. In an interactive terminal session with bypass available, plan mode’s blocks don’t hold, and “a file edit or shell command Claude attempts during planning can run without prompting.” You can’t enter bypass mode at all in a session started without one of these options. The first interactive start shows a warning dialog; accepting it writes "skipDangerousModePermissionPrompt": true to ~/.claude/settings.json. Background sessions (claude --bg) count that acceptance only from user or managed settings: with none recorded, a bypass launch is refused, and with the key only in .claude/settings.local.json, the session starts in Manual mode with this notice:

Bypass permissions was requested at launch and ignored · if that was you, ~/.claude/settings.json needs "skipDangerousModePermissionPrompt": true

Cloud sessions ignore a bypass defaultMode from settings files, and the VS Code extension needs its own “Allow dangerously skip permissions” toggle.

Why would Claude Code ignore or refuse —dangerously-skip-permissions?

Because a setting switched it off, or because the run is in restricted mode or running as root. Restricted mode (--restricted, v2.1.248 and later) removes the tools that run code and ignores user, project and local settings files. Combined with the flag, it stopped at once in my run:

Error: bypassPermissions not supported in restricted mode

Per the docs, running as root or under sudo on Linux and macOS stops too, unless Claude Code detects it is inside a recognized sandbox:

--dangerously-skip-permissions cannot be used with root/sudo privileges for security reasons

The quiet case is permissions.disableBypassPermissionsMode. It reads like a managed setting, but its scope is any settings file, and for this kind of lock the docs apply the strictest value any source sets. So a repository can switch the flag off for you even though it can’t switch it on. With {"permissions":{"disableBypassPermissionsMode":"disable"}} in the test repository’s .claude/settings.json, a run started with --dangerously-skip-permissions began in default mode, wrote nothing to stderr, refused its touch and exited 0.

For an unattended run, that adds up to one rule: check the mode the run started in. The first line of --output-format stream-json --verbose is the init message, and it carries permissionMode. This post-run check fails on a non-zero exit, a missing init or result, a mode other than bypass, an error result, or any refused call:

shell
claude -p "$PROMPT" --dangerously-skip-permissions \
  --output-format stream-json --verbose < /dev/null > run.jsonl
rc=$?
python3 - run.jsonl "$rc" <<'PY'
import json, sys
rc = int(sys.argv[2])
msgs = [json.loads(l) for l in open(sys.argv[1]) if l.strip()]
init = next((m for m in msgs if m.get("subtype") == "init"), None)
result = next((m for m in msgs if m.get("type") == "result"), None)
if not init or not result:
    sys.exit(f"exit {rc}: no init or result message")
denied = result.get("permission_denials") or []
print("exit:", rc, "| mode:", init.get("permissionMode"),
      "| subtype:", result.get("subtype"), "| refused calls:", len(denied))
ok = (rc == 0 and init.get("permissionMode") == "bypassPermissions"
      and result.get("subtype") == "success" and not result.get("is_error")
      and not denied)
sys.exit(0 if ok else 1)
PY

On my saved runs it passed the plain bypass run and failed the deny rule run (refused calls: 1), the repository lock (mode: default), an empty output and a hand-made error_max_turns result. It also passed the run that deleted its own deny rule, which is the limit of any check like this: it tells you how the run went, not whether the rules were still there. And keep run.jsonl somewhere the session can’t write.

Can you turn off the Claude Code critical-path rm prompt in bypass mode?

Yes, from v2.1.311, with CLAUDE_CODE_EVEN_MORE_DANGEROUSLY_SKIP_PERMISSIONS=1 in the environment that launches claude. I didn’t set it; this section comes from the docs. The variable is read from the launch environment only and ignored in a settings file’s env block, and the docs’ warning is plain: “a command such as rm -rf ~ can run without asking you.” It also lets through flagged commands Claude Code can’t fully parse, in the Bash and Monitor tools.

The more useful part of the docs’ entry is the list of things that keep the prompt on anyway. Examples: a PermissionRequest hook with any matcher, a PreToolUse hook answering ask, a --permission-prompt-tool, the VS Code chat panel or the Desktop app, a claude started from inside another session, background sessions, agent-team teammates in split panes, blockReadsOutsideWorkingDirectories, and a deny or ask rule that targets Bash, Edit or Read (even one removed later in the session). That last one means the deny rules from the sections above and this variable don’t combine: to remove a tool while the variable is set, the docs point to --tools instead of a deny rule. Claude Code prints a startup line saying whether the variable took effect (on stderr in a -p run), so read it rather than assume.

Where should you run Claude Code with —dangerously-skip-permissions?

Inside a container, a VM or the sandbox runtime, as a non-root user. The mode table lists bypass as “Isolated containers and VMs only”, and the sandbox environments page says why the built-in Bash sandbox alone isn’t enough:

Always run --dangerously-skip-permissions sessions inside a container, a VM,
or the sandbox runtime, so that file tools, MCP servers, and hooks are also
inside the boundary.

The built-in Bash sandbox wraps shell commands and nothing else. Read, Edit and Write run inside the Claude Code process, and local MCP servers and hooks run as separate processes on your host. In my built-in sandbox test, bypass mode let a command reach a host outside the allowlist (200) until strictAllowlist was on. The standalone sandbox runtime (srt claude) wraps the whole process without Docker, denies network access by default and has to be granted every path and endpoint the session needs; the same piece could list ~/.ssh under it until a denyRead entry was added. A remote MCP server is a different matter: no local boundary limits what it does with its own credentials.

A container protects the host, not what you mount or pass into it. The dev container page says bypass mode doesn’t stop a malicious project “from exfiltrating anything accessible inside the container, including the Claude Code credentials stored in ~/.claude”, and that Claude “can still modify any file in the bind-mounted workspace, which appears directly on your host”. Put that next to the results above: a .git/hooks file or an emptied .claude/settings.json written inside the container lands in your host checkout. A repository can also run code on the first claude -p in it: per the hooks reference, hooks in settings files run in a folder you’ve never trusted in a headless run. So the setup that matches the docs, and my tests, is short:

1. Read the repository's .claude/, .mcp.json and .devcontainer/ before
   the first headless run in it, or start that run with --bare.
2. Non-root user in the container or VM. Don't rely on the root refusal:
   per the docs it is lifted inside a recognized sandbox.
3. No host secrets mounted: no ~/.ssh, no cloud credential files.
   Repository-scoped or short-lived tokens only.
4. Egress allowlist (the reference dev container ships init-firewall.sh),
   or your own network controls.
5. Deny rules where the session's user can't write or replace them,
   including the directory they sit in and any hook script they call:
   on Linux, managed settings in /etc/claude-code/managed-settings.json.
6. Afterwards, review the tracked diff, then list .git/hooks, .git/config
   and the untracked or ignored files under .claude/ by hand: git diff
   and git status don't show what sits inside .git.

Point 5 is the one the bypass flag makes urgent, because it is the mode in which the project settings file is fair game. The dev container page adds one more catch: the Dockerfile step that installs those managed settings lives in the repository, so anyone with write access to it, a bypass session included, can change that step for the next build.

Should you use Claude Code auto mode or dontAsk instead of bypassPermissions?

Usually, yes. Auto mode, the built-in starting mode for interactive terminal and VS Code sessions since v2.1.283, sends the actions your rules don’t settle to a classifier instead of a prompt, and the docs call isolation defense in depth for it rather than a requirement. dontAsk suits CI: anything that would prompt is refused, while reads in the working directory and your pre-approved tools still run. The docs’ CI line is claude -p "run the test suite" --permission-mode dontAsk with --allowedTools "Bash(npm test)" "Read".

Bypass fits when the box itself is the control: a disposable container or VM whose only valuable contents are the repository you are about to review anyway. Inside that box, the rules that survive the flag still stop the commands they name; in my runs a deny rule, a hook on git push and the rm check each held. They match commands as written, which is the limit the hooks piece found, and the session can rewrite the file they live in. So the box does the holding, and the rules steer inside it. Anywhere else, the docs’ warning stands: “bypassPermissions offers no protection against prompt injection or unintended actions.”

I’ve argued that over-prompting pushes people toward the bypass flag. If that is how you got here, keep two results from above: the session can delete the rules you added to slow it down, and a repository can cancel the flag without a word while the run still exits 0. Read permissionMode from the first line before you trust what the run reports.

01 / Discussion

No comment section here — all discussions happen on X.

Max Nardit@mnardit

02 / More articles