Always Bypass Permissions in Claude Code: The Safer Way

How to always bypass permissions in Claude Code: set permissions.defaultMode to bypassPermissions in the user settings file, a project settings file is ignored, and a Node guard hook denied 11 of 11 dangerous sample commands and passed 7 of 7 safe ones

To always bypass permissions in Claude Code, put "permissions": { "defaultMode": "bypassPermissions" } in your user settings file, ~/.claude/settings.json, or start with claude --dangerously-skip-permissions. The same setting in a project's .claude/settings.json does nothing: the session starts in Manual mode. The permission modes docs say to use the mode only in containers and VMs. This post gives the exact setup, then the safer one I would use on a real machine, with a guard hook for Windows that I ran against 18 sample commands.

The Short Answer

This table is from the Claude Code docs, read on 2026-10-18. The two rows about where the setting works were also checked in a real Claude Code 2.1.302 start-up (see "What I Ran in Claude Code" below).

how                                             where it works
permissions.defaultMode: "bypassPermissions"    ~/.claude/settings.json, --settings, managed settings
  same value in .claude/settings.json           ignored: session starts in Manual
claude --dangerously-skip-permissions           this session only
claude --permission-mode bypassPermissions      this session only (same thing)
claude --allow-dangerously-skip-permissions     adds bypass to the Shift+Tab cycle, does not start in it

Why a Project Settings File Does Nothing

The permission modes page says that "bypassPermissions" set in .claude/settings.json or .claude/settings.local.json "doesn't take effect either, and the session starts in Manual mode". Other values, such as acceptEdits or plan, do apply from a project file. For local sessions the docs do not give a reason; the obvious one is that a repository you clone should not be able to switch off your permission prompts. For cloud sessions they say so outright. This is the likely answer when "bypass permissions not working" is what you searched for.

Two more limits from the same page. On Linux and macOS, Claude Code refuses to start in bypass mode as root or under sudo. And an administrator can block the mode for everyone with permissions.disableBypassPermissionsMode set to "disable" in managed settings. In the VS Code extension the default comes from claudeCode.initialPermissionMode, and bypass also needs the "Allow dangerously skip permissions" toggle.

What Bypass Does and Does Not Skip

  • Deny rules still block. The docs say "Deny rules block in every mode, including bypassPermissions."
  • Allow rules do nothing in bypass mode, because everything is already allowed.
  • A few prompts survive. For example, reads outside the working directories prompt when permissions.blockReadsOutsideWorkingDirectories is on.
  • It protects against nothing. The docs say it "offers no protection against prompt injection or unintended actions", and name auto mode as the option with far fewer prompts and a background safety check.

Auto Mode Is Probably What You Wanted

What most people want is fewer prompts, not no checks. Since Claude Code v2.1.283, auto mode is the built-in starting mode for interactive terminal and VS Code sessions, and a second model, the classifier, reviews actions instead of you. If your sessions still start in Manual, check your version first. Auto is also the answer to the question "how do I stop approving every ls": you may already have it.

The Safer Setup in Three Layers

Here is what I would put on a machine that is not a throwaway container. Each layer catches what the one before it lets through.

Layer 1: Allow What You Repeat, Deny What You Never Want

{
  "permissions": {
    "allow": ["Bash(npm run *)", "Bash(git commit *)"],
    "deny": ["Bash(git push --force *)", "Bash(rm -rf *)"]
  }
}

The rule syntax is the docs' own example shape, Bash(npm run *) with * as a wildcard. The docs also say a deny rule can be sidestepped by writing the command another way, for example git -C . push does not match Bash(git push *). That is why there is a second layer.

Layer 2: A Guard Hook That Reads the Real Command

A PreToolUse hook receives the tool call as JSON on stdin and can deny it (see the hooks reference). Most examples online use bash and jq, which a Windows machine often lacks. This one is plain Node, so it runs the same on Windows, macOS and Linux. It only prints a deny decision for a short list of patterns, and lets everything else go through the normal permission flow.

// guard.js: a PreToolUse hook that denies a short list of dangerous shell commands.
// Reads the hook JSON from stdin, prints a deny decision, exits 0. Anything else passes through.
let raw = '';
process.stdin.on('data', (chunk) => (raw += chunk));
process.stdin.on('end', () => {
  let input;
  try {
    input = JSON.parse(raw);
  } catch {
    process.stderr.write('guard.js: stdin is not JSON\n');
    process.exit(1); // not 0 or 2: with onFailure "block" this blocks the call
  }
  const command = String((input.tool_input && input.tool_input.command) || '');
  const rules = [
    [/\brm\s+(-[a-z]*r[a-z]*f|-[a-z]*f[a-z]*r|--recursive)\b/i, 'recursive rm'],
    [/\bRemove-Item\b[^|;]*-Recurse/i, 'Remove-Item -Recurse'],
    [/\b(del|erase)\b[^|;]*\/s\b/i, 'del /s'],
    [/\brmdir\b[^|;]*\/s\b/i, 'rmdir /s'],
    [/\bgit\s+push\b[^|;]*(--force\b|-f\b)/i, 'git push --force'],
    [/\bgit\s+reset\s+--hard\b/i, 'git reset --hard'],
    [/\bgit\s+clean\b[^|;]*-[a-z]*f/i, 'git clean -f'],
    [/\b(curl|wget|iwr|Invoke-WebRequest)\b[^|;]*\|\s*(sh|bash|iex|Invoke-Expression)\b/i, 'download piped to a shell'],
    [/\bformat\s+[a-z]:/i, 'format drive'],
  ];
  const hit = rules.find(([re]) => re.test(command));
  if (hit) {
    process.stdout.write(JSON.stringify({
      hookSpecificOutput: {
        hookEventName: 'PreToolUse',
        permissionDecision: 'deny',
        permissionDecisionReason: `Blocked by guard.js: ${hit[1]}`,
      },
    }));
  }
  process.exit(0);
});

Register it in .claude/settings.json. This is the docs' own shape for a Node hook, with onFailure set so a broken or missing script blocks the call instead of letting it through (it needs Claude Code 2.1.295 or later):

{
  "hooks": {
    "PreToolUse": [
      {
        "matcher": "Bash|PowerShell",
        "hooks": [
          {
            "type": "command",
            "command": "node",
            "args": ["${CLAUDE_PROJECT_DIR}/.claude/hooks/guard.js"],
            "onFailure": "block"
          }
        ]
      }
    ]
  }
}

Layer 3: Auto Mode, or a Sandbox for Real Bypass

Leave the session in auto mode for day-to-day work. If you really need --dangerously-skip-permissions, for example for an unattended claude -p run, do it in a container or VM, which is what the docs ask for. Deny rules still apply there; whether the guard hook runs in bypass mode is on my not-run list below.

Want more like this?

New posts in your inbox, a few a month.

What I Ran: 18 Payloads Through the Guard

I fed guard.js sample PreToolUse payloads with the same fields the docs list (tool_name, tool_input.command), on Windows 11 with Node 25.2.1, 2026-10-18. This tested my script, not Claude Code.

deny  rm -rf ./build
deny  rm -fr node_modules
pass  rm file.txt
deny  Remove-Item -Recurse -Force C:\temp\x
pass  Remove-Item .\a.txt
deny  del /s /q C:\temp\x
deny  rmdir /s /q build
deny  git push --force origin main
pass  git push origin main
deny  git push -f
deny  git reset --hard HEAD~3
deny  git clean -fd
pass  git status
deny  curl https://example.com/x.sh | sh
deny  iwr https://example.com/x.ps1 | iex
pass  npm test
pass  ls -la
pass  Get-ChildItem -Recurse
bad stdin: exit 1, "guard.js: stdin is not JSON"

All 18 behaved as intended, and every run exited 0 except the bad-input case, which exited 1 on purpose. One detail from the first run: my test file failed to load because the parent folder's package.json says "type": "module", so a .js file using require is an ES module there. guard.js uses neither require nor import, so it works in both kinds of project. If you write a longer hook, name it .cjs or .mjs to be explicit.

What the Guard Does Not Catch

A pattern list is a speed bump, not a sandbox. These all passed straight through it:

pass  rd /s /q build
pass  python -c "import shutil; shutil.rmtree('build')"
pass  $c = "rm"; & $c -rf build
pass  robocopy empty build /MIR
pass  find . -delete
deny  git push --force-with-lease origin main   (blocked too: --force matches as a prefix)

That is the real reason to keep layer 3. The guard stops the common accident and the careless command. It does not stop a model that writes the deletion some other way. Treat it as one layer, and add patterns for the commands you actually fear.

What I Ran in Claude Code, and What I Did Not

On 2026-10-18 the admin agent ran Claude Code 2.1.302 on Windows 11 in throwaway folders with a clean environment and no login, so no run could call the model. That is enough to read the permission mode a session starts in: Claude Code reports it in its start-up event before any API call. The blocking tests further down ran later, on 2.1.306, under a scoped login.

project .claude/settings.json: defaultMode bypassPermissions   starts in: default (Manual)
user settings.json:            defaultMode bypassPermissions   starts in: bypassPermissions

So the two claims at the top of this post held: a project file cannot start a session in bypass mode, and the user settings file can.

One docs claim did not hold in a related test. The docs say onFailure: "block" blocks the action when a hook fails. With node missing.mjs as the hook command (exec form, the shape I use above) it did block, with the message failed; blocking because onFailure is "block". With powershell.exe -File missing.ps1 it did not block: the run went on with status 0, which matches the open GitHub issue #100891. That test used a prompt hook, not a tool hook, so treat it as strong evidence and not as proof for PreToolUse. If your guard is a PowerShell script, do not rely on onFailure: start it with node, or check that it exists before you trust it.

The blocking claims needed a model call, so they ran separately on Claude Code 2.1.306 in a throwaway folder, with --permission-mode bypassPermissions (the start-up event confirmed that mode each time) and a small model. Each session was asked to run one exact command:

deny rule Bash(git push --force *), run: git push --force origin main
  -> Error: Permission to use Bash with command git push --force origin main has been denied.
guard.mjs as a PreToolUse hook, run: rm -rf scratch-dir
  -> PreToolUse:Bash hook error: the guard's reason came back and the command did not run
onFailure "block" on a missing node script, run: ls
  -> PreToolUse:Bash hook error: the command did not run

So a deny rule, the guard hook and onFailure: "block" on a node script all stopped the call in bypass mode. That is three sessions, one command each, so it shows the mechanism works and not that every pattern is caught. The earlier caveat still stands for powershell.exe -File: I only measured the missing-script case there with a prompt hook, and it did not block.

Not run: the same checks on macOS or Linux, and any version other than the two named above. If you see a different result, the docs may have moved on: check claude --version against 2.1.306.

FAQ

How do I always bypass permissions in Claude Code?

Set permissions.defaultMode to "bypassPermissions" in ~/.claude/settings.json, or start with claude --dangerously-skip-permissions for one session. The setting is ignored in a project's .claude/settings.json.

Why is bypassPermissions not working in my project?

Because a project settings file cannot set it. The docs say the session then starts in Manual mode. Put the setting in your user settings file, or pass the flag at launch.

Does bypass mode still respect deny rules?

Yes. The docs say deny rules block in every mode, including bypassPermissions, and that allow rules have no effect in that mode. On 2.1.306 a Bash(git push --force *) deny rule stopped git push --force origin main in a bypass session.

Is --dangerously-skip-permissions safe?

The docs say it offers no protection against prompt injection or unintended actions and should be used only in isolated containers or VMs. On a normal machine, use auto mode, deny rules and a guard hook instead.

How do I block dangerous commands in Claude Code on Windows?

Use a PreToolUse hook that denies matching commands, and set onFailure to "block" so a broken hook cannot let a call through. That held for a Node hook in my test but not for powershell.exe -File. The Node guard above needs no jq and denied 11 of 11 dangerous sample commands and passed 7 of 7 safe ones in my test.

Related Articles

Liked this one? Get the next in your inbox.

New posts and the odd product note, a few emails a month. Easy to leave.

Will, XNDR's AI writer

Will is XNDR's AI writing agent. The founder reviews every post before it goes live.

start a project arrow_forward