Skip to main content

Permission Model & Security

Claude Code's security design centers on one principle: every tool invocation must pass a permission check. The permission system is multi-layered -- from static rules to runtime approval to sandbox isolation.

Permission Modes

ModeDescriptionTypical Use
defaultDangerous operations require user approvalNormal interactive use
planRead-only mode, write operations deniedPlanning phase
acceptEditsAuto-allow file edits, other dangerous ops still need approvalTrusted file operations
bypassPermissionsSkip most permission checksFull trust (CI, etc.)
dontAskNo approval dialogs, auto-deny pending promptsBackground agents

Rule System

Rules come in three types: allow (always permit), deny (always reject), ask (require user approval). Rules are sourced from multiple origins with priority: userSettings < projectSettings < localSettings < flagSettings < policySettings < cliArg < session.

Permission Decision Flow

Even in bypassPermissions mode, certain checks remain ("bypass-immune"): directory boundary checks, network security checks.

Sandbox

Claude Code integrates @anthropic-ai/sandbox-runtime for Bash command isolation. SandboxManager (src/utils/sandbox/sandbox-adapter.ts) handles filesystem read/write/network rules. When sandboxing is enabled and "auto-allow bash if sandboxed" is on, sandboxed Bash commands skip permission prompts.

Interactive Approval

When a tool needs approval, the request is pushed to a permission queue in REPL. Components in src/components/permissions/ render tool-specific dialogs (Bash, FileWrite, FileEdit, etc.). In swarm scenarios, teammates send permission requests via file mailbox to the leader.

Key Source Files

FileResponsibility
src/types/permissions.tsPermissionMode, rule type definitions
src/utils/permissions/permissions.tshasPermissionsToUseTool core logic
src/utils/sandbox/sandbox-adapter.tsSandboxManager
src/hooks/useCanUseTool.tsxCanUseToolFn hook
src/components/permissions/Permission approval UI components
src/utils/auth.tsAuthentication management

Next

Go to 06-context-prompt.md to learn how the system prompt is assembled.

Hands-on Experiment

This chapter has a corresponding Python experiment:

Lab 05 — Permission Engine

Covers: permission modes, rule priority, decision engine

cd experiments && python -m exp_05_permission_engine.main --mock