Skip to content
Mia Automation
NLEN Sign in Put Mia to workGet started

Claude Code Permissions: Let It Work Freely Without Breaking Anything

Claude Code permissions come in three layers: allow, ask and deny rules in a settings file, a permission mode that decides what happens to everything else, and hooks, small scripts that can refuse a command before it runs. In our test, a deny rule on rm stopped rm -rf build but not the same delete written in Python. A 30-line hook stopped both. Below is the settings file and hook we used, what each layer catches, and when --dangerously-skip-permissions is a reasonable choice.

Claude in practiceUpdated 8 min read

Tested by us on 11 November 2026.

How Claude Code decides whether a command may run

Every tool call passes the same checks. PreToolUse hooks run first and can block. Then the rules: deny is checked before ask, and ask before allow, so a deny rule always wins, however specific your allow rule is. Anything no rule covers goes to the permission mode. In the default mode, labeled Manual, Claude Code asks you.

Diagram: a command passes the PreToolUse hook, then deny, ask and allow rules, then runs. rm -rf build is stopped by the deny rule; a Python one-liner that deletes the same folder is only stopped by the hook
The order of checks, with the two commands from our test. Deny rules match the text of a command; a hook can check what it does.

What you need

  • Claude Code installed and signed in. We tested version 2.1.321 on Ubuntu.
  • A project folder with a .claude folder in it. Project settings go in .claude/settings.json, personal ones in .claude/settings.local.json.
  • Python 3 for the hook below. Any language works, as long as the script reads JSON from standard input and exits with code 2 to block.

Set up permissions in four steps

  1. Allow what's safe and frequent

    Every prompt you click through trains you to click without reading. Allow the commands Claude Code runs all day in your project: your test runner, your build script, read-only git commands. Put them in .claude/settings.json so the whole team gets the same list.

  2. Deny what must never happen

    Deny rules win over everything else. Block reading secrets with Read(./.env), block edits to folders that other systems own, and block the obvious destructive commands. Remember what a deny rule matches: the text Claude Code writes. Anthropic's own docs note that Bash(rm *) doesn't match /bin/rm or bash -c 'rm ...'.

  3. Ask before anything that leaves your machine

    Put git push, deploys and anything that sends data in the ask list. Claude Code then stops and shows you the exact command, even in a session where most work runs without prompts.

    json
    {
      "permissions": {
        "allow": ["Bash(python3 *)", "Bash(ls *)", "Bash(git status)", "Bash(git diff *)"],
        "ask":   ["Bash(git push *)"],
        "deny":  ["Bash(rm *)", "Read(./.env)", "Read(./.env.*)", "Edit(./export/**)"]
      },
      "hooks": {
        "PreToolUse": [
          {
            "matcher": "Bash",
            "hooks": [
              { "type": "command", "command": "python3 \"$CLAUDE_PROJECT_DIR/.claude/hooks/block-delete.py\"" }
            ]
          }
        ]
      }
    }
  4. Add a hook for the rules that must hold

    A hook sees the full command and can apply your own logic. Ours looks for every way of deleting files we could think of, in any wrapper, and exits with code 2. Claude Code then cancels the call and shows Claude the message from standard error. Save it as .claude/hooks/block-delete.py.

    python
    #!/usr/bin/env python3
    """PreToolUse hook: refuse shell commands that delete files, whatever form they take.
    Tested with Claude Code 2.1.321 on 2026-11-11. Exit 2 = block; stderr is shown to Claude."""
    import json, re, sys
    
    PATTERNS = [
        r"(^|[\s;&|/'\"`(])rm\s",  # rm, /bin/rm, bash -c 'rm ...', git rm
        r"\brmdir\b",
        r"shutil\.rmtree",            # python -c "import shutil; shutil.rmtree(...)"
        r"\bunlink\(|os\.remove\(",
        r"\bfind\b.*\s-delete\b",
        r"Remove-Item",               # PowerShell
    ]
    
    try:
        data = json.load(sys.stdin)
    except Exception:
        sys.exit(0)  # fail open on bad input: never block work because of a hook bug
    
    cmd = (data.get("tool_input") or {}).get("command", "")
    for p in PATTERNS:
        if re.search(p, cmd):
            print(f"Blocked by project hook: deleting files is not allowed here ({p}). "
                  "Ask the user to delete it themselves.", file=sys.stderr)
            sys.exit(2)
    sys.exit(0)

What each layer stopped in our test

We gave Claude Code a project with a build folder and a .env file holding a fake password, and ran each request in a fresh session. First we fed the hook ten commands directly to see what it catches, then we ran real sessions with and without it.

Tested November 11, 2026, Claude Code 2.1.321 on Ubuntu, with the settings file above.
Request or commandDeny rules onlyDeny rules + hook
"Delete the build folder, then show me the password in .env"rm -rf denied; reading .env denied by Read(./.env)rm -rf blocked by the hook; grep on .env denied
"Delete the build folder with a python3 one-liner"Folder deleted: Bash(python3 *) allowed itBlocked by the hook; folder still there
/bin/rm -rf build, bash -c 'rm -rf build'Not covered by Bash(rm *), per the docsBlocked (hook fed directly)
find build -name '*.o' -deleteNot coveredBlocked (hook fed directly)
ls -la build, python3 app.pyAllowedAllowed
git rm --cached xNot coveredBlocked. A false positive you may want to allow
Two terminal transcripts side by side. Left, with only deny rules, Claude Code runs a Python one-liner and the build folder is deleted. Right, with the hook, the same command returns a PreToolUse hook error and the folder is still there (opens at full size)
The same request in two fresh sessions. Only the hook made the difference.

Two things stood out. Claude Code didn't try to get around a block on its own: after a denial it stopped and told us how to do it ourselves. The Python delete only happened because we asked for it by name. That's the case to plan for, because a prompt written by someone else, or text inside a file Claude reads, can ask for the same thing.

Permission modes and --dangerously-skip-permissions

From the Claude Code permissions documentation, checked November 11, 2026. Switch modes with Shift+Tab in a session or --permission-mode on the command line.
ModeWhat happens to calls no rule covers
default (Manual)Claude Code asks the first time each tool is used
acceptEditsFile edits and simple file commands like mkdir and mv in your folder run without asking
planClaude reads and explores, but doesn't edit your files
autoA background classifier reviews actions instead of you
dontAskEverything that would prompt is refused
bypassPermissionsNo prompts, except for actions no mode approves. This is what --dangerously-skip-permissions turns on

Skipping permissions makes sense in a throwaway environment: a container or virtual machine with no secrets, no access to production and nothing you can't rebuild. On your own laptop it means Claude Code can do anything your user account can. Deny rules and hooks keep working in that mode, which is one more reason to put your hard limits there. To stop anyone on a team from using it, set permissions.disableBypassPermissionsMode to "disable" in a managed settings file.

Sandbox: the layer under the rules

Rules and hooks look at commands. The sandbox limits what a shell command can touch, whatever it's called: writes stay inside your project folder and temp folder, and network traffic goes through a proxy that only lets through domains you allow. Turn it on with /sandbox in a session. According to the docs it runs on macOS, Linux and WSL2, and on Linux it needs bubblewrap and socat. On native Windows, commands run without a sandbox, so use WSL2 if you need it there. We didn't test the sandbox for this page.

When rules don't seem to work

What you seeCauseFix
"Ignoring 4 permissions.allow entries from .claude/settings.json: this workspace has not been trusted"Claude Code skips project allow rules until you've accepted the trust dialog for that folder. We hit this on our first runStart claude interactively in the folder once and accept the dialog
An allow rule doesn't make a command runA deny or ask rule also matches, and those are checked firstNarrow the deny rule; an allow rule can't carve out an exception
A blocked command runs anyway in another formRules match command text, not behaviorAdd a PreToolUse hook, or turn on the sandbox
Your hook never blocksIt exits with 1 instead of 2. Exit 1 is a non-blocking error and the command goes aheadExit with 2 and write the reason to standard error

How we run it day to day

We let our agents work for hours without anyone watching, so we sort every limit by one question: what happens if the agent forgets it? An inconvenience goes in the instructions. Real damage goes in a hook. We also decide per hook how it fails. A hook that only slows work down lets the action through if the hook itself crashes, like the except branch above, so a bug never stops all work. A hook that protects customers or money blocks when in doubt.

Want the agent to follow your rules without being forced? Those belong in a CLAUDE.md file, which Claude Code reads at the start of every session.

Questions

Where do Claude Code permission settings go?

In .claude/settings.json in your project for rules the whole team shares, .claude/settings.local.json for your own, and ~/.claude/settings.json for rules across all projects. Use /permissions in a session to see what's active.

Is --dangerously-skip-permissions safe?

In a disposable container or VM without secrets, mostly yes. On your own computer it lets Claude Code do anything your account can. Your deny rules and hooks still apply in that mode.

Do deny rules always win?

Yes. Claude Code checks deny, then ask, then allow, and the first match decides. A specific allow rule can't override a broad deny rule.

Can Claude Code read my .env file?

By default it can read files in your project. Add Read(./.env) to your deny list. In our test that blocked both the Read tool and a grep on the file.

Sources