pub enum ToolInput {
Show 23 variants
Edit(EditInput),
Write(WriteInput),
MultiEdit(MultiEditInput),
AskUserQuestion(AskUserQuestionInput),
TodoWrite(TodoWriteInput),
Task(TaskInput),
NotebookEdit(NotebookEditInput),
WebFetch(WebFetchInput),
TaskOutput(TaskOutputInput),
Bash(BashInput),
Read(ReadInput),
Glob(GlobInput),
Grep(GrepInput),
ToolSearch(ToolSearchInput),
WebSearch(WebSearchInput),
KillShell(KillShellInput),
Skill(SkillInput),
ExitPlanMode(ExitPlanModeInput),
ScheduleWakeup(ScheduleWakeupInput),
NotebookRead(NotebookReadInput),
LS(LsInput),
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
MultiEdit(MultiEditInput)
MultiEdit tool - batch file edits (file_path + edits, before Read)
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
ToolSearch(ToolSearchInput)
ToolSearch tool - fetch deferred tool schemas (query + max_results)
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
ScheduleWakeup(ScheduleWakeupInput)
ScheduleWakeup tool - schedule delayed wakeup (3 required fields)
NotebookRead(NotebookReadInput)
NotebookRead tool - read notebook cells (notebook_path required)
LS(LsInput)
LS tool - list files and directories
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 from_named_input(name: &str, input: Value) -> Self
pub fn from_named_input(name: &str, input: Value) -> Self
Parse a tool-use input payload using the authoritative tool name
from the surrounding ToolUse block, instead of guessing the variant
from field shape.
The Deserialize impl for ToolInput is #[serde(untagged)], so it
resolves variants by structural shape in declaration order. Tools whose
inputs are structurally identical are therefore genuinely ambiguous to
the untagged impl — most notably WebSearch and
ToolSearch, which both deserialize cleanly
from a bare { "query": String }, so the first-declared variant wins
and the other is never produced. The tool name disambiguates them.
Falls back to ToolInput::Unknown when the named struct doesn’t
deserialize, and defers to the untagged Deserialize impl for tool
names this crate doesn’t model (e.g. MCP tools).
§Examples
use claude_codes::ToolInput;
// A bare-query WebSearch input — ambiguous to the untagged impl, which
// would pick `ToolSearch`. The name resolves it correctly.
let input = serde_json::json!({ "query": "rust async" });
let parsed = ToolInput::from_named_input("WebSearch", input);
assert!(matches!(parsed, ToolInput::WebSearch(_)));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.