After the beginner series, your sessions are framed but every project keeps asking for the same approvals. This guide sets up a durable configuration through settings.json: you lock down sensitive permissions, pre-approve repetitive commands and share a common base with your team. Everything is applied on lab-claude and checked with /permissions, the command that tells you which file each rule comes from.
What you will learn
- The four files of configuration and the five levels of priority
- How Claude Code decides: tool type, then
deny,ask,allowin that order - The six permission modes, from
plantobypassPermissions - Setting up each level concretely, from the project file to the managed settings
- Writing a correct rule on the first try: tool, scope, list, pattern form
- Diagnosing a rule that does not apply, from
/permissionsto/doctor
Prerequisites
Claude Code CLIinstalled and working- The running project ready:
~/Projets/lab-claude - Conventions set in
CLAUDE.md(see configure CLAUDE.md (in French)) - Comfortable with the execution modes (see plan mode, diff and validations (in French))
The four configuration files
Claude Code reads its configuration from four locations, ranked here from highest to lowest priority:
| Scope | File | Use | Tracked by git |
|---|---|---|---|
| Managed | managed-settings.json (system) | Policy imposed by the company | N/A |
| Local | .claude/settings.local.json | Personal preferences for the project | Ignored |
| Project | .claude/settings.json | Rules shared by the team | Tracked |
| User | ~/.claude/settings.json | Global user preferences | N/A |
The official documentation gives five priority levels, because command-line arguments slot in between the managed level and the local file:
- Managed, the strongest: "can't be overridden by anything"
- Command-line arguments, for the duration of a session
- Local, which wins over project and user
- Project
- User, which applies when nothing else defines the setting
Permissions are an exception to this hierarchy. They do not overwrite each other, they merge: "Permission rules behave differently because they merge across scopes rather than override". A rule from the user file therefore coexists with those of the project instead of being replaced. This explains why a permissions file only ever grows over time, a topic covered in securing your settings.json (in French).
How does Claude Code decide to run a command?
Before writing a single rule, you need to understand what happens when Claude wants to run something. Many failed configurations come from a wrong mental picture of this cycle, not from a syntax error.
First step, the tool type. Not all tools are subject to the same regime, and mixing them up muddles everything that follows.
| Tool type | Example | Approval requested |
|---|---|---|
| Read-only | read a file, Grep | No, within the working directories |
| Shell command | Bash | Yes, except for a set of read-only commands |
| File modification | Edit, Write | Yes |
Second step, rule evaluation. It follows a strict order, and the documentation insists on a counter-intuitive point: "Rules are evaluated in order: deny, then ask, then allow. The first match in that order determines the outcome, and rule specificity doesn't change the order".
In other words, a broad deny always beats a precise allow. A Bash(aws *)
rule in deny blocks Bash(aws s3 ls) even if the latter is explicitly listed
in allow. A deny list therefore cannot carry exceptions: there is no way
to say "all of aws except aws s3 ls".
The same principle holds between ask and allow: a matching ask rule
triggers the question, even if a more specific allow also matches.
Third step, the permission mode, which decides what happens when no rule matches.
The following diagram summarizes the last two steps. Read it from top to bottom: each diamond is a list of rules, tested in the order deny, ask, allow. A "yes" exits to the right and concludes: refusal, question or execution. A "no" goes down to the next diamond. Only the last "no" leads to the permission mode, which decides when no rule matches.
Permission modes
The defaultMode decides what Claude does when no rule matches.
Six values exist.
| Mode | Behavior |
|---|---|
default | Asks for every action not covered by a rule. Shown as Manual in the interface since version 2.1.200 |
acceptEdits | Automatically accepts file modifications, keeps asking for the rest |
plan | Claude reads and explores with read-only commands, without modifying your sources |
auto | Approves automatically, with background safety checks that verify consistency with your request |
dontAsk | Automatically refuses anything not pre-approved, instead of asking |
bypassPermissions | Skips the prompts, except for actions that no mode approves automatically |
The last two are symmetrical extremes and deserve a careful reading. dontAsk
tightens: whatever is not planned for is refused, without interruption.
bypassPermissions opens up, and the documentation attaches a clear warning to
it.
The basic structure of a settings.json
Always start with $schema to enable autocompletion and validation in your editor.
{ "$schema": "https://json.schemastore.org/claude-code-settings.json", "permissions": { "allow": [], "deny": [], "ask": [] }, "env": {}, "attribution": { "commit": "", "pr": "" }, "cleanupPeriodDays": 30}The most useful keys day to day:
| Key | Effect |
|---|---|
permissions.allow | Pre-approved commands, no prompt |
permissions.deny | Commands refused when their text matches the pattern |
permissions.ask | Commands that ask for confirmation every time |
env | Environment variables injected into every session |
attribution | Changes or hides the Co-Authored-By line of commits (commit) and the text of pull requests (pr); an empty string hides it. Replaces includeCoAuthoredBy, deprecated since Claude Code 2.0.62 |
cleanupPeriodDays | Retention of conversation transcripts |
permissions.defaultMode | Default permission mode (default, acceptEdits, plan, auto, dontAsk, bypassPermissions, described above). It goes under permissions, not at the root. auto and bypassPermissions have no effect from the project files or the local file (documentation) |
Setting up each level in practice
The four files do not share the same location, the same way of being created or the same fate with git. Here is how to set up each one, in the order in which you need them.
-
The project level, shared by the team. It is the one you create first, because it carries the rules that apply to everyone.
Terminal window mkdir -p .claudecat > .claude/settings.json <<'EOF'{"$schema": "https://json.schemastore.org/claude-code-settings.json","permissions": {"allow": ["Bash(npm run lint *)", "Bash(npm test *)"],"ask": ["Bash(git push *)"],"deny": ["Read(./.env)", "Bash(rm -rf *)"]}}EOFgit add .claude/settings.jsonThis file is committed. It is the contract of the repository, just like an
.editorconfig. -
The local level, personal to the repository. It holds what depends on your machine and has no place in the shared repository.
Terminal window cat > .claude/settings.local.json <<'EOF'{"permissions": {"allow": ["Bash(podman *)"]}}EOFCreated by Claude Code, this file is automatically added to git's global exclude file. Created by hand, as above, it is not: check it, otherwise your personal rules will go to the repository.
Terminal window git check-ignore -v .claude/settings.local.json -
The user level, valid for all your projects. It is the place for rules that have nothing to do with a particular repository.
Terminal window mkdir -p ~/.claudecat > ~/.claude/settings.json <<'EOF'{"permissions": {"deny": ["Read(~/.ssh/**)","Read(~/.aws/credentials)","Read(~/.claude/.credentials.json)"]}}EOFA
denyon your secrets suits this level well: it follows you everywhere, whichever project is open. -
The managed level, imposed by the organization. It is deployed through fleet management tooling, at a system location that depends on the OS.
System Path Linux and WSL /etc/claude-code/managed-settings.jsonmacOS /Library/Application Support/ClaudeCode/managed-settings.jsonWindows C:\Program Files\ClaudeCode\managed-settings.jsonThis level cannot be bypassed. It also carries the policy locks, such as
disableBypassPermissionsMode, which forbids the most permissive mode.
Creating a rule: the method
A misplaced or malformed rule produces no error, it simply has no effect. Four questions let you set one up correctly on the first try.
Which tool? The name before the parenthesis must be that of the tool
actually used: Bash for a shell command, Read for a read,
Edit and Write for a modification, WebFetch for a network request.
Writing Bash(...) to protect a file protects nothing.
Which scope? A stable command useful to the whole team goes in the project file. A command tied to your workstation goes in the local file. A protection for your secrets goes in the user file.
Which list? deny for what must never get through, ask for what
must stay under your eye, allow for what is repetitive and harmless.
Reminder of the cycle: deny always wins, however precise the allow rule
facing it.
Which pattern form? A well-placed rule fails silently if its pattern is badly written.
| Intent | Correct pattern | Common mistake |
|---|---|---|
| An exact command | Bash(git status) | |
| A prefix and its arguments | Bash(npm run *) | Bash(npm run*), which also covers npm runner |
| A specific file | Read(./.env) | |
| A folder and its contents | Read(./secrets/**) | Read(./secrets) |
| A network domain | WebFetch(domain:github.com) | WebFetch(github.com) |
Once the rule is written, check that it is actually active rather than
assuming it: the /permissions command lists the rules and the file each one
comes from. The section "How do you find where an applied rule comes from?",
further down, details how to use it.
Permission rule syntax
The rules use a simple Tool(pattern) syntax:
Bash(uv run ruff check *) -> prefix "uv run ruff check" + any argumentsBash(git status) -> exact command, no argumentRead(./.env) -> read of a specific fileRead(./secrets/**) -> recursive read of a folderEdit(src/**) -> edit of a path through a patternWebFetch(domain:github.com) -> network access restricted to one domainThe space before the asterisk, not the colon
The two forms are equivalent, and the documentation says so without
ambiguity: Bash(uv run:*) and Bash(uv run *) cover exactly the same
commands. Contrary to what you often read, neither is "the right one": it is
the form with a space that the permission dialog writes to your file when
you answer "don't ask again", so it is the one you will see in practice.
What really matters is the space. It is part of the pattern:
| Pattern | Covers | Does not cover |
|---|---|---|
Bash(ls *) | ls -la, and plain ls | lsof |
Bash(ls*) | ls -la, and lsof |
A trailing asterisk preceded by a space also covers the bare command:
Bash(git log *) allows git log. Without the space, the pattern spills over
onto everything that starts with the same letters, which is rarely the intent.
Two clarifications that save hours of searching:
- The colon is only recognized at the end of a pattern. In
Bash(git:* push), it is treated as a literal character and will match no git command. - A
*in the middle replaces any text, including dangerous options.Bash(git * main)coversgit -c core.fsmonitor=<script> diff main, therefore an arbitrary program execution.
A bare tool name opens everything
This is a trap you cannot see and that costs dearly. A rule reduced to the
tool name, without parentheses, allows that tool in full. The
documentation states it as a recipe: "To run all Bash commands without
prompts except for a few you want blocked, add "Bash" to your allow list".
{ "permissions": { "allow": ["Bash"] }}This single line makes useless all the detailed allow rules Bash(...)
in the file, however precise they are: they add nothing as soon as a bare Bash
has been added. The deny and ask rules still apply, since they are read
before allow.
The same effect holds for Read, Edit, Write, Glob, Grep, and for a
whole MCP server such as mcp__github, which covers all its tools.
Two matching subtleties
Claude Code removes a fixed set of wrappers (prefixes that launch another command) before comparing:
timeout, time, nice, nohup, stdbuf, the built-in commands command and
builtin, and zsh's noglob. A Bash(npm test *) rule therefore also covers
timeout 30 npm test, and a deny cannot be bypassed by prefixing the command.
On symbolic links, the handling is deliberately asymmetric:
an allow rule applies only if both the link and its target match,
whereas a deny rule applies as soon as either one matches.
A rule reads the text of the command, not its intent
To forbid an action, it is not enough to name the command: you have to cover every form in which the text can appear. Take Git's forced push. A deny rule on Bash(git push --force) refuses only that exact text. It lets through git push --force origin main, git push origin main --force and git push -f, which do the same thing.
The flag can sit in several places, and it has several spellings (--force, -f, --force-with-lease). Each combination needs its own rule, which is why a deny is written as a list:
{ "permissions": { "deny": [ "Bash(git push --force *)", "Bash(git push * --force)" ] }}These two lines show the principle, not the complete list: it is up to you to count the spellings of the flag (-f, --force-with-lease) and their places. The opposite trap exists too. Since * replaces any text, a rule that looks for -f anywhere in the command also refuses a git push origin feature/price-format, because the branch name contains -f. A deny that is too broad blocks legitimate work, a deny that is too narrow lets the accident through.
The same reasoning applies to files. Read(./secrets/*) covers only the files directly in secrets/, whereas Read(./secrets/**) also goes through the subfolders, such as secrets/prod/database.ini.
For a risky action that you want to keep possible but never silent, combine the lists. Keep the team's allow (Bash(git push origin feature/*)), then add a broader ask (Bash(git push *)). The deny, ask, allow order means the ask is read before the allow: Claude always asks, even on a feature/* branch. A project's deny rules protect that project only, and a contributor can modify them. For a ban that holds across the whole machine, for example curl, wget or reading secrets/, put it in the managed file: no project can get around it, even by adding an allow for the same command.
Applying it on lab-claude
-
Move into the project
Terminal window cd ~/Projets/lab-claude -
Create the shared
.claude/settings.json{"$schema": "https://json.schemastore.org/claude-code-settings.json","permissions": {"allow": ["Bash(uv run ruff check *)","Bash(uv run ruff format *)","Bash(uv run pytest *)","Bash(uv add *)","Bash(uv sync *)","Bash(git status)","Bash(git diff *)","Bash(git log *)"],"deny": ["Bash(rm -rf *)","Bash(curl *)","Bash(wget *)","Read(./.env)","Read(./.env.*)","Read(./secrets/**)"],"ask": ["Bash(git push *)","Bash(git commit *)"]},"env": {"PYTHONDONTWRITEBYTECODE": "1"},"attribution": {"commit": "","pr": ""},"cleanupPeriodDays": 30} -
Validate the JSON syntax
Terminal window python3 -c "import json; json.load(open('.claude/settings.json'))" && echo "JSON valide" -
Start a session and check
Terminal window claudeThen, in the session:
/permissions -
Confirm that
.claude/settings.local.jsonis indeed ignoredTerminal window git check-ignore .claude/settings.local.jsonIf git prints the path, the file is ignored. If the command prints nothing, it is not: add
.claude/settings.local.jsonto.gitignore.
settings.json vs settings.local.json
Two files, two distinct uses:
| File | Recommended content |
|---|---|
.claude/settings.json | Stable rules, relevant for the whole team (allow for uv run, deny for secrets) |
.claude/settings.local.json | Temporary personal preferences (preferred model, allow specific to your machine) |
Simple rule: if another developer can replay your configuration without trouble, it belongs in settings.json. If it depends on your machine or your account, it belongs in settings.local.json.
How do you find where an applied rule comes from?
The command to remember is /permissions. It lists all the permission rules
and, for each one, the settings.json file it comes from.
This is exactly what you need when an approval seems granted or
refused for no apparent reason, since permissions merge across
scopes instead of overwriting each other.
/permissionsYou can open it while Claude is working: a rule added or removed applies from the next tool call, within the same turn.
The other commands answer other questions, and mixing them up wastes time. Here is the order in which to chain them when something does not behave as expected:
| Command | What it answers |
|---|---|
/permissions | which rules exist, and which file each one comes from |
/status | which configuration sources are loaded in the session |
/context | what fills the context window, when the behavior drifts rather than being refused |
/hooks | which hooks are active, and where they come from |
/mcp | which MCP servers are connected, and their state |
/doctor | an installation diagnostic when nothing above explains the symptom |
Commented example for lab-claude
Why these rules are in the shared settings.json:
Bash(uv run ruff check *)andBash(uv run pytest *): validations repeated in every cycle, no reason to promptBash(git status),Bash(git diff *),Bash(git log *): read-only, harmlessBash(git push *)andBash(git commit *)inask: action visible to the team, confirmation desirableRead(./.env)andRead(./secrets/**)indeny: systematic protection of secretsBash(rm -rf *)indeny: reduces the risk of an accident with a destructive command. It is not a guarantee, see the note belowattribution.commitandattribution.prset to"": the default attribution can get in the way in some review workflows
Common mistakes
Symptoms about rules look alike, but they fall into three
families. Either the rule is in the wrong place, and /permissions says so
by naming its source file. Or its syntax does not match what
you believe, usually a missing space before the asterisk or only one form
of the forbidden action. Or a broader rule makes it ineffective, as with the
bare tool name seen above. The middle column tells you which one. The last three
rows concern the editor and git.
| Symptom | Likely cause | Fix |
|---|---|---|
Claude asks for approval again although the command is in allow | pattern too restrictive: Bash(git log) allows only the exact command | add a space and an asterisk, Bash(git log *), which also covers the bare command |
A command goes through despite a deny | the rule targets the text, not the program: /usr/bin/curl escapes Bash(curl *) | restrict the allow list, and for a real boundary, use a sandbox or a PreToolUse hook |
deny not respected | rule placed in a scope that does not apply | /permissions names the source file of each rule |
git push origin main --force goes through despite Bash(git push --force) | the rule targets only that exact text | one rule per flag position: Bash(git push --force *) and Bash(git push * --force), then the other spellings (-f) |
| Editor does not autocomplete the JSON | $schema missing or incorrect | Add the $schema line at the top of the file |
settings.local.json shows up in git status | File created by hand: Claude Code did not add it to git's exclusions | Add .claude/settings.local.json to .gitignore manually |
| Personal permissions pushed to the repository | Rule put in settings.json instead of .local.json | Move the rule to the local file |
End-of-guide checklist
A configuration is checked on the effective result, not on what the file seems to say. The last three points cover the causes of an ineffective rule: a forgotten form of the action, a bare tool name, a missing space.
- I identified the four configuration files and their order of priority
- I created
.claude/settings.jsonwith$schemaat the top - I have at least one entry in
allow,denyandask - I validated the JSON syntax of the file
- I checked where each rule comes from with
/permissions - I know where to put a personal rule (
settings.local.json) versus a team rule (settings.json) -
.claude/settings.local.jsonis indeed ignored by git - My
denyrules cover every form of the forbidden action (flag position and spelling) - No bare rule (
Bash,Read,Edit) makes my detailed rules useless - My prefixes use
Bash(command *), with a space before the asterisk
Put it into practice
The lab starts from an incident: a repository's coding agent did a forced push on main, because the project allows Bash(git *) and its only deny rule matches just one exact text. You write the team's policy, at project level, then the security team's, at managed level. At project level, you refuse every form of forced push without removing the team's allow rules, and you make any other push ask. At managed level, you refuse curl, wget and the secrets/ folder, even when the project allows them.
The validation has a simulated, offline agent read your merged rules, and it is not Claude Code. It says what the rules decide for actions that only it knows: other forms of forced push, other pushes, other reads of secrets/. The lab therefore proves the reading of the rules, not their effect in a real session: for that, open /permissions in a real session.
Key takeaways
settings.jsonturns guardrails into a durable contract of the projectdenyprotects,allowspeeds up,askkeeps control over visible actions- Permissions merge across scopes instead of overwriting each other, unlike the other settings
- A bare tool name opens the whole tool and makes the detailed
allowrules that concern it useless;denyandaskstay active - The
:*form is recognized only at the end of a pattern, and wrappers liketimeoutare removed before comparison - A rule reads the text of the command: list every form of the forbidden action, and put at managed level what must hold across the whole machine
settings.jsonis shared,settings.local.jsonstays local/permissionsnames the source file of each rule: it is the provenance tool, whereas/statuslists the configuration sources loaded- A Bash rule is not a security boundary: it prevents the accident, it does not resist a workaround. Protection comes from the precision of the
allow, which does not close everything:uv run *orpyteststill run arbitrary code
Knowledge check
Check that the essentials of this guide are mastered. The questions cover only what has just been explained here.
Knowledge check
Check what you have learned with this interactive quiz
How it works
- The timer starts when you click Start
- Multiple choice, true/false and short answer questions
- You can move between questions
- Detailed results are shown at the end
Starts the quiz and the timer
Review
(0/0)Result saved on this device. It will be sent to your account at the next sync. Sync now
Score by domain
A domain groups several guides and gets several questions, so its score is more reliable than a per-topic score, which often rests on a single question.
Summary
Strengths
No topic passed at 80% on at least two questions yet.
Weak areas
No topic below the pass mark.
Recommended next
Hints before you try again?
A new full quiz with random questions
Work again only on the questions you missed