Claude Code permissions decide what Claude may do without asking you, what it must ask about, and what it may never do. They are the first layer of Claude Code security for an agent that runs commands and edits files with your access, and the one most people set up first. This post covers how permission rules are checked, where they live, how to write them so they match what you mean, and the gap that no rule can close on its own.
What permission rules are
A permission rule names a tool and, optionally, what it applies to: Bash(npm test), Read(./.env), WebFetch(domain:docs.python.org). Each rule goes in one of three lists:
- Allow: Claude can use the tool this way without asking you
- Ask: Claude Code asks you first, every time
- Deny: Claude can't do it at all
Claude Code enforces these lists, not the model. An instruction in your prompt or in CLAUDE.md shapes what Claude tries to do, but it can't change a rule, and neither can text Claude reads in a file. Rules work alongside the permission mode: a rule decides the actions it matches, and the mode decides what happens to everything else. Manual mode asks you, auto mode hands the decision to a classifier, and dontAsk denies it.
Where rules live
Rules go in the permissions section of a settings file, and Claude Code reads four kinds of settings file:
~/.claude/settings.json: your user settings, for you in every project.claude/settings.jsonin the project: shared settings that are committed with the code, for everyone on the project.claude/settings.local.jsonin the project: your personal settings for this project- Managed settings: a policy your organization deploys, which nothing else can override
Most settings follow a precedence order, where a more specific file wins. Rule lists are the exception: Claude Code combines the rules from every file. Because deny rules are checked first, a deny in any file blocks the action even if another file allows it. If your user settings deny Bash(git push *) and the project's shared settings allow it, the push is denied.
Two practical details. When you answer a prompt with Yes, and don't ask again, Claude Code saves the rule to .claude/settings.local.json. And a project's own allow rules don't apply until you accept the trust dialog for that folder, which lists them for you to review. Read that list before you accept it: a cloned repository can bring broad allow rules with it.
To see every rule in force and the file each one comes from, run /permissions in Claude Code.
How Claude Code decides
Rules are checked in a fixed order: deny first, then ask, then allow. The first match in that order decides, and how specific a rule is doesn't change it. A deny rule like Bash(aws *) blocks aws s3 ls even if a narrower allow rule names exactly that command, and an ask rule prompts even when an allow rule also matches.
That makes the safe pattern simple. Put what must never happen in deny, what needs a human in ask, and only routine, low-risk commands in allow.
Writing a rule
For Bash, a rule without a * matches one exact command. A * matches any text, including spaces, so one rule can cover a family of commands. Put the * after the subcommand: Bash(git log *) allows only git log commands, while Bash(git *) allows every git command, including git push. The space before the * matters too: Bash(ls *) matches ls -la but not lsof, and Bash(ls*) matches both.
Claude Code understands shell operators. An allow rule for one command doesn't approve that command chained with another, such as safe-command && other-command: every part has to be allowed. Deny and ask rules work the other way and apply when any part matches.
For files, Read and Edit rules use gitignore-style patterns, and the start of the path decides where it points:
./pathorpath: relative to the current directory, such asRead(./.env)~/path: from your home folder, such asRead(~/.aws/**)//path: an absolute path, such asRead(//etc/secrets/**)/path: relative to the settings file's location, which for a project file means the project folder
The last one is a common trap. A single leading slash isn't an absolute path, and in your user settings Read(/secrets/**) points at ~/.claude/secrets, not at a folder in your project. For a user-level rule that applies in every project, use a ~/ or // path.
A starting point that keeps secrets out of reach, makes pushes a human decision, and lets routine commands run:
{
"permissions": {
"deny": [
"Read(./.env)",
"Read(./.env.*)",
"Read(~/.ssh/**)"
],
"ask": [
"Bash(git push *)"
],
"allow": [
"Bash(npm test)",
"Bash(npm run lint)"
]
}
}
What a rule can't stop
A Bash rule matches the text of the command Claude writes. It isn't a boundary around the program. A deny rule for Bash(git push *) stops git push origin main, but not the same push written as git -C . push origin main, and a rule for curl doesn't stop /usr/bin/curl or a sh -c wrapper.
Read deny rules reach further than you might expect, but not all the way. They stop Claude's file tools, and Claude Code also applies them to file commands it recognizes, such as cat, head, tail, and sed. What they can't see is a program that opens the file itself.
We tested exactly that while building our course. With Read(./.env) in deny, asking Claude to show .env was blocked, and so was asking it to run cat .env. Then we asked it to run a small Python tool from the project that loads a token from .env on its own. The project allowed Python commands, so the tool ran without a prompt and printed the token. The rule wasn't broken: the command never mentioned .env, so there was nothing for it to match.
Closing that gap takes a layer that doesn't depend on the command text. The Claude Code sandbox is enforced by the operating system, and it borrows your Read deny rules, so the same Python tool then gets "Permission denied".
Conclusion
Claude Code permissions are allow, ask, and deny rules that Claude Code enforces whatever the model decides. Deny is checked first, rules from every settings file are combined, and /permissions shows what is in force. Write Bash rules with the * after the subcommand, use ~/ or // for paths outside the project, and keep allow rules narrow. Then remember the limit: a rule matches what a command says, not what it does, so pair it with the sandbox for anything that must stay out of reach.
Relevant Training
Permission rules, auto mode, the sandbox, and managed settings are covered in Claude Code Agent Security, part of Cybrec's Claude AI training program, with hands-on tasks in an AI Lab.


0 Comments