ToolPermissionRequest

Struct ToolPermissionRequest 

Source
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: String

Name of the tool Claude wants to use (e.g., “Bash”, “Write”, “Read”)

§input: Value

Input 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

Source

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");
Source

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");
Source

pub fn allow_with_permissions( &self, modified_input: Value, permissions: Vec<Value>, request_id: &str, ) -> ControlResponse

Allow with updated permissions list.

Source

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");
Source

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

Source§

fn clone(&self) -> ToolPermissionRequest

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ToolPermissionRequest

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for ToolPermissionRequest

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for ToolPermissionRequest

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,