Documentation Index
Fetch the complete documentation index at: https://docs.runloop.ai/llms.txt
Use this file to discover all available pages before exploring further.
Overview
The@runloop/agent-axon-client SDK is the TypeScript client for interacting with agents over Axon. It wraps the raw event stream in protocol-aware connection classes, typed timeline events, and narrowing guards so you do not have to hand-parse event.payload strings.
It supports two protocol modules:
- ACP for OpenCode, Goose, and other Agent Client Protocol agents
- Claude for Claude Code CLI over the
claude_jsonbroker protocol
SDK Repository
Source code and examples
Full SDK Documentation
Full method signatures, types, and options
Installation
Install the SDK
- Node.js 22+ or Bun
RUNLOOP_API_KEYANTHROPIC_API_KEYfor Claude integrations
Quick Comparison: ACP vs Claude
| Feature | ACP | Claude |
|---|---|---|
| Use case | OpenCode, Goose, custom ACP agents | Claude Code CLI |
| Connection class | ACPAxonConnection | ClaudeAxonConnection |
| Lifecycle | connect() -> initialize() -> newSession() | connect() -> initialize() -> send() |
| Basic streaming | onSessionUpdate() | receiveAgentResponse() / receiveAgentEvents() |
| Recommended app API | onTimelineEvent() | onTimelineEvent() |
| Replay / resume | replay + afterSequence | replay + afterSequence |
| Custom events | publish() | publish() |
| Permission customization | requestPermission / createClient() | onControlRequest() |
| Best fit | Structured ACP session workflows | Native Claude Code flows |
Pick your consumption pattern
| If you want to… | Use |
|---|---|
| Handle ACP session updates only | onSessionUpdate() |
| Build a UI over protocol + system + custom events | onTimelineEvent() / receiveTimelineEvents() |
| Send one Claude prompt and stop at the end of the turn | receiveAgentResponse() |
| Consume Claude messages continuously | receiveAgentEvents() |
ACP Module
The ACP module connects to agents that implement the Agent Client Protocol, including OpenCode and Goose.1. Create a connection
2. Start a session and send a prompt
3. Handle basic session updates
UseonSessionUpdate() if you only care about ACP session payloads.
4. Recommended: use timeline events for apps
Timeline events are the better fit for UIs because they combine protocol events, turn boundaries, broker/system events, and custom Axon events in one ordered stream.ACP Key Methods
The most commonly used methods onACPAxonConnection:
| Method | Description |
|---|---|
connect() | Open the Axon SSE stream and wire the ACP transport. |
initialize(params) | Run the ACP handshake. |
newSession(params) | Create a session. |
loadSession(params) | Re-open an existing session. |
listSessions(params) | List sessions known to the agent. |
prompt(params) | Start an agent turn. |
cancel(params) | Cancel an in-progress turn. |
authenticate(params) | Respond to an advertised auth method (differs from agent-to-agent auth). |
extMethod(method, params) | Send a custom extension request. |
extNotification(method, params) | Send a custom extension notification. |
publish(params) | Publish a custom Axon event on the same channel. |
onTimelineEvent(listener) | Subscribe to classified timeline events. |
disconnect() | Abort the stream and clean up. |
ACP type guards
ForonSessionUpdate() you can narrow with:
isUserMessageChunk()isAgentMessageChunk()isAgentTextChunk()isAgentThoughtChunk()isThoughtTextChunk()isToolCall()isToolCallProgress()isPlan()isUsageUpdate()isAvailableCommandsUpdate()isCurrentModeUpdate()isConfigOptionUpdate()isSessionInfoUpdate()
isSessionUpdateEvent()isInitializeEvent()isPromptEvent()isNewSessionEvent()isTurnStartedEvent()isTurnCompletedEvent()isBrokerErrorEvent()isDevboxLifecycleEvent()isAgentErrorEvent()isAgentLogEvent()isUnknownTimelineEvent()createCustomEventGuard<T>()
Claude Module
The Claude module connects to Claude Code CLI running in a Devbox via theclaude_json broker protocol.
1. Create a connection
2. Send one prompt and iterate the response
3. Recommended: use timeline events for apps
4. Handle Claude control requests
UseonControlRequest() when you want to intercept Claude permission prompts or other control flow.
Claude Key Methods
The most commonly used methods onClaudeAxonConnection:
| Method | Description |
|---|---|
connect() | Open the transport and start the read loop. |
initialize() | Run the Claude handshake. |
send(prompt) | Send a string or SDKUserMessage. |
receiveAgentResponse() | Async iterator that stops after the result message. |
interrupt() | Interrupt the current conversation turn. |
publish(params) | Publish a custom Axon event on the same channel. |
onTimelineEvent(listener) | Subscribe to classified timeline events. |
disconnect() | Close the transport and clean up. |
Claude timeline guards
Useful Claude-side guards include:isClaudeProtocolEvent()isClaudeAssistantEvent()isClaudeAssistantTextEvent()isClaudeResultEvent()isClaudeQueryEvent()isClaudeSystemInitEvent()isClaudeControlRequestEvent()isClaudeControlResponseEvent()- plus the shared guards like
isTurnCompletedEvent(),isBrokerErrorEvent(), andisDevboxLifecycleEvent()
Sessions and Replays
Axon is an append-only session log. Reconnecting to the same Axon lets the SDK replay the conversation history so your app can recover the session view instead of starting from scratch. This page uses sessions and replays intentionally. Do not call this a “snapshot” workflow in Runloop docs. “Snapshots” already means Devbox disk snapshots.What happens by default
When you callconnect(), the SDK replays the existing session history first, then resumes live delivery. Conceptually, that means:
- re-open the same Axon
- rebuild the current session state
- continue streaming from where the session left off
Recovering a session
If your app reconnects to an existing Axon, the SDK can recover the session state and continue from there:Resume after interruptions
If a stream drops or a Devbox resumes, the important mental model is the same: reconnect to the same session and let the SDK rehydrate what happened before live events continue. Timeline listeners are the best fit for this because they naturally rebuild UI state from the replayed session history.Suspend / resume with Devboxes
This model pairs well with Devboxes that suspend on idle and resume on Axon activity. Thecombined-app example uses:
lifecycle.after_idle.on_idle: "suspend"resume_triggers.axon_event: true
Timeline Events
For apps, prefer the timeline event APIs. They give you one ordered stream that includes:- protocol events (
acp_protocolorclaude_protocol) - broker/system events (
system) - custom Axon events (
unknown)
| Field | Description |
|---|---|
kind | One of acp_protocol, claude_protocol, system, or unknown |
data | Typed payload for that event kind |
axonEvent | The underlying raw Axon event |
Custom events
Usepublish() to emit custom Axon events and createCustomEventGuard<T>() or tryParseTimelinePayload<T>() to consume them safely.
Known Limitations
- Call
connect()beforeinitialize(). Both modules require an explicit connection step. - ACP
prompt()resolves before trailingsession/updateevents are fully delivered. If you need precise turn boundaries, useonTimelineEvent(). - Auto-reconnect is single retry only. If the stream drops twice, create a new connection instance.
- Claude permission requests auto-approve by default. Register
onControlRequest("can_use_tool", ...)if you need custom approval logic. - ACP permissions auto-approve by default. Override
requestPermissionor providecreateClient()if you need custom handling. - Node 22+ is required.
@runloop/api-clientis a peer dependency.@anthropic-ai/claude-agent-sdkis only required for Claude integrations.
Examples Repository
If you want a real application to copy from, start with the full-stack demo:Combined App
React + Express demo that streams classified timeline events over WebSocket,
handles permissions, and demonstrates suspend/resume-aware agent sessions.
ACP Hello World
Small ACP script showing connect, initialize, newSession, and prompt.
Claude Hello World
Small Claude script showing connect, initialize, send, and
receiveAgentResponse.
ACP CLI
Interactive ACP REPL with cancellation and richer event handling.
Claude CLI
Interactive Claude REPL with model selection and prompt streaming.
Running the examples
Full-stack app:Related Documentation
Axons Overview
Learn the raw Axon event model, event structure, and brokered flows.
ACP Protocol
Broker configuration and ACP-specific protocol behavior.
Claude Protocol
Broker configuration and Claude Code event flow.
Broker Overview
Learn how Broker bridges Axons to Devbox-hosted agents.
Axon + ACP Tutorial
Step-by-step walkthrough of an ACP integration over Axon.
Base SDK
Devbox and Axon management in the core Runloop SDKs.
