Skip to main content

Permission Model

How Claude Code controls what the AI can and cannot do — permission modes, rules, classifiers, and the approval flow.

Permission Modes

Every session operates in one of several permission modes:

ModeBehaviorUse Case
defaultAsk user for each tool useNormal interactive use
acceptEditsAuto-approve file edits onlyTrust file changes, still ask for shell
bypassPermissionsAllow everythingFully trusted automation
dontAskAuto-approve all toolsHeadless/CI mode
planStructured planning modePlan before execute
auto (internal)Classifier-based auto-approvalSmart auto-mode with safety net

Permission Resolution Flow

🤖
Model wants to use a tool
Validate input schema
🔒
Check permission rules
Rule: allow
Rule: deny → Return denial
No matching rule
Check permission mode
default
Show approval dialog
Approved
Denied
auto
⚙️
Bash classifier
Safe → Proceed
Unsafe → Ask user
acceptEdits
Is file edit?
Yes → Proceed
No → Ask user
🔧
Pre-tool hooks
Hook vetoed — Denied
Proceed — Execute tool

Permission Rules

Rules are pattern-based matchers that pre-authorize or block specific tool uses:

Bash(git *)              # Allow all git commands
Bash(npm test) # Allow npm test specifically
FileEdit(/src/*) # Allow edits in src/
FileEdit(/node_modules/*) # (would deny edits in node_modules)
MCPTool(mcp__github__*) # Allow all GitHub MCP tools

Rule Sources

Rules come from multiple places, evaluated in order:

  1. CLI flags--allow Bash(git *), --deny FileEdit(*)
  2. User settings~/.claude/settings.json
  3. Project settings.claude.json in repo root
  4. Local settings.claude/local.json
  5. Enterprise policies — managed by org admin, cannot be overridden

Rule Precedence

Highest Priority
Enterprise Policy
Project Settings
User Settings
Local Settings
Lowest Priority
CLI Flags

Enterprise policies always win — if an admin blocks Bash(rm -rf *), no local setting can override it.

Bash Classifier

In auto mode, the Bash tool has an additional safety layer — a classifier that evaluates commands before execution:

What the Classifier Checks

  • Destructive commandsrm -rf, git reset --hard, etc.
  • Network commandscurl to unknown hosts, wget, etc.
  • Privilege escalationsudo, su, etc.
  • System modificationchmod, chown, systemctl, etc.

Classifier Decision

  • Allow — command is clearly safe (e.g., git status, ls, cat)
  • Ask — command might be risky, ask the user
  • Deny — command is clearly dangerous

User Approval Dialog

When permission mode requires approval, the REPL shows an interactive dialog:

Illustration

This mockup is a stylized explainer for the approval flow, not a pixel-accurate reproduction of the current Claude Code CLI UI.

Permission Request
Approval Required
Claude wants to run a shell command
Bash
~/claude-code-anatomy rm -rf dist/
Mode: defaultSandbox: workspace-writeRisk: destructive
This command deletes the generated build output and needs your approval before execution.
Y
Allow once
Run this command for this prompt only.
N
Deny
Block execution and return to the REPL.
A
Always allow
Persist a permission rule for future matches.

Options:

  • Allow — permit this one time
  • Deny — block this one time
  • Always allow — add a permanent permission rule

Decision Handlers

The permission system supports different decision handlers depending on context:

ContextHandlerHow It Works
Interactive REPLInteractiveShows UI dialog to user
Coordinator modeCoordinatorDelegates to coordinator worker
Swarm workerSwarmSyncs with leader via mailbox
Background taskBackgroundAuto-deny (no UI available)

How Other Frameworks Compare

Claude Code's permission model is unusually integrated: approval policy, rule sources, interactive UI, and resume behavior all live in the same runtime layer.

FrameworkApproval PrimitiveRuntime ShapeWho Resolves It
Claude CodePermission modes + rules + classifier + hooksTool gate before executionBuilt-in REPL / coordinator / SDK callback
Google ADKPer-tool require_confirmation; bash prefix policyTool asks through ToolContextHost app / tool confirmation handler
OpenAI AgentsTool approval callbacks + ToolApprovalItem interruptionsPending approvals for shell, patch, MCP, or nested agent-tool runsCaller records decision and resumes run
LangChain / LangGraphinterrupt_before checkpointsGraph pauses before selected nodesCaller inspects state and resumes the graph
Key difference

Claude Code treats permissions as a first-class runtime subsystem. The other frameworks expose approval points, but the surrounding policy engine, UI, and resume loop are usually left to the host application or graph client.

Key Source Files

FilePurpose
src/types/permissions.tsPermission type definitions
src/utils/permissions/permissions.tsCore permission resolution and approval reasons
src/utils/permissions/permissionSetup.tsRule loading and permission bootstrapping
src/hooks/toolPermission/handlers/interactiveHandler.tsInteractive approval UI handler
src/hooks/toolPermission/handlers/swarmWorkerHandler.tsWorker-side approval forwarding in swarm mode
src/entrypoints/sdk/controlSchemas.tsSDK can_use_tool approval protocol
src/hooks/useCanUseTool.tsxPermission check React hook