Skip to content
Français
Sync not enabled: your progress stays in this browser My learning
Select theme
Français

Claude Code CLI: advanced settings.json and per-project permissions

27 min read
Improve this page

Logo Claude

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, allow in that order
  • The six permission modes, from plan to bypassPermissions
  • 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 /permissions to /doctor

Prerequisites

The four configuration files

Claude Code reads its configuration from four locations, ranked here from highest to lowest priority:

ScopeFileUseTracked by git
Managedmanaged-settings.json (system)Policy imposed by the companyN/A
Local.claude/settings.local.jsonPersonal preferences for the projectIgnored
Project.claude/settings.jsonRules shared by the teamTracked
User~/.claude/settings.jsonGlobal user preferencesN/A

The official documentation gives five priority levels, because command-line arguments slot in between the managed level and the local file:

  1. Managed, the strongest: "can't be overridden by anything"
  2. Command-line arguments, for the duration of a session
  3. Local, which wins over project and user
  4. Project
  5. 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 typeExampleApproval requested
Read-onlyread a file, GrepNo, within the working directories
Shell commandBashYes, except for a set of read-only commands
File modificationEdit, WriteYes

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.

Decision tree from top to bottom. Claude wants to run a command. If a deny rule matches, the command is refused. Otherwise, if an ask rule matches, Claude Code asks you. Otherwise, if an allow rule matches, the command runs without a question. If no rule matches, the permission mode decides.Claude wants to runa commandDoes a deny rulematch?Does an ask rulematch? no Denied yes Does an allow rulematch? no Claude Codeasks you yes Runs withoutasking yes The permission modedecides no rule testeddeniednext stepruns directly
Source · SVG
Esc to close, + and − to zoom, scroll to move around. 100 %

Permission modes

The defaultMode decides what Claude does when no rule matches. Six values exist.

ModeBehavior
defaultAsks for every action not covered by a rule. Shown as Manual in the interface since version 2.1.200
acceptEditsAutomatically accepts file modifications, keeps asking for the rest
planClaude reads and explores with read-only commands, without modifying your sources
autoApproves automatically, with background safety checks that verify consistency with your request
dontAskAutomatically refuses anything not pre-approved, instead of asking
bypassPermissionsSkips 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:

KeyEffect
permissions.allowPre-approved commands, no prompt
permissions.denyCommands refused when their text matches the pattern
permissions.askCommands that ask for confirmation every time
envEnvironment variables injected into every session
attributionChanges 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
cleanupPeriodDaysRetention of conversation transcripts
permissions.defaultModeDefault 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.

  1. 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 .claude
    cat > .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 *)"]
    }
    }
    EOF
    git add .claude/settings.json

    This file is committed. It is the contract of the repository, just like an .editorconfig.

  2. 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 *)"]
    }
    }
    EOF

    Created 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
  3. 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 ~/.claude
    cat > ~/.claude/settings.json <<'EOF'
    {
    "permissions": {
    "deny": [
    "Read(~/.ssh/**)",
    "Read(~/.aws/credentials)",
    "Read(~/.claude/.credentials.json)"
    ]
    }
    }
    EOF

    A deny on your secrets suits this level well: it follows you everywhere, whichever project is open.

  4. The managed level, imposed by the organization. It is deployed through fleet management tooling, at a system location that depends on the OS.

    SystemPath
    Linux and WSL/etc/claude-code/managed-settings.json
    macOS/Library/Application Support/ClaudeCode/managed-settings.json
    WindowsC:\Program Files\ClaudeCode\managed-settings.json

    This 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.

IntentCorrect patternCommon mistake
An exact commandBash(git status)
A prefix and its argumentsBash(npm run *)Bash(npm run*), which also covers npm runner
A specific fileRead(./.env)
A folder and its contentsRead(./secrets/**)Read(./secrets)
A network domainWebFetch(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 arguments
Bash(git status) -> exact command, no argument
Read(./.env) -> read of a specific file
Read(./secrets/**) -> recursive read of a folder
Edit(src/**) -> edit of a path through a pattern
WebFetch(domain:github.com) -> network access restricted to one domain

The 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:

PatternCoversDoes not cover
Bash(ls *)ls -la, and plain lslsof
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) covers git -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

  1. Move into the project

    Terminal window
    cd ~/Projets/lab-claude
  2. 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
    }
  3. Validate the JSON syntax

    Terminal window
    python3 -c "import json; json.load(open('.claude/settings.json'))" && echo "JSON valide"
  4. Start a session and check

    Terminal window
    claude

    Then, in the session:

    /permissions
  5. Confirm that .claude/settings.local.json is indeed ignored

    Terminal window
    git check-ignore .claude/settings.local.json

    If git prints the path, the file is ignored. If the command prints nothing, it is not: add .claude/settings.local.json to .gitignore.

settings.json vs settings.local.json

Two files, two distinct uses:

FileRecommended content
.claude/settings.jsonStable rules, relevant for the whole team (allow for uv run, deny for secrets)
.claude/settings.local.jsonTemporary 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.

/permissions

You 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:

CommandWhat it answers
/permissionswhich rules exist, and which file each one comes from
/statuswhich configuration sources are loaded in the session
/contextwhat fills the context window, when the behavior drifts rather than being refused
/hookswhich hooks are active, and where they come from
/mcpwhich MCP servers are connected, and their state
/doctoran 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 *) and Bash(uv run pytest *): validations repeated in every cycle, no reason to prompt
  • Bash(git status), Bash(git diff *), Bash(git log *): read-only, harmless
  • Bash(git push *) and Bash(git commit *) in ask: action visible to the team, confirmation desirable
  • Read(./.env) and Read(./secrets/**) in deny: systematic protection of secrets
  • Bash(rm -rf *) in deny: reduces the risk of an accident with a destructive command. It is not a guarantee, see the note below
  • attribution.commit and attribution.pr set 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.

SymptomLikely causeFix
Claude asks for approval again although the command is in allowpattern too restrictive: Bash(git log) allows only the exact commandadd a space and an asterisk, Bash(git log *), which also covers the bare command
A command goes through despite a denythe 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 respectedrule 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 textone 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 incorrectAdd the $schema line at the top of the file
settings.local.json shows up in git statusFile created by hand: Claude Code did not add it to git's exclusionsAdd .claude/settings.local.json to .gitignore manually
Personal permissions pushed to the repositoryRule put in settings.json instead of .local.jsonMove 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.json with $schema at the top
  • I have at least one entry in allow, deny and ask
  • 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.json is indeed ignored by git
  • My deny rules 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.json turns guardrails into a durable contract of the project
  • deny protects, allow speeds up, ask keeps 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 allow rules that concern it useless; deny and ask stay active
  • The :* form is recognized only at the end of a pattern, and wrappers like timeout are 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.json is shared, settings.local.json stays local
  • /permissions names the source file of each rule: it is the provenance tool, whereas /status lists 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 * or pytest still 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

6 questions
6 min
70% to pass

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