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
impl ToolInput
Sourcepub fn tool_name(&self) -> Option<&'static str>
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.
Sourcepub fn as_write(&self) -> Option<&WriteInput>
pub fn as_write(&self) -> Option<&WriteInput>
Try to get the input as a Write input.
Sourcepub fn as_web_fetch(&self) -> Option<&WebFetchInput>
pub fn as_web_fetch(&self) -> Option<&WebFetchInput>
Try to get the input as a WebFetch input.
Sourcepub fn as_web_search(&self) -> Option<&WebSearchInput>
pub fn as_web_search(&self) -> Option<&WebSearchInput>
Try to get the input as a WebSearch input.
Sourcepub fn as_todo_write(&self) -> Option<&TodoWriteInput>
pub fn as_todo_write(&self) -> Option<&TodoWriteInput>
Try to get the input as a TodoWrite input.
Sourcepub fn as_ask_user_question(&self) -> Option<&AskUserQuestionInput>
pub fn as_ask_user_question(&self) -> Option<&AskUserQuestionInput>
Try to get the input as an AskUserQuestion input.
Sourcepub fn as_notebook_edit(&self) -> Option<&NotebookEditInput>
pub fn as_notebook_edit(&self) -> Option<&NotebookEditInput>
Try to get the input as a NotebookEdit input.
Sourcepub fn as_task_output(&self) -> Option<&TaskOutputInput>
pub fn as_task_output(&self) -> Option<&TaskOutputInput>
Try to get the input as a TaskOutput input.
Sourcepub fn as_kill_shell(&self) -> Option<&KillShellInput>
pub fn as_kill_shell(&self) -> Option<&KillShellInput>
Try to get the input as a KillShell input.
Sourcepub fn as_skill(&self) -> Option<&SkillInput>
pub fn as_skill(&self) -> Option<&SkillInput>
Try to get the input as a Skill input.
Sourcepub fn as_unknown(&self) -> Option<&Value>
pub fn as_unknown(&self) -> Option<&Value>
Try to get the input as an unknown Value.
Sourcepub fn is_unknown(&self) -> bool
pub fn is_unknown(&self) -> bool
Check if this is an unknown tool input.