Creates a new Claude connection over the given Axon channel and devbox.
Unlike ACP, the transport is not opened until connect is called.
The Axon channel to communicate over (from @runloop/api-client).
The Runloop devbox hosting the Claude Code agent.
Optionaloptions: ClaudeAxonConnectionOptionsOptional configuration for verbose logging, system prompt, model selection, error handling, and lifecycle hooks.
ReadonlyaxonThe Axon channel ID this connection is bound to.
ReadonlydevboxThe Runloop devbox ID.
Whether the transport is connected and the read loop is active.
Returns true after connect resolves and before disconnect.
Whether the connection has been fully initialized (transport connected,
read loop active, and protocol handshake complete).
Returns false before initialize resolves or after the read loop ends.
Aborts the underlying SSE stream without clearing registered listeners
or running the onDisconnect callback.
Unlike disconnect, listeners remain registered. Note that after
calling this method, the connection cannot be reused — create a new
ClaudeAxonConnection instance to reconnect.
Opens the transport and starts the background read loop.
Call this before initialize to establish the Axon connection.
When replay is true (the default), queries the axon for the
current head sequence and replays all events up to that point
without invoking handlers. Unresolved control requests are
dispatched to handlers after replay completes.
Closes the transport, fails all pending control requests, and runs the
onDisconnect callback if one was provided.
User-registered listeners (onAxonEvent, onTimelineEvent, onControlRequest) are preserved so they keep working after another connect.
Idempotent — subsequent calls are no-ops until the next connect.
Resolves once all teardown (including onDisconnect) completes.
Runs the Claude agent protocol initialize step with the Claude Code CLI.
This is required once after connect on first startup: connect() only
opens the transport and read loop; the agent does not accept prompts or control
traffic until this handshake completes. If ClaudeAxonConnectionOptions.model
was set, a set_model control request is sent immediately afterward.
If connect has not been called yet (code: "not_connected").
Registers a listener for every Axon event (before origin filtering). Useful for debugging, observability, and building Axon event viewers.
Callback invoked with the raw AxonEventView for every event on the channel, regardless of origin.
An unsubscribe function that removes the listener.
Register a handler for incoming control requests of a given subtype.
When Claude Code sends a control request (e.g. asking permission to use a tool), the registered handler is called instead of the built-in default. The handler receives the full SDKControlRequest and must return a complete SDKControlResponse. The connection sends it back as-is.
Only one handler can be registered per subtype. Calling this method again with the same subtype replaces the previous handler.
The control request subtype to handle (e.g. "can_use_tool").
Async function that processes the request and returns a full SDKControlResponse.
Registers a listener for classified timeline events (push API).
Every Axon event on the channel is classified into one of:
claude_protocol — a known Claude protocol event (user or agent message)system — a broker system event (turn.started, turn.completed, broker.error)unknown — anything elseFor a pull-based alternative, see receiveTimelineEvents. Both APIs deliver the same events; choose whichever fits your consumption pattern.
Callback invoked with each ClaudeTimelineEvent.
An unsubscribe function that removes the listener.
Publishes a custom event to the Axon channel.
The event will appear in the SSE stream and be classified by the
timeline (typically as kind: "unknown" unless the event_type
matches a known Claude protocol message type).
The event to publish (same shape as Axon.publish()).
The publish result with sequence number and timestamp.
Async iterator that yields every SDKMessage from Claude indefinitely.
Does not stop at result messages — use receiveAgentResponse
for single-turn convenience. Iteration ends when the transport closes
or disconnect is called.
Async iterator that yields SDKMessages until (and including) a
result message, then terminates automatically.
Convenient for single-turn usage: send a prompt, iterate
receiveAgentResponse(), and the loop ends when Claude finishes.
Use receiveAgentEvents instead.
Use receiveAgentResponse instead.
Async generator that yields classified timeline events (pull API).
Mirrors the pull-based pattern of receiveAgentEvents. The generator completes when the connection is disconnected or the read loop ends.
For a push-based alternative, see onTimelineEvent. Both APIs deliver the same events; choose whichever fits your consumption pattern.
An async generator of ClaudeTimelineEvent.
Sends a single user message to Claude.
If given a plain string, it is automatically wrapped into an
SDKUserMessage with role: "user". Pass a pre-built
SDKUserMessage for full control (e.g. to set parent_tool_use_id).
A string message or a fully formed SDKUserMessage.
Changes the permission mode for tool use.
The new permission mode (e.g. "default", "acceptEdits").
Bidirectional, interactive client for Claude Code via Axon.
Provides:
Messages are yielded as
SDKMessagefrom@anthropic-ai/claude-agent-sdk— the exact types the Claude Code CLI emits.