Skip to main content
Permission modes control how the SDK handles tool execution approval. They provide different levels of control over which operations the AI can perform automatically.

Permission Modes Overview

The SDK supports four built-in permission modes:

Default Mode

The safest interactive mode. Write operations require explicit approval.

Behavior

  • Read-only tools: Execute automatically (e.g., read_file, list_directory)
  • Write tools: Denied unless approved via canUseTool callback or in allowedTools
  • Shell commands: Require approval

Example

Without canUseTool

If no canUseTool callback is provided, write tools are automatically denied:

Plan Mode

Blocks all write operations. The AI explains what it would do instead of executing.

Behavior

  • Read-only tools: Execute normally
  • Write tools: Blocked (AI instructed to present a plan)
  • Special: exit_plan_mode tool allowed (if available)

Example

Use Cases

  • Getting implementation plans before execution
  • Code review and suggestions
  • Architecture analysis
  • Exploration without modification

Auto-Edit Mode

Auto-approves file editing operations while requiring confirmation for other tools.

Behavior

  • Edit tools (edit, write_file): Execute automatically
  • Other write tools: Require approval via canUseTool or allowedTools
  • Read-only tools: Execute automatically

Example

With Additional Approvals

Use Cases

  • Code refactoring assistants
  • Automated fix tools
  • Documentation generators
  • Bulk code updates

YOLO Mode

Auto-approves all tools without confirmation. Use with extreme caution.

Behavior

  • All tools: Execute automatically
  • No callbacks: canUseTool is never called
  • No restrictions: Except tools in excludeTools
YOLO mode grants the AI full access to file system operations and shell commands. Only use in trusted, isolated environments.

Example

Safe YOLO with Exclusions

Combine with excludeTools to prevent dangerous operations:

Use Cases

  • Automated CI/CD pipelines in isolated environments
  • Batch processing scripts
  • Development environment setup
  • Testing and experimentation in sandboxes

Permission Priority Chain

Understanding the order of permission checks:

Example with Multiple Controls

Custom Permission Handler

The canUseTool callback provides fine-grained control over tool execution.

Signature

Parameters

toolName
string
required
Name of the tool requesting permission.
input
Record<string, unknown>
required
Input parameters for the tool.
options.signal
AbortSignal
required
Signal for cancelling the permission request.
options.suggestions
PermissionSuggestion[] | null
Suggested actions from the CLI (if available).

Return Value

behavior
'allow' | 'deny'
required
Whether to allow or deny the tool execution.
updatedInput
Record<string, unknown>
Modified input parameters (only for 'allow'). Return the original input if no modifications needed.
message
string
Explanation for denial (only for 'deny').
interrupt
boolean
Whether to interrupt the entire session on denial (only for 'deny').

Examples

Allow with Modified Input

Deny with Interrupt

Path-Based Approval

Interactive Approval

Allowed and Excluded Tools

allowedTools

Auto-approve specific tools without calling canUseTool. Pattern matching:
  • Tool name: 'write_file', 'run_shell_command'
  • Tool class: 'WriteTool', 'ShellTool'
  • Shell command prefix: 'ShellTool(git status)'

excludeTools

Block specific tools completely (highest priority).

Timeout Configuration

The canUseTool callback must respond within a timeout period (default: 60 seconds).
If the timeout is exceeded, the tool request is automatically denied with a timeout error.

Best Practices

1. Start with Default Mode

Use default mode with a custom canUseTool handler for most applications:

2. Use Plan Mode for Analysis

When you want suggestions without execution:

3. Combine Modes with Tool Lists

Use allowedTools and excludeTools to fine-tune any mode:

4. Validate Tool Input

Always validate and sanitize tool inputs:

5. Log Permission Decisions

Log all permission decisions for audit trails:

See Also