Skip to main content

ToolInput

Enum ToolInput 

Source
pub enum ToolInput {
Show 18 variants Edit(EditInput), Write(WriteInput), AskUserQuestion(AskUserQuestionInput), TodoWrite(TodoWriteInput), Task(TaskInput), NotebookEdit(NotebookEditInput), WebFetch(WebFetchInput), TaskOutput(TaskOutputInput), Bash(BashInput), Read(ReadInput), Glob(GlobInput), Grep(GrepInput), WebSearch(WebSearchInput), KillShell(KillShellInput), Skill(SkillInput), ExitPlanMode(ExitPlanModeInput), EnterPlanMode(EnterPlanModeInput), Unknown(Value),
}
Expand description

Unified enum representing input for any Claude Code tool.

This enum uses #[serde(untagged)] to automatically deserialize based on the structure of the JSON. The Unknown variant serves as a fallback for:

  • New tools added in future Claude CLI versions
  • Custom MCP tools provided by users
  • Any tool input that doesn’t match known schemas

§Example

use claude_codes::ToolInput;

// Known tool - deserializes to specific variant
let bash_json = serde_json::json!({"command": "ls"});
let input: ToolInput = serde_json::from_value(bash_json).unwrap();
assert!(matches!(input, ToolInput::Bash(_)));

// Unknown tool - falls back to Unknown variant
let custom_json = serde_json::json!({"custom_field": "value"});
let input: ToolInput = serde_json::from_value(custom_json).unwrap();
assert!(matches!(input, ToolInput::Unknown(_)));

§Note on Ordering

The variants are ordered from most specific (most required fields) to least specific to ensure correct deserialization with #[serde(untagged)].

Variants§

§

Edit(EditInput)

Edit tool - has unique field combination (file_path, old_string, new_string)

§

Write(WriteInput)

Write tool - file_path + content

§

AskUserQuestion(AskUserQuestionInput)

AskUserQuestion tool - has questions array

§

TodoWrite(TodoWriteInput)

TodoWrite tool - has todos array

§

Task(TaskInput)

Task tool - description + prompt + subagent_type

§

NotebookEdit(NotebookEditInput)

NotebookEdit tool - notebook_path + new_source

§

WebFetch(WebFetchInput)

WebFetch tool - url + prompt

§

TaskOutput(TaskOutputInput)

TaskOutput tool - task_id + block + timeout

§

Bash(BashInput)

Bash tool - has command field

§

Read(ReadInput)

Read tool - has file_path

§

Glob(GlobInput)

Glob tool - has pattern field (with deny_unknown_fields, must come before Grep)

§

Grep(GrepInput)

Grep tool - has pattern field plus many optional fields

§

WebSearch(WebSearchInput)

WebSearch tool - has query field

§

KillShell(KillShellInput)

KillShell tool - has shell_id

§

Skill(SkillInput)

Skill tool - has skill field

§

ExitPlanMode(ExitPlanModeInput)

ExitPlanMode tool

§

EnterPlanMode(EnterPlanModeInput)

EnterPlanMode tool (empty input)

§

Unknown(Value)

Unknown tool input - fallback for custom/new tools

This variant captures any tool input that doesn’t match the known schemas. Use this for:

  • MCP tools provided by users
  • New tools in future Claude CLI versions
  • Any custom tool integration

Implementations§

Source§

impl ToolInput

Source

pub fn tool_name(&self) -> Option<&'static str>

Returns the tool name if it can be determined from the input type.

For Unknown variants, returns None since the tool name cannot be determined from the input structure alone.

Source

pub fn as_bash(&self) -> Option<&BashInput>

Try to get the input as a Bash input.

Source

pub fn as_read(&self) -> Option<&ReadInput>

Try to get the input as a Read input.

Source

pub fn as_write(&self) -> Option<&WriteInput>

Try to get the input as a Write input.

Source

pub fn as_edit(&self) -> Option<&EditInput>

Try to get the input as an Edit input.

Source

pub fn as_glob(&self) -> Option<&GlobInput>

Try to get the input as a Glob input.

Source

pub fn as_grep(&self) -> Option<&GrepInput>

Try to get the input as a Grep input.

Source

pub fn as_task(&self) -> Option<&TaskInput>

Try to get the input as a Task input.

Source

pub fn as_web_fetch(&self) -> Option<&WebFetchInput>

Try to get the input as a WebFetch input.

Try to get the input as a WebSearch input.

Source

pub fn as_todo_write(&self) -> Option<&TodoWriteInput>

Try to get the input as a TodoWrite input.

Source

pub fn as_ask_user_question(&self) -> Option<&AskUserQuestionInput>

Try to get the input as an AskUserQuestion input.

Source

pub fn as_notebook_edit(&self) -> Option<&NotebookEditInput>

Try to get the input as a NotebookEdit input.

Source

pub fn as_task_output(&self) -> Option<&TaskOutputInput>

Try to get the input as a TaskOutput input.

Source

pub fn as_kill_shell(&self) -> Option<&KillShellInput>

Try to get the input as a KillShell input.

Source

pub fn as_skill(&self) -> Option<&SkillInput>

Try to get the input as a Skill input.

Source

pub fn as_unknown(&self) -> Option<&Value>

Try to get the input as an unknown Value.

Source

pub fn is_unknown(&self) -> bool

Check if this is an unknown tool input.

Trait Implementations§

Source§

impl Clone for ToolInput

Source§

fn clone(&self) -> ToolInput

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 ToolInput

Source§

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

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

impl<'de> Deserialize<'de> for ToolInput

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 From<AskUserQuestionInput> for ToolInput

Source§

fn from(input: AskUserQuestionInput) -> Self

Converts to this type from the input type.
Source§

impl From<BashInput> for ToolInput

Source§

fn from(input: BashInput) -> Self

Converts to this type from the input type.
Source§

impl From<EditInput> for ToolInput

Source§

fn from(input: EditInput) -> Self

Converts to this type from the input type.
Source§

impl From<GlobInput> for ToolInput

Source§

fn from(input: GlobInput) -> Self

Converts to this type from the input type.
Source§

impl From<GrepInput> for ToolInput

Source§

fn from(input: GrepInput) -> Self

Converts to this type from the input type.
Source§

impl From<ReadInput> for ToolInput

Source§

fn from(input: ReadInput) -> Self

Converts to this type from the input type.
Source§

impl From<TaskInput> for ToolInput

Source§

fn from(input: TaskInput) -> Self

Converts to this type from the input type.
Source§

impl From<TodoWriteInput> for ToolInput

Source§

fn from(input: TodoWriteInput) -> Self

Converts to this type from the input type.
Source§

impl From<WebFetchInput> for ToolInput

Source§

fn from(input: WebFetchInput) -> Self

Converts to this type from the input type.
Source§

impl From<WebSearchInput> for ToolInput

Source§

fn from(input: WebSearchInput) -> Self

Converts to this type from the input type.
Source§

impl From<WriteInput> for ToolInput

Source§

fn from(input: WriteInput) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for ToolInput

Source§

fn eq(&self, other: &ToolInput) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for ToolInput

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
Source§

impl StructuralPartialEq for ToolInput

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>,