Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Claude Code Permission Configuration

Claude Code Permission Configuration

Claude Code uses a layered permission system to balance functionality and security, supporting fine-grained permission rules, permission modes, and sandbox policies to control what Claude can access and execute. Configuring permissions properly lets the AI complete tasks efficiently while preventing accidental damage to code or leakage of sensitive files.

Starting from Claude Code v1.1.1, the new permission configuration method is recommended. The old tools boolean configuration is still supported, but migrating to the new permission rule syntax is recommended.


Overview of the permission system

Claude Code's permission system divides operations into three categories, with different default permission policies for each type:

Tool Type Example Whether approval is needed Permanently allowed actions
Read-only operations File reads, Grep searches No Not applicable
Bash commands Shell command execution Is Permanently valid for each project directory and command
File modification Edit/Write files Is Until the session ends

Three permission actions

Each permission rule ultimately resolves to one of the following three actions:

Action effect Applicable scenarios
"allow" No approval needed, runs automatically Low-risk, high-frequency operations such as git status, npm run build
"ask" Pops up an approval prompt, and you decide whether to allow it Somewhat risky operations such as file writes and dangerous command execution
"deny" Blocked outright, neither executed nor prompted Explicitly disallowed dangerous operations such as git push, rm -rf

Rule priority: deny → ask → allow. The first matching rule wins, so deny rules always take precedence over allow and ask.


Permission modes

Permission modes control whether Claude asks the user before executing an operation. Different tasks require different levels of autonomy.

1. Six available modes

Mode Description Best suited scenarios
default Standard behavior: prompt for permission the first time each tool is used Getting started and sensitive work requiring full supervision
acceptEdits Automatically accept file edit permissions for the session, except in protected directories Iterating on code under review
plan Plan Mode: Claude can analyze but cannot modify files or execute commands Exploring the codebase, planning refactors
auto Automatically approve tool calls with background safety checks (research preview) Long-running tasks, reducing prompt fatigue
dontAsk Automatically deny tool calls unless pre-approved by permission rules Locked-down environments, CI pipelines
bypassPermissions Skip permission prompts, but writes to protected directories still prompt Only isolated containers and VMs

Protected directories note:Regardless of the mode, writes to .git、.vscode、.idea、.husky and .claude are never automatically approved, except for .claude/commands、.claude/agents and .claude/skills。

2. Switching permission modes

**Switch during the session:** press Shift+Tab to cycle through default → acceptEdits → plan → auto

Specify mode at startup:

claude --permission-mode plan

claude --permission-mode bypassPermissions

Set as the default mode (settings.json):

Example

{

 

"permissions"

:

{

   

"defaultMode"

:

"acceptEdits"

 

}

}


Permission rule syntax

1. Basic format

Permission rules follow the format Tool or Tool(specifier):

Example

{

 

"permissions"

:

{

   

"allow"

:

[

"Bash"

,

"WebFetch"

,

"Read"

]

,

   

"deny"

:

[

"Edit"

]

 

}

}

2. Matching all tool uses

Rules without a specifier match all uses of that tool:

Rule effect
Bash Match all Bash commands
WebFetch Match all network fetch requests
Read Match all file reads
Edit Match all file edits

Bash(*) is equivalent to Bash, both have the same effect.

3. Fine-grained control with specifiers

Example

{

 

"permissions"

:

{

   

"allow"

:

[

     

"Bash(npm run build)"

,

   

// Match the exact command

     

"Read(./.env)"

,

           

// Match reading the .env file in the current directory

     

"WebFetch(domain:example.com)"

 

// Match fetch requests to example.com

   

]

 

}

}

4. Wildcard patterns

Bash rules support glob patterns with * , where wildcards can appear anywhere in the command:

Example

{

 

"permissions"

:

{

   

"allow"

:

[

     

"Bash(npm run *)"

,

       

// Match npm run build, npm run test, etc.

     

"Bash(git commit *)"

,

     

// Match git commit -m "message", etc.

     

"Bash(git * main)"

,

       

// Match git checkout main, git merge main, etc.

     

"Bash(* --version)"

,

     

// Match any command with a --version argument

     

"Bash(* --help *)"

       

// Match any command with a --help argument

   

]

,

   

"deny"

:

[

     

"Bash(git push *)"

       

// Block all git push operations

   

]

 

}

}

Note the space before the wildcard:Bash(ls *) Matches ls -la but does not match lsof;Bash(ls*) matches both.


Tool-specific permission rules

1. Bash commands

Rule Matching examples
Bash(npm run build) Only npm run build
Bash(npm run test *) npm run test、npm run test --coverage
Bash(npm *) Any command starting with npm
Bash(* install) Any command ending with install
Bash(git * main) git checkout main、git merge main

Important limitation:Bash permission patterns that try to constrain command arguments can be fragile. Options before the URL, different protocols, redirects, variables, and extra spaces can all cause mismatches. It is recommended to use the WebFetch tool with domain: permissions for URL filtering.

2. Read and Edit (file operations)

File paths support several path prefix patterns:

Pattern prefix Meaning Example
//path Absolute path (from the filesystem root) Read(//Users/alice/secrets/**) Matches /Users/alice/secrets/**
~/path Home directory path Read(~/Documents/*.pdf) Matches /Users/alice/Documents/*.pdf
/path Relative to the project root Edit(/src/**/*.ts) Matches /src/**/*.ts
path or ./path Relative to the current directory Read(*.env) Matches /*.env

Example

{

 

"permissions"

:

{

   

"allow"

:

[

     

"Edit(/docs/**)"

,

         

// Allow editing files in the project's docs directory

     

"Read(~/.zshrc)"

,

       

// Allow reading the home directory's .zshrc

     

"Edit(//tmp/scratch.txt)"

,

// Allow editing temporary files at absolute paths

     

"Read(src/**)"

           

// Allow reading files in the current directory's src subdirectory

   

]

,

   

"deny"

:

[

     

"Read(*.env)"

,

           

// Block reading .env files (to prevent leaking secrets)

     

"Edit(//etc/**)"

         

// Block editing files in system directories

   

]

 

}

}

Note:Read and Edit deny rules do not apply within Bash subprocesses cat .env. To get OS-level enforcement, enable the sandbox.

3. WebFetch (network requests)

Example

{

 

"permissions"

:

{

   

"allow"

:

[

     

"WebFetch(domain:github.com)"

,

   

// Allow access to GitHub

     

"WebFetch(domain:api.example.com)"

// Allow access to internal APIs

   

]

,

   

"deny"

:

[

     

"WebFetch(domain:untrusted.com)"

 

// Block access to untrusted domains

   

]

 

}

}

4. MCP (Model Context Protocol)

Example

{

 

"permissions"

:

{

   

"allow"

:

[

     

"mcp__puppeteer"

,

                     

// Allow any tool provided by the puppeteer server

     

"mcp__puppeteer__*"

                   

// Allow all tools from the puppeteer server

   

]

,

   

"deny"

:

[

     

"mcp__puppeteer__puppeteer_navigate"

 

// Block specific tools

   

]

 

}

}

5. Agent (Sub-agent)

Example

{

 

"permissions"

:

{

   

"allow"

:

[

     

"Agent(Explore)"

,

         

// Allow use of the Explore Subagent

     

"Agent(Plan)"

             

// Allow use of the Plan Subagent

   

]

,

   

"deny"

:

[

     

"Agent(my-custom-agent)"

   

// Block custom Subagents

   

]

 

}

}


Working directory configuration

By default, Claude Code only allows access to the working directory at startup and its subdirectories. If you need to access paths outside the project directory, you must configure them explicitly.

1. Ways to extend access

Example

{

 

"additionalDirectories"

:

[

   

"~/projects/personal/**"

,

   

// Allow access to personal project directories

   

"~/projects/work/**"

,

       

// Allow access to work project directories

   

"~/dotfiles/**"

             

// Allow access to configuration file directories

 

]

}

2. Exceptions

The following remain accessible after setting additional directories, with no extra configuration:


Auto Mode

Auto Mode is a new mechanism introduced in Claude Code that replaces manual approval with a model-driven classifier, controlling risk as much as possible while ensuring efficiency.

1. Availability conditions

2. How it works

Before each operation runs, a separate classifier model reviews the conversation and decides whether the operation matches what the user requested.

Layers of defense:

  1. Server-side probes scan incoming tool results
  2. The classifier never sees tool results, preventing injected instructions from influencing decisions

Operation evaluation order:

  1. Operations matching allow or deny rules are resolved immediately
  2. Read-only operations and file edits in the working directory are auto-approved (except in protected directories)
  3. Everything else is sent to the classifier
  4. If the classifier blocks, Claude receives the reason and tries an alternative approach

3. Classifier default behavior

Operation types Behavior
Blocked by default
Downloading and executing code curl \| bash etc.
Sending sensitive data to external endpoints Data exfiltration risk
Production deployments and migrations Production environment modifications
Large-scale deletions on cloud storage Data loss risk
Granting IAM or repository permissions Privilege escalation risk
Modifying shared infrastructure Affecting other users
Irreversibly destroying files Files existing before the session started
Destructive source-control operations Force pushes, direct pushes to main
Allowed by default
Local file operations in the working directory Within safe bounds
Installing declared dependencies Dependencies already in package.json
Reading .env and sending credentials Sending to matching APIs
Read-only HTTP requests GET requests
Pushing to the startup branch Safe branch operations

4. Auto Mode configuration

Example

{

 

"autoMode"

:

{

   

"environment"

:

[

     

"Source control: github.example.com/acme-corp and all repos under it"

,

     

"Trusted cloud buckets: s3://acme-build-artifacts, gs://acme-ml-datasets"

,

     

"Trusted internal domains: *.corp.example.com, api.internal.example.com"

,

     

"Key internal services: Jenkins at ci.example.com, Artifactory at artifacts.example.com"

   

]

,

   

"allow"

:

[

     

"Deploying to the staging namespace is allowed"

,

     

"Writing to s3://acme-scratch/ is allowed"

   

]

,

   

"soft_deny"

:

[

     

"Never run database migrations outside the migrations CLI"

,

     

"Never modify files under infra/terraform/prod/: production infrastructure changes go through the review workflow"

   

]

 

}

}

5. Fallback mechanism

If the classifier blocks an operation 3 times in a row, or 20 times in total in a session, Auto Mode pauses and Claude Code reverts to prompting for each operation.

/permissions  # 在 "最近拒绝" 选项卡查看被拒绝的操作


Relationship between sandbox and permissions

The sandbox and permissions are complementary security layers that work together:

Aspect Permission Sandbox
What it controls Controls which tools Claude Code can use Restricts the filesystem and network content accessible to Bash commands
When evaluated Evaluated before any tool runs Applies only to Bash commands and their subprocesses
Scope of application All tools: Bash, Read, Edit, WebFetch, MCP, etc. Only Bash commands

1. Enabling the sandbox

/sandbox

Run /sandbox Running the command to enable the sandbox opens a menu to select a sandbox mode.

2. Configuring the sandbox

Example

{

 

"sandbox"

:

{

   

"enabled"

:

true

,

   

"filesystem"

:

{

     

"allowWrite"

:

[

"~/.kube"

,

"/tmp/build"

]

,

   

// Allow writing to these paths

     

"denyWrite"

:

[

"~/important/**"

]

,

           

// Block writing to important directories

     

"denyRead"

:

[

"~/"

]

                         

// Block reading the home directory

   

}

,

   

"network"

:

{

     

"httpProxyPort"

:

8080

,

                     

// HTTP proxy port

     

"socksProxyPort"

:

8081

                     

// SOCKS proxy port

   

}

 

}

}

Defense in depth:Permissions and the sandbox should be enabled together. Permission deny rules stop Claude from attempting to access restricted resources, while sandbox restrictions prevent Bash commands from reaching resources beyond the defined boundaries.


Extending permissions with Hooks

PreToolUse hooks run before permission prompts and can:

Example

#!/bin/bash

PreToolUse hook example: intercepting dangerous commands

COMMAND

=$

(

cat

|

jq

-r

'.tool_input.command // empty'

)

if

echo

"$COMMAND"

|

grep

-qE

'rm\s+(-[rf]+\s+)*(/|~|../)'

;

then

   

echo

"BLOCKED: rm on sensitive path"

   

exit

2

 

Exit code 2 blocks the tool call

fi

exit

0

 

Allow to continue

Important:Skipping the prompt does not bypass permission rules. Deny and ask rules are still evaluated after a hook returns "allow." When a blocking hook exits with code 2, the tool call is stopped before permission rules are evaluated.


Settings precedence

Claude Code settings take effect in the following order of precedence (highest to lowest):

  1. Managed settings - Cannot be overridden by any other level (admin-controlled)
  2. Command-Line Arguments - Temporary session override
  3. Local project settings (.claude/settings.local.json)
  4. Shared project settings (.claude/settings.json)
  5. User settings (~/.claude/settings.json)

Key rules:If a tool is denied at any level, no other level can allow it.


Practical configuration examples

Example 1: Conservative mode (all operations require approval)

Suitable for first-time Claude Code users or when working on important projects:

Example

{

 

"permissions"

:

{

   

"defaultMode"

:

"default"

 

}

}

Example 2: Common development configuration (open read operations, approve command execution)

Suitable for daily development: allow Claude to read and search code freely, but require confirmation when modifying files or executing commands:

Example

{

 

"permissions"

:

{

   

"defaultMode"

:

"acceptEdits"

,

   

"allow"

:

[

     

"Bash(git status *)"

,

     

// View git status

     

"Bash(git log *)"

,

       

// View git log

     

"Bash(git diff *)"

,

     

// View git diff

     

"Bash(npm run *)"

,

       

// Run npm scripts

     

"Bash(npm test *)"

,

       

// Run tests

     

"Bash(ls *)"

,

             

// List directories

     

"Bash(grep *)"

           

// Search content

   

]

,

   

"deny"

:

[

     

"Bash(rm *)"

,

             

// Delete files: block outright

     

"Bash(git push *)"

,

       

// Push code: block outright

     

"Bash(mkdir / *)"

,

       

// Create system directories: block outright

     

"Edit(*.env)"

             

// Block editing .env files

   

]

 

}

}

Example 3: Locked-down environment configuration (only pre-approved operations allowed)

Suitable for CI pipelines or environments requiring strict control:

Example

{

 

"permissions"

:

{

   

"defaultMode"

:

"dontAsk"

,

   

"allow"

:

[

     

"Read(*)"

,

                 

// Allow reading all files

     

"Bash(npm run build *)"

,

   

// Allow build commands

     

"Bash(npm test *)"

         

// Allow running tests

   

]

,

   

"deny"

:

[

     

"Edit(*)"

,

                 

// Block all file edits

     

"Bash(git *)"

,

             

// Block all git operations

     

"Bash(curl *)"

,

           

// Block network requests

     

"Bash(ssh *)"

             

// Block SSH connections

   

]

 

}

}

Example 4: Allowing multi-project access

When Claude needs to work across multiple project directories:

Example

{

 

"permissions"

:

{

   

"allow"

:

[

     

"Edit(/src/**)"

,

           

// Allow editing the src directory

     

"Edit(/docs/**)"

           

// Allow editing the docs directory

   

]

,

   

"deny"

:

[

     

"Edit(/docs/**/*.md)"

     

// Block editing doc files (read-only)

   

]

 

}

,

 

"additionalDirectories"

:

[

   

"~/projects/personal/**"

,

   

// Allow access to personal projects

   

"~/projects/work/**"

,

       

// Allow access to work projects

   

"~/dotfiles/**"

             

// Allow access to configuration files

 

]

}

Example 5: Using the sandbox to restrict Bash operations

Enabling the sandbox provides an extra layer of OS-level protection:

Example

{

 

"sandbox"

:

{

   

"enabled"

:

true

,

   

"filesystem"

:

{

     

"allowWrite"

:

[

"/tmp/build"

,

"~/projects/myapp/**"

]

,

     

"denyRead"

:

[

"~/secrets/**"

]

   

}

,

   

"network"

:

{

     

"httpProxyPort"

:

8080

   

}

 

}

,

 

"permissions"

:

{

   

"allow"

:

[

     

"Bash(*)"

,

                 

// Allow all commands inside the sandbox

     

"WebFetch(domain:api.github.com)"

   

]

,

   

"deny"

:

[

     

"WebFetch(domain:untrusted.com)"

   

]

 

}

}


Managed settings (admin configuration)

Administrators can deploy managed settings that cannot be overridden by user or project settings.

Settings Description
allowManagedHooksOnly Prevent loading user, project, and plugin hooks
allowManagedMcpServersOnly Only honor MCP servers from managed settings
allowManagedPermissionRulesOnly Prevent user and project settings from defining permission rules
sandbox.filesystem.allowManagedReadPathsOnly Only honor read paths from managed settings
sandbox.network.allowManagedDomainsOnly Only honor allowed domains from managed settings
permissions.disableBypassPermissionsMode Set to "disable" to prevent use of bypassPermissions mode
permissions.disableAutoMode Set to "disable" to prevent use of Auto Mode

Security best practices

  1. Start restrictive: start with minimal permissions and expand as needed
  2. Use the sandbox: the sandbox provides extra OS-level protection and should be enabled alongside
  3. Protect sensitive files: When using deny rules block access to .env, key files, etc.
  4. Restrict network access: only allow access to necessary domains to prevent data leakage
  5. Avoid bypassPermissions: use only in isolated environments (containers, VMs)
  6. Use Auto Mode's soft_deny: provides safety guidance without over-restricting
  7. Review configuration regularly: review sandbox violation attempts and denied operations

Security warning:bypassPermissions This mode does not provide protection against prompt injection or unintended actions. For a safer alternative that still maintains background safety checks, use Auto Mode.