Skip to content
zeeshare.com

writing / FDE and agents

How Claude Code works

How Claude Code worksPart 5

Permissions and safety

On this page
  1. Keys, knocks and locked doors
  2. Modes: how careful the whole visit is
  3. Three layers that work together
  4. When to give a key, and when to lock the door
  5. The Acme storefront, step by step
  6. Where this fits in the bigger picture
  7. Which one fits?
  8. Your setup so far
  9. Three rules of thumb

In short: A new colleague does not get every key on day one. Some doors open with a key (allow), some need a knock so you can say yes or no (ask), and some stay locked for everyone (deny). The mode decides what happens when no rule matches. The sandbox is the walls of the room: it limits what any command can reach, whatever the command says.

Part 4 connected your colleague to other departments. This part decides what they may touch once they are there. The project in the examples, the Acme storefront, is made up.

Claude Keys: allow Knock first: ask Locked: deny Walls: the sandbox You

Keys, knocks and locked doors

Think of it like this: On the first day you give a new colleague the key to the workshop. They knock before going into the client’s office. The safe stays locked, and nobody hands out that key.

Claude Code works the same way. Before Claude takes an action, such as running a command, editing a file or calling a tool, it checks three lists in your settings:

  • deny: the locked doors. The action is refused.
  • ask: knock first. You see the action and say yes or no.
  • allow: a key. The action runs without a question.

The order matters, and it is always the same: deny first, then ask, then allow. A locked door wins over any key, however specific the key is.

Checked first: is the door locked? (deny) Claude: read .env deny: Read(./.env) stopped, always Then: do I knock first? (ask) Claude: git push ask: Bash(git push *) you say yes or no Then: is there a key? (allow) Claude: npm test allow: Bash(npm test) runs, no question No rule matches at all Claude: curl a site no rule the mode decides Order: deny, then ask, then allow. The first match in that order decides.
A locked door wins over any key. An allow rule can never open something a deny rule has locked.

Example: With Bash(git *) in allow and Bash(git push *) in ask, git status runs at once but git push still knocks. The ask rule is checked before the allow rule.

Under the hood: how rules are written
  • A rule is a tool name, with an optional pattern in brackets: Bash(npm test *), Read(./.env), Edit(./src/**), WebFetch(domain:docs.example.com).
  • MCP tools are named mcp__<server>__<tool>, as in Part 4.
  • A bare filename such as Read(.env) matches that file at any depth under the project.
  • Read and Edit deny rules cover Claude’s own file tools and the file commands it recognises, like cat and sed. They do not cover a script that opens files by itself. For that, use the sandbox.
  • Simple read-only commands like ls, cat, grep and git diff never prompt. Add an ask or deny rule if you want one of them to.
  • Rules can live in user, project, local and managed settings. A deny at any level cannot be undone by an allow at another level. Managed settings, set by an organisation, sit above everything.

Modes: how careful the whole visit is

Think of it like this: Rules are the keys. The mode is the house rule for doors that have no key yet: ask me, look but do not touch, or go ahead.

Press Shift+Tab to move between modes, or set defaultMode in your settings so every session starts the same way.

Manual (default)

Asks the first time for each kind of action. Every door needs your nod until you hand over a key.

Plan

Looks around and reads, but does not touch your files. A walk-through before the work starts.

Accept edits

Edits files and makes folders in the project without asking. Keys to the workshop, not to the front door.

Auto

No routine prompts. A second checker reviews risky actions against what you asked for.

Don't ask

Anything that would prompt is refused. Only pre-approved keys work. Good for unattended runs.

Bypass

Skips prompts. Only inside a throwaway container or VM, never on your laptop.

Important: Bypass mode skips the prompts, including for writes to .git and .claude. Use it only in a container or VM that holds nothing you would miss.

Three layers that work together

Rules, hooks and the sandbox each catch something the others miss. Use them together.

Keys and locks · rules

Your allow, ask and deny lists. They match the name of an action, such as Bash(git push *).

Smoke alarms · hooks

A script that looks at each action before it runs and can block it with your own logic (Part 3).

Walls · the sandbox

The operating system limits which folders and websites commands can reach, whatever the command says.

Example: A deny rule Read(./.env) stops Claude from opening the file. But if Claude runs node print-config.js and that script reads .env itself, the rule never sees it. The sandbox does: the script cannot reach paths outside what the sandbox allows.

Under the hood: the sandbox and hooks
  • Run /sandbox to turn it on. It applies to shell commands and every process they start, and limits both the filesystem and the network.
  • With the sandbox on, sandboxed commands can run without a prompt, because the walls do the job the prompt was doing.
  • Paths and domains from your permission rules are merged into the sandbox settings, so WebFetch(domain:...) rules can widen or narrow where commands may connect.
  • A PreToolUse hook (Part 3) runs before the permission check and can block with exit code 2. It cannot open a door a deny rule has locked.
  • The sandbox matters most for prompt injection: even if hidden instructions fool Claude, the walls still hold.

When to give a key, and when to lock the door

Give a key when
  • The action is routine and reversible: running tests, the linter, the build.
  • You have approved it ten times this week and never said no.
  • It only reads, like git diff or a search.
Lock the door when
  • It touches secrets: .env, keys, credentials.
  • It cannot be undone: deleting data, force-pushing, dropping a table.
  • It publishes: pushing, deploying, posting, sending email. Make those ask.

The Acme storefront, step by step

Here is one project’s settings built up in order. All of it lives in .claude/settings.json, so the whole team gets the same keys.

  1. 1 · Start in plan mode for the Acme storefront

    A new colleague walks the building before they get keys. Plan mode reads and proposes; nothing changes.

    "permissions": { "defaultMode": "plan" }
  2. 2 · Lock the secret doors

    These stay shut for everyone, however a later rule is written.

    "deny": [
      "Read(./.env)",
      "Read(./.env.*)",
      "Read(./secrets/**)",
      "Bash(rm -rf *)"
    ]
  3. 3 · Knock before anything leaves the building

    Pushing and deploying always ask, even after a key for git is handed out.

    "ask": [
      "Bash(git push *)",
      "Bash(npm run deploy *)",
      "mcp__tracker__update_issue"
    ]
  4. 4 · Hand out keys for the routine work

    The commands you approve all day stop interrupting you.

    "allow": [
      "Bash(npm test *)",
      "Bash(npm run lint)",
      "Bash(npm run build)",
      "Bash(git diff *)"
    ]
  5. 5 · Add walls for shell commands

    Rules match what a command says. A script can still open files by itself, so the sandbox limits what any command can reach.

    /sandbox
  6. 6 · Commit it, keep your own keys local

    The team shares .claude/settings.json in git. Personal extras go in .claude/settings.local.json, which stays out of git.

Where this fits in the bigger picture

Think of it like this: A trusted colleague is trusted because the boundaries are clear, not because there are none.

This series is building a setup that works the way you work, on any project. Safety is what lets you hand more over. When the dangerous doors are locked and the publishing doors knock, you can give keys for everything else and stop babysitting. From Part 7 the written spec decides what gets built; these rules decide what Claude may do while building it.

Which one fits?

  • I keep approving the same safe command: Give it a keyAdd it to allow, for example Bash(npm test *). Or choose “Yes, and don't ask again” at the prompt.
  • Claude must never read a file: A deny rule, plus the sandboxRead(./.env) in deny blocks Claude's file tools and the file commands it recognises. The sandbox also blocks scripts that open the file themselves.
  • It is fine, but I want to see it first: An ask rulePut it in ask. An ask rule wins over a broader allow rule, so git push still knocks after git has a key.
  • I am starting on a codebase I do not know: Plan modeShift+Tab until it says Plan, or set defaultMode. Claude reads and proposes, you approve, then it works.
  • The rule depends on what the command does: A PreToolUse hookA script that reads the full command and blocks it with exit code 2. Deny rules still apply on top.
  • I want to skip every prompt: Only in a throwaway boxBypass mode belongs in a container or VM with nothing to lose. On your laptop, use keys for routine work instead.

Your setup so far

your setup so far · parts 1 to 5
  1. Part 1 · where it worksYou know which machine does what, and which folders Claude can reach.
  2. Part 2 · what it remembersOne task per notebook; photocopies in their own folder; helpers for noisy side jobs.
  3. Part 3 · how it behavesFridge rules for what is always true, recipe cards for procedures, alarms for musts, specialists for checks.
  4. Part 4 · what it can reachPhone lines to your tracker and tools, checked before trusted; your setup packed as one toolbox.
  5. Part 5 · what it may doKeys for routine work, a knock for anything that publishes, locked doors for secrets.
  6. NextPart 6 · context and cost

Three rules of thumb

Lock first

Write the deny list before the allow list. A locked door holds whatever keys come later.

Knock for anything that leaves

Pushes, deploys, messages and tracker writes ask. Everything that stays on your desk can have a key.

Walls for what rules cannot see

Rules read the command text. The sandbox limits what any command can actually reach.

QuizYour settings have Bash(git *) in allow and Bash(git push *) in ask. Claude wants to run git push origin main. What happens?

Show the answer

Answer: Claude Code asks you first

Rules are checked deny, then ask, then allow. The ask rule matches before the allow rule is reached, so you get a knock on the door.

Words in this post:

  • Permission rule: a line in settings that says an action is allowed, needs asking, or is denied.
  • Mode: the default behaviour for actions no rule covers. Switch with Shift+Tab.
  • Plan mode: Claude reads and proposes, but does not change your files.
  • Sandbox: limits from the operating system on what commands can read, write and connect to.
  • Prompt injection: hidden instructions in content Claude reads, trying to steer it.

Facts here were checked against the Claude Code documentation on permissions and sandboxing in November 2026. These features change often, so the docs are the final word for your version.

Next, Part 6: Context and cost is about keeping your colleague’s desk clear, so it stays sharp and does not waste effort.

Setting up Claude Code or AI agents for your team?

I help teams build this: agents, RAG search and Claude Code setups that hold up in production.

See services
Next in this seriesHow Claude Code worksContext and cost4 min read