pub struct ToolPermissionRequest {
pub tool_name: String,
pub input: Value,
pub permission_suggestions: Vec<Value>,
pub blocked_path: Option<String>,
}Expand description
Tool permission request details
This is sent when Claude wants to use a tool. The SDK should evaluate the request and respond with allow/deny using the ergonomic builder methods.
§Example
use claude_codes::{ToolPermissionRequest, ControlResponse};
use serde_json::json;
fn handle_permission(req: &ToolPermissionRequest, request_id: &str) -> ControlResponse {
// Block dangerous bash commands
if req.tool_name == "Bash" {
if let Some(cmd) = req.input.get("command").and_then(|v| v.as_str()) {
if cmd.contains("rm -rf") {
return req.deny("Dangerous command blocked", request_id);
}
}
}
// Allow everything else
req.allow(request_id)
}Fields§
§tool_name: StringName of the tool Claude wants to use (e.g., “Bash”, “Write”, “Read”)
input: ValueInput parameters for the tool
permission_suggestions: Vec<Value>Suggested permissions (if any)
blocked_path: Option<String>Path that was blocked (if this is a retry after path-based denial)
Implementations§
Source§impl ToolPermissionRequest
impl ToolPermissionRequest
Sourcepub fn allow(&self, request_id: &str) -> ControlResponse
pub fn allow(&self, request_id: &str) -> ControlResponse
Allow the tool to execute with its original input.
§Example
let req = ToolPermissionRequest {
tool_name: "Read".to_string(),
input: json!({"file_path": "/tmp/test.txt"}),
permission_suggestions: vec![],
blocked_path: None,
};
let response = req.allow("req-123");Sourcepub fn allow_with(
&self,
modified_input: Value,
request_id: &str,
) -> ControlResponse
pub fn allow_with( &self, modified_input: Value, request_id: &str, ) -> ControlResponse
Allow the tool to execute with modified input.
Use this to sanitize or redirect tool inputs. For example, redirecting file writes to a safe directory.
§Example
let req = ToolPermissionRequest {
tool_name: "Write".to_string(),
input: json!({"file_path": "/etc/passwd", "content": "test"}),
permission_suggestions: vec![],
blocked_path: None,
};
// Redirect to safe location
let safe_input = json!({"file_path": "/tmp/safe/passwd", "content": "test"});
let response = req.allow_with(safe_input, "req-123");Sourcepub fn allow_with_permissions(
&self,
modified_input: Value,
permissions: Vec<Value>,
request_id: &str,
) -> ControlResponse
pub fn allow_with_permissions( &self, modified_input: Value, permissions: Vec<Value>, request_id: &str, ) -> ControlResponse
Allow with updated permissions list.
Sourcepub fn deny(
&self,
message: impl Into<String>,
request_id: &str,
) -> ControlResponse
pub fn deny( &self, message: impl Into<String>, request_id: &str, ) -> ControlResponse
Deny the tool execution.
The message will be shown to Claude, who may try a different approach.
§Example
let req = ToolPermissionRequest {
tool_name: "Bash".to_string(),
input: json!({"command": "sudo rm -rf /"}),
permission_suggestions: vec![],
blocked_path: None,
};
let response = req.deny("Dangerous command blocked by policy", "req-123");Sourcepub fn deny_and_stop(
&self,
message: impl Into<String>,
request_id: &str,
) -> ControlResponse
pub fn deny_and_stop( &self, message: impl Into<String>, request_id: &str, ) -> ControlResponse
Deny the tool execution and stop the entire session.
Use this for severe policy violations that should halt all processing.
Trait Implementations§
Source§impl Clone for ToolPermissionRequest
impl Clone for ToolPermissionRequest
Source§fn clone(&self) -> ToolPermissionRequest
fn clone(&self) -> ToolPermissionRequest
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more