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
canUseToolcallback or inallowedTools - Shell commands: Require approval
Example
Without canUseTool
If nocanUseTool 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_modetool 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
canUseToolorallowedTools - 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:
canUseToolis never called - No restrictions: Except tools in
excludeTools
Example
Safe YOLO with Exclusions
Combine withexcludeTools 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
ThecanUseTool callback provides fine-grained control over tool execution.
Signature
Parameters
Name of the tool requesting permission.
Input parameters for the tool.
Signal for cancelling the permission request.
Suggested actions from the CLI (if available).
Return Value
Whether to allow or deny the tool execution.
Modified input parameters (only for
'allow'). Return the original input if no modifications needed.Explanation for denial (only for
'deny').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 callingcanUseTool.
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
ThecanUseTool callback must respond within a timeout period (default: 60 seconds).
Best Practices
1. Start with Default Mode
Usedefault 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
UseallowedTools 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
- query() Function - Main API documentation
- Custom Permissions Example - Detailed permission handler examples
- Query Instance Methods - Control permission mode during execution
