Claude Code: Permission Configuration

Last updated: 2026-08-31

Claude Code has high permissions — it can read/write files, execute commands, and access networks. Understanding and configuring permissions is fundamental to safe usage.

💡 Tip: By default, Claude Code auto-approves reads, confirms writes and executions. You can adjust this balance through permission configuration.

📋 Prerequisites: Chapter 10 - Context Management

1. What You'll Learn


2. Permission Model

(1) Operation Categories and Default Permissions

Operation Type Example Default Permission Notes
Read Read files, view directories Auto-allowed Read-only, no risk
Write Create/modify files Requires confirmation Configurable auto-approve
Bash Execute shell commands Requires confirmation High risk, recommend keeping confirm
Network Install packages, API calls Requires confirmation External access, security risk
MCP Call MCP tools Requires confirmation Depends on tool function

(2) Confirmation Options

TEXT 📖 Display only
Claude wants to execute: npm install lodash
  [Allow / Deny / Always for this session]

▶ Example 1: Permission Confirmation Scenarios

TEXT 📖 Display only
# Read: auto-approved
→ Reading src/index.ts ✓ (auto-approved)

# Modify: needs confirmation
→ Modifying src/index.ts
  Allow editing? [y/n/a] y

# Execute: needs confirmation
→ Running: npm test
  Allow executing: npm test? [y/n/a] a
  (Set to auto-allow for this session)

3. Auto-Approve Configuration

(1) Configure in CLAUDE.md

MARKDOWN
## Permission Configuration
- Auto-allow editing .ts and .test.ts files under src/
- Auto-allow running npm test and npm run lint
- Auto-allow running npm install (adding dependencies)
- Require confirmation: modifying prisma/schema.prisma
- Require confirmation: modifying package.json scripts
- Require confirmation: any git operations
- Deny: executing curl/wget and other network request commands

(2) Command Line Parameters

BASH
# Only allow read and write (no command execution)
claude --allowed-tools Read,Write

# Allow read, write, and specific Bash commands
claude --allowed-tools Read,Write,Bash(npm test),Bash(npm run lint)

# Fully auto mode (dangerous!)
claude --allow-full-auto

▶ Example 2: Project-Level Permission Config

MARKDOWN
<!-- Test project CLAUDE.md (relaxed permissions) -->
## Permissions
- Auto-allow: All file edits
- Auto-allow: npm test, npm run build, npm run lint
- Auto-allow: git add, git commit
- Require confirmation: npm publish, git push

<!-- Production project CLAUDE.md (strict permissions) -->
## Permissions
- Auto-allow: Read-only operations
- Require confirmation: All file modifications
- Require confirmation: All command executions
- Deny: git push, npm publish, rm -rf
- Deny: Modifying .env and config files

4. Restricted Mode

(1) Read-Only Mode

BASH
# Completely read-only, no file modifications
claude --allowed-tools Read

# Read-only + safe Bash commands
claude --allowed-tools Read,Bash(git status),Bash(npm test)

(2) Sandbox Mode

BASH
# Run in sandbox, changes don't affect real files
claude --sandbox

5. Sensitive Project Protection

(1) .claudeignore File

TEXT 📖 Display only
# .claudeignore - Exclude sensitive files
.env
.env.*
**/secrets/**
**/credentials/**
**/private-key.*
config/production.*

(2) Protection Strategy

File Type Protection Method Reason
.env .claudeignore exclude Contains secrets
secrets/ .claudeignore + confirm Credentials directory
schema.prisma CLAUDE.md mark for confirmation DB structure changes high-risk
package.json CLAUDE.md mark for confirmation Dependency changes need review

▶ Example 3: Financial Project Permission Config

MARKDOWN
## Permissions (Strict Mode)
- Auto-allow: Read-only operations
- Require confirmation: All file modifications (including src/)
- Require confirmation: All Bash commands
- Deny: Modify files under src/payment/ and src/billing/
- Deny: Run any database operation commands
- Deny: Modify Docker and CI configuration

6. Comprehensive Example: Team Permission Strategy

TEXT 📖 Display only
# Level 1: Personal experimental projects
claude --allow-full-auto (Fully auto, rapid iteration)

# Level 2: Team development projects
- CLAUDE.md configures auto-edit src/ and tests/
- Auto-run npm test
- Git operations need confirmation

# Level 3: Core business projects
- Read-only mode + manual confirm writes
- .claudeignore protects sensitive directories
- All changes go through git diff review

# Level 4: Production/Financial projects
- Read-only mode
- Output suggestions, don't directly modify
- Human review before manual application

❓ FAQ

Q Is --allow-full-auto safe?
A No. Full-auto mode does no confirmation, suited for test projects and CI. Never use in production.
Q Difference between .claudeignore and .gitignore?
A .gitignore controls git-ignored files; .claudeignore controls files Claude Code won't read. They work independently.
Q Can Claude Code bypass permission configuration?
A Normally no. But it might indirectly execute unauthorized operations via Bash commands. Protect critical data at the file system level.
Q How to revoke "Always" authorization?
A Exit the current session. "Always" only works within the current session; new sessions restore default permissions.
Q How to unify team permission configuration?
A Commit CLAUDE.md and .claudeignore to git; team members automatically share the same permission rules.

📖 Summary


📝 Exercises

  1. Basic (⭐): Configure .claudeignore to exclude .env, verify Claude Code no longer reads it.
  2. Intermediate (⭐⭐): Write permission config for your project distinguishing auto-allow vs confirm operations.
  3. Advanced (⭐⭐⭐): Design team-level permission strategy covering personal, team, and production scenarios.
Web-Tutorial.com

Web-Tutorial Tech Team

A team of developers maintaining programming tutorials. Each tutorial is written and reviewed by developers with expertise in that field. We work to keep our content accurate and reliable — if you spot an issue, please let us know.

100%

🙏 帮我们做得更好

我们是刚上线的编程教程站,几个人的小团队,精力有限。页面虽经检查,难免还有疏漏——链接失效、排版错乱、内容有误、语言生硬……

如果您发现了,麻烦告诉我们,我们会在收到反馈后第一时间进行修复,再次感谢您的光临 🙏