Contents
What --dangerously-skip-permissions actually does
The flag equals claude --permission-mode bypassPermissions. It turns off permission prompts and safety checks, so tool calls run as soon as Claude makes them, including writes to protected paths such as .git, .claude, .bashrc and .mcp.json.
What still holds in this mode:
- Deny rules block in every mode, including bypassPermissions. A
permissions.denyentry is still a hard stop. - Allow rules have no effect, because nothing is left to allow.
- Explicit ask rules still prompt, and recognized
rmorrmdirremovals of critical paths (such asrm -rf ~) still end in a prompt or a denial. - PreToolUse hooks still run. They receive
permission_mode: "bypassPermissions"in their input, and a hook that returnsdenystops the call. - On Linux and macOS, Claude Code refuses to start in this mode as root or under
sudounless it is inside a recognized sandbox.
Anthropic's docs say bypassPermissions "offers no protection against prompt injection or unintended actions" and recommend it in isolated environments such as containers, VMs or dev containers without internet access. Two guardrails protect you from a hostile repository: since v2.1.257 a project or local settings file cannot set defaultMode: "bypassPermissions", and cloud sessions ignore that value in settings files.
Why developers reach for it, and what goes wrong
The reasons are real:
- Prompt fatigue. Anthropic's auto mode post reports that users accept 93% of manual permission prompts. At that rate, people stop reading what they approve.
- Long or parallel tasks. A refactor that stops every two minutes for a "yes" breaks flow, and several sessions multiply the stops.
- Headless runs.
claude -pin CI or a script has no one at the keyboard to answer.
The risk is that one flag removes every check at once, on a machine that holds source code, SSH keys and cloud tokens. Nx "s1ngularity" is a public example: in August 2025, malicious versions of the Nx npm package ran claude --dangerously-skip-permissions -p with a prompt that hunted for wallets, keys and .env files, and called Gemini CLI with --yolo and Amazon Q with --trust-all-tools (StepSecurity). The attacker did not need to beat a permission system. They called the agent with it switched off.
Prompt injection is the quieter version. A README, issue or web page can tell the agent to run a command. In bypass mode, nothing stands between that text and your shell except the deny rules and hooks you set up beforehand, and because protected-path writes are allowed, the agent can also edit .claude/settings.json and remove those hooks.
The ladder of safer alternatives
Climb as far as the task needs, and no further.
- Scoped allow rules. Pre-approve commands you run all day:
Bash(npm run test *),Bash(npm run lint),Bash(git diff *). Rules are evaluated deny, then ask, then allow. - acceptEdits.
claude --permission-mode acceptEditsaccepts file edits in your working directory, plusmkdir,touch,rm,rmdir,mv,cpandsedthere. Other shell commands, paths outside the project and protected paths still prompt. Review withgit diff. - Sandbox or dev container.
/sandbox, or"sandbox": {"enabled": true}, puts shell commands inside an OS boundary (Seatbelt on macOS, bubblewrap on Linux and WSL2): writes limited to the project and temp folders, network through a proxy with an empty domain allowlist.sandbox.autoAllowBashIfSandboxedlets sandboxed commands run without a prompt. For autonomous runs, the docs point to the dev container configuration, which runs Claude Code as a non-root user. - Auto mode.
claude --permission-mode autohands routine approvals to a separate classifier model that blocks actions beyond your request, aimed at unrecognized infrastructure, or driven by hostile content. Its default block list includescurl | bash, force push,git reset --hard,terraform destroy, production deploys and printing live credentials. Since v2.1.283 it is the built-in starting mode for interactive sessions on every plan. - A PreToolUse policy hook. A hook sees every tool call and its arguments before it runs, can allow, deny or ask, and applies in every permission mode. It is the layer you control fully.
Comparing the options
- --dangerously-skip-permissions: no prompts; protection left = deny rules, explicit ask rules, critical
rmchecks, your hooks. Use in a disposable container or VM with no internet. - Allow rules: fewer prompts, fully predictable, limited to command text; long lists drift.
- acceptEdits: no prompts for project edits; shell and network still prompt. Good when you review the diff.
- Sandbox: OS-enforced file and network limits for shell commands. Claude's file tools, MCP servers and hooks run outside it, and native Windows has no sandbox (use WSL2).
- Dev container: the whole process behind a container boundary; more setup, and mounted credentials are still exposed.
- Auto mode: few prompts, model judgment on each risky action. Anthropic's post reports a 17% miss rate on its set of real overeager actions; the docs say it reduces prompts "but does not guarantee safety."
- PreToolUse hook policy: exact, auditable rules enforced in every mode; as good as its rules, and text matching can be evaded.
Most teams combine them: a sandbox or auto mode for day-to-day speed, deny rules and a hook for actions that must never run unreviewed.
A PreToolUse hook that denies the worst and asks about the rest
In .claude/settings.json:
{
"permissions": {
"allow": ["Bash(npm run test *)", "Bash(npm run lint)", "Bash(git status)", "Bash(git diff *)"],
"deny": ["Read(./.env)", "Read(./.env.*)"]
},
"hooks": {
"PreToolUse": [
{
"matcher": "Bash",
"hooks": [
{
"type": "command",
"command": "${CLAUDE_PROJECT_DIR}/.claude/hooks/bash-policy.sh",
"onFailure": "block"
}
]
}
]
}
}And .claude/hooks/bash-policy.sh:
#!/bin/bash
cmd=$(jq -r '.tool_input.command // ""')
decide() {
jq -n --arg d "$1" --arg r "$2" '{
hookSpecificOutput: {
hookEventName: "PreToolUse",
permissionDecision: $d,
permissionDecisionReason: $r
}
}'
exit 0
}
# Deny: recursive force delete, force push, download piped into a shell
if grep -Eq 'rm[[:space:]]+-[a-zA-Z]*([rR][a-zA-Z]*f|f[a-zA-Z]*[rR])' <<<"$cmd"; then
decide deny "rm -rf is blocked by team policy"
fi
if grep -Eq 'git[[:space:]]+push.*(--force|[[:space:]]-f([[:space:]]|$)|[[:space:]]\+)' <<<"$cmd"; then
decide deny "Force push is blocked by team policy"
fi
if grep -Eq '(curl|wget)[^|]*\|[[:space:]]*(sudo[[:space:]]+)?(ba|z)?sh' <<<"$cmd"; then
decide deny "Piping a download into a shell is blocked by team policy"
fi
# Allow: simple commands with no chaining or substitution
if ! grep -q '[;&|`$<>]' <<<"$cmd" &&
grep -Eq '^(git (status|diff|log)|ls|pwd|npm (test|run (test|lint)))( |$)' <<<"$cmd"; then
decide allow "Safe command"
fi
decide ask "Not on the safe list: please review"Notes:
- For
deny, the reason is shown to Claude so it can change course; forask, it appears in your prompt. - A hook cannot override your rules: deny and ask rules are still evaluated whatever the hook returns, and an
allownever skips the criticalrmchecks. "onFailure": "block"stops the call if the hook crashes or times out. Without it, a failed PreToolUse hook does not block.- Print nothing but the JSON to stdout, or Claude Code may fail to parse it.
CI and headless runs with claude -p
Do not use the flag in CI unless the runner is a throwaway, network-isolated container.
- Since v2.1.302,
claude -pwith no mode set starts in Manual mode, and calls that need approval are denied unless something approves them. - Use dontAsk with an exact allowlist:
claude -p "run the test suite" --permission-mode dontAsk --allowedTools "Bash(npm test)" "Read". Anything not pre-approved is denied and the run continues. - Or set
permissions.denyInsteadOfPrompting: truein user or managed settings: calls that would wait on a prompt are denied, in any mode. - Auto mode works headless too:
claude -p "..." --permission-mode auto. A blocked action does not run and Claude keeps working. - In a
-prun, a hook'saskbecomes a denial and Claude reads your reason; a hook can also returndefer, which ends the turn so a person can resume the call later.
Rolling it out to a team
Managed settings sit above user, project, local and command-line settings. The file goes in C:\Program Files\ClaudeCode\ (Windows), /Library/Application Support/ClaudeCode/ (macOS) or /etc/claude-code/ (Linux), or comes from server-managed settings in the claude.ai admin console.
{
"permissions": {
"disableBypassPermissionsMode": "disable",
"deny": ["Read(./.env)", "Read(./.env.*)", "Read(~/.ssh/**)"]
},
"allowManagedHooksOnly": true
}disableBypassPermissionsModestops anyone from entering bypassPermissions mode;permissions.disableAutoModedoes the same for auto mode if your policy needs it.allowManagedHooksOnlyblocks user, project, local and plugin hooks, so the hooks you deploy are the ones that run.allowManagedPermissionRulesOnlyignores allow, ask and deny rules outside managed settings.- Run
/statuson a device: the Setting sources line names the managed source in effect.
Approve Claude Code, Cursor and Codex actions from a Slack alert
When a policy holds an action, SecGuardRail sends a Slack alert with a Review request link. The link opens the request on a phone-width approval page in the dashboard, where you approve or reject it. Until you decide, the action does not run: the agent is told the request number and when to retry, and after you approve, the identical command can run once within 15 minutes.
The held call and the approved run are written to the hash-chained audit log, and the decision is recorded with the reviewer's name. Requests that time out expire and the action stays blocked; a later retry opens a new request. Approving happens on that page, not inside Slack itself.
Honest limits
- Matching command text can be evaded: a script that builds a path, an alias or an unusual flag order can slip past a regex. Pair hooks with a sandbox or container.
- The sandbox covers shell commands. File tools, MCP servers and hooks run outside it, the proxy does not inspect TLS by default, and native Windows has no sandbox.
- Auto mode is a model making a judgment. It can miss actions, and boundaries stated in chat can be lost after context compaction; add a deny rule for anything that must hold.
- A hook without
onFailure: "block"fails open when it crashes or times out. - A local administrator can edit managed files. Managed settings stop the agent and ordinary users, not an admin.
- Deny rules have had bypass bugs. Keep Claude Code updated.
How SecGuardRail handles it
- A policy hook you do not have to write. SecGuardRail installs as Claude Code's PreToolUse hook and decides each call against your workspace policies. A deny works in every permission mode, including bypassPermissions and
claude -p. Policy evaluation in our tests: p50 0.11 ms; server time per hook on the hosted service about 85 ms (measured 21 Nov 2026), plus network time. - Monitor mode before enforcement. Packs install in Monitor mode: each call is evaluated and Activity shows "Monitor: would block" while nothing is stopped, with a 7-day summary before you switch a policy to Enforce.
- One policy for Claude Code, Cursor and Codex CLI. All three go through the same decision flow, approvals and audit log.
- Hold for approval. A held call is refused with a request number and a retry window, and a Slack alert links to the request. The approver opens the link, on a laptop or a phone, and approves or rejects. Approval lets the identical command run once within 15 minutes. Because a hold is a refusal plus a retry, it works when no one is at the terminal.
- Fails closed. If SecGuardRail cannot decide, shell commands, file changes and MCP tools do not run (
onFailure: block); the fail mode is configurable per tool class. - Tamper Protection. Always-on policies deny agent edits to Claude Code and Cursor settings and hook files, and attempts to switch hooks off, with a Critical alert. An admin can install the hooks machine-wide as a managed settings drop-in a standard user cannot change. An agent that goes quiet is flagged Unprotected.
- Packs for the usual failures. Git Safety, Secrets (credentials denied from leaving the machine, redacted before storage) and Prompt Injection Protection (risky actions held after a session reads suspicious content). New workspaces block
git pushto main or master by default. - Audit. Every decision is stored with agent, session, tool and redacted arguments in a tamper-evident hash chain you can verify and export as CSV or NDJSON.
- Try it. Request access at secguardrail.com/signup; we email you within one working day.
FAQ
Do deny rules still work with --dangerously-skip-permissions?
Yes. Anthropic's docs state that deny rules block in every mode, including bypassPermissions. Explicit ask rules and recognized critical rm removals still prompt. Allow rules have no effect in this mode.
Do Claude Code hooks run in bypassPermissions mode?
Yes. PreToolUse hooks receive permission_mode: "bypassPermissions", and a hook that returns deny stops the call. Set onFailure: "block" so a crashed hook does not let the call through.
How do I stop my team from using --dangerously-skip-permissions?
Set permissions.disableBypassPermissionsMode to "disable" in managed settings, where users cannot override it, and add allowManagedHooksOnly: true so your deployed hooks are the ones that run. See Claude Code security for teams.
Is auto mode a safe replacement for skipping permissions?
It is much safer, because a classifier reviews risky actions before they run. Anthropic says it does not guarantee safety, so keep deny rules for actions that must never run.
Can I approve AI agent commands from Slack?
From a Slack alert, yes. When SecGuardRail holds a Claude Code, Cursor or Codex action, the Slack alert has a Review request link that opens the request in the dashboard, on a phone or a laptop, where you approve or reject it. After approval the identical command can run once within 15 minutes; a request nobody answers expires and the action stays blocked.
What should I use for claude -p in CI?
--permission-mode dontAsk with an exact --allowedTools list, or permissions.denyInsteadOfPrompting. Keep bypassPermissions for a disposable, network-isolated container running as a non-root user.