Events are the SDK contract

The Autohand CLI runs the reasoning loop. The SDK opens a JSON-RPC or stdio connection to the CLI and receives a stream of events. Your application never needs to host the model or implement tool calling itself; it only needs to understand the events.

This design keeps SDKs thin, consistent across languages, and safe. The CLI enforces permissions and file access; the SDK observes and responds.

Common event types

The TypeScript, Python, Go, Java, Rust, Ruby, C#/.NET, and C++ CLI-backed wrappers support the same current CLI notification families. String-event SDKs use normalized snake-case names; Java exposes corresponding typed records. The native Swift SDK has its own event transport and should be treated as a separate contract.

EventWhen it firesKey fields
turn_startA new reasoning turn beginsturnId, iteration
message_updateThe model streams a token or fragmentdelta, message
tool_startA tool is about to runtoolName, args
tool_endA tool has finishedtoolName, output, success
permission_requestThe CLI needs user approvalrequestId, tool, description
file_modifiedA tool created, modified, or deleted a filefilePath, changeType, toolId
errorA runtime or transport error occurredmessage, recoverable

Complete CLI hook notification set

The CLI-backed wrappers now expose all 16 hook notifications as typed events instead of dropping them into a generic fallback.

Normalized eventWhat it reports
hook_pre_toolA tool is about to run, including its name and arguments.
hook_post_toolA tool completed, including success, output, and duration.
file_modifiedA CLI hook reports a created, modified, or deleted path.
hook_pre_promptThe CLI accepted an instruction and its mentioned files.
hook_post_responseA response completed with usage, tool-call count, and duration.
hook_session_errorThe active session reports an error and optional context.
hook_stopThe runtime stop hook reports final usage and duration.
hook_session_startA startup, resume, or clear session lifecycle begins.
hook_session_endA session ends because of quit, clear, exit, or error.
hook_subagent_stopA subagent completes or fails.
hook_permission_requestA hook observes the tool action awaiting permission.
hook_notificationA configured notification hook emits a typed message.
hook_context_compactedContext was compacted, including usage and cropped-message counts.
hook_context_overflowContext overflow recovery cropped messages.
hook_context_warningContext use crossed the warning threshold.
hook_context_criticalContext use crossed the critical threshold.

MCP and learning notifications

Normalized eventWhat your host should do
mcp_invoke_requestReview an MCP tool invocation request and respond through the SDK's MCP response API.
mcp_tools_changedRefresh the MCP tool catalog exposed by the host UI.
learn_progressRender progress while the CLI analyzes, loads, evaluates, generates, or updates learned material.

C#/.NET currently names the first normalized string mcp_invocation_request; its typed McpInvocationRequestEvent carries the same CLI notification. Unknown or malformed newer notifications remain available through each wrapper's unknown-event fallback instead of being discarded.

Stream events

Every SDK provides a streaming prompt method that yields events. These examples demonstrate the same event-loop shape in a representative set of SDKs; use the language reference for its native event type names.

Intercept behavior with hooks

In addition to observing events, you can register SDK hooks that run before or after specific events and optionally veto the action. This is useful for guardrails, audit logging, and custom integrations.

A hook handler returns an object. Return { allow: true } or undefined to proceed. Return { allow: false, reason: '...' } to block the action and surface a message to the model.

Event ordering guarantees

  • Events for a single turn are delivered in order.
  • tool_start always precedes tool_end for the same invocation.
  • permission_request is emitted before the action is taken. The loop waits until the SDK responds or a timeout occurs.
  • Pre-action hook notifications arrive before their matching action; post-action hook notifications include the completed result.
  • Unknown notification fallbacks preserve the original RPC method and payload so a newer CLI does not silently lose data.

Best practices

  • Handle events asynchronously. Do not block the event stream with network calls unless the event requires a decision, such as permission_request.
  • Persist important events outside the process. The stream ends when the session closes.
  • Use typed SDK clients when available so event fields are validated at compile time or runtime.
  • Keep hook handlers stateless. The SDK may retry a call if the CLI restarts.