Claude Code permissions and settings: allow, ask, deny
Where the rules live, which one wins, and a settings file you can copy for a server.
Claude Code asks before it does anything risky: running a shell command, editing a file, fetching a URL. Every answer you give can be written down once as a rule, so the question never comes back, and the things that must never happen can be forbidden for good. This guide shows where those rules live, how they are matched, which file wins when two disagree, and a starting set for a server.
Three kinds of rule: allow, ask, deny
Rules sit under a permissions key in a settings file. Each one names a tool, optionally with a pattern in brackets:
allow: the tool call runs without a prompt.ask: Claude Code always stops and asks first.deny: the tool call is refused.
The permissions documentation states the order in which they are checked: "Rules are evaluated in order: deny, then ask, then allow. The first match in that order determines the outcome". That one sentence is the most useful fact about the whole system. A deny rule beats an allow rule, no matter which file each one came from or how specific the allow rule is. So you can keep a broad allow such as Bash(git *) and still forbid one dangerous variant with a deny rule.
A settings file to start from
Save this as .claude/settings.json in a project, or as ~/.claude/settings.json for every project of your user:
{
"permissions": {
"allow": [
"Bash(git status *)",
"Bash(git diff *)",
"Bash(npm run test *)"
],
"ask": [
"Bash(git push *)"
],
"deny": [
"Read(./.env)",
"Read(./secrets/**)",
"Bash(rm -rf *)",
"Bash(curl *)"
]
}
}
Read it from the bottom up. Reading the .env file and the secrets folder is denied, so a prompt-injected instruction cannot make Claude paste a key into its answer. Recursive deletes and raw curl are denied. A push always asks. The three read-only commands in allow never interrupt you again. Check the JSON with python3 -m json.tool .claude/settings.json before you rely on it: a file with a syntax error is not a file with strict rules.
How a Bash pattern is matched
A pattern after the tool name is matched against the command. The space-star form Bash(npm run test *) matches the command followed by any arguments. The older colon form Bash(ls:*) means the same as Bash(ls *) in the docs, and you will meet both in examples online. For files, Read(./.env) names one file and Read(./secrets/**) a whole tree.
Be modest about what pattern rules can do. A command can be written many ways, chained with &&, wrapped in bash -c or hidden in a script, and a pattern only sees the text. Treat deny rules as a first fence that catches the common mistakes. For the commands that must never run, add a PreToolUse hook that reads the actual command, as the hooks guide on this site does.
Which file wins
Settings come from several places and are merged. The settings documentation lists, from the top:
- Managed settings: set by an administrator for the machine. The docs say "Nothing in your own settings files or --settings overrides a managed key".
- Command line: JSON you pass with
--settings <file-or-json>when you startclaude, for that session only. - Project local:
.claude/settings.local.json, "your personal settings for this project". Keep it out of git. - Project shared:
.claude/settings.json, committed for the whole team. - User:
~/.claude/settings.json, your defaults everywhere.
Because deny is checked before allow, a deny rule in the shared project file is not undone by an allow rule in your own user file. A rule you want everyone to keep belongs in .claude/settings.json. A personal convenience belongs in .claude/settings.local.json.
To test a setup on its own, start Claude Code with --setting-sources and a comma-separated list from user, project and local. That loads only those sources, so you can see what the project file does without your user defaults.
Rules on the command line
For a one-off or scheduled run you do not need a file. --allowedTools and --disallowedTools take a list of the same rules, for example --allowedTools "Bash(git *) Edit" and --disallowedTools "Bash(rm -rf *)". This suits claude -p in a cron job, where nobody is there to answer a prompt.
Permission modes
A mode sets the default behaviour for everything your rules do not cover. In Claude Code 2.1.328, claude --help lists these values for --permission-mode: manual, acceptEdits, plan, auto, dontAsk and bypassPermissions. In short, plan lets Claude read and propose but not change anything, and acceptEdits stops asking about file edits. bypassPermissions switches the prompts off. Use it only in a throwaway container with no secrets and no network you care about, never on a machine that holds real data. Even there, add deny rules and a hook first.
claude -p "run the tests and summarise failures" \
--permission-mode plan \
--disallowedTools "Bash(rm -rf *)" \
--max-budget-usd 2
Common mistakes
- Trusting a deny rule to stop a determined command. It stops the plain form. A hook that parses the command stops far more.
- Putting a secret deny only in your user file. A teammate or a CI job that loads only the project file does not get it. Commit the deny rules for
.envand key folders to.claude/settings.json. - Allowing a whole interpreter.
Bash(python *)orBash(bash *)allows anything a script can do. Allow the narrow commands you actually need. - Never reviewing the allow list. Every "always allow" click adds a rule. Open the file once a month and remove what you no longer need.
A short checklist
- Deny
.env, key folders and destructive commands in the committed project file. - Allow only narrow, read-only commands without a prompt; make pushes and deploys
ask. - Remember the order: deny, then ask, then allow.
- Use
settings.local.jsonfor personal rules and keep it out of git. - Back the fence with a
PreToolUsehook for commands that must never run. - For unattended runs, pass
--disallowedToolsand--max-budget-usdexplicitly.