Skip to main content

StreamHandler

Trait StreamHandler 

Source
pub trait StreamHandler: Send {
    // Required methods
    fn on_text(&mut self, text: &str);
    fn on_tool_call(&mut self, name: &str, id: &str, input: &Value);
    fn on_tool_result(&mut self, id: &str, output: &str);
    fn on_error(&mut self, error: &str);
    fn on_complete(&mut self, result: &SessionResult);
}
Expand description

Handler for streaming output events from Claude.

Implementors receive events as Claude processes and can format/display them in various ways (console output, TUI updates, logging, etc.).

Required Methods§

Source

fn on_text(&mut self, text: &str)

Called when Claude emits text.

Source

fn on_tool_call(&mut self, name: &str, id: &str, input: &Value)

Called when Claude invokes a tool.

§Arguments
  • name - Tool name (e.g., “Read”, “Bash”, “Grep”)
  • id - Unique tool invocation ID
  • input - Tool input parameters as JSON (file paths, commands, patterns, etc.)
Source

fn on_tool_result(&mut self, id: &str, output: &str)

Called when a tool returns results.

Source

fn on_error(&mut self, error: &str)

Called when an error occurs.

Source

fn on_complete(&mut self, result: &SessionResult)

Called when session completes (verbose only).

Implementors§