Class Handler.default

Default handler that does nothing for all events.

This is the recommended base class for most use cases. Override only the methods you need:

  let handler =
    object
      inherit Claude.Handler.default

      method! on_text t =
        Printf.printf "Text: %s\n" (Response.Text.content t)
    end

Methods you don't override will simply be ignored, making this ideal for prototyping and for cases where you only care about specific events.

method on_text : Claude__.Response.Text.t -> unit

on_text t is called when text content is received from the assistant.

method on_tool_use : Claude__.Response.Tool_use.t -> unit

on_tool_use t is called when the assistant requests a tool invocation. The caller is responsible for responding with Client.respond_to_tool.

method on_tool_result : Claude__.Content_block.Tool_result.t -> unit

on_tool_result t is called when a tool result is observed in the message stream. This is typically an echo of what was sent to Claude.

method on_thinking : Claude__.Response.Thinking.t -> unit

on_thinking t is called when internal reasoning content is received.

method on_init : Claude__.Response.Init.t -> unit

on_init t is called when the session is initialized. This provides session metadata like session_id and model.

method on_error : Claude__.Response.Error.t -> unit

on_error t is called when an error occurs. Errors can come from the system (e.g., CLI errors) or from the assistant (e.g., rate limits).

method on_complete : Claude__.Response.Complete.t -> unit

on_complete t is called when the conversation completes. This provides final metrics like duration, cost, and token usage.