Skip to main content

Overview

The @runloop/remote-agents-sdk SDK is the TypeScript client for interacting with remote 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_json broker protocol

SDK Repository

Source code and examples

Full SDK Documentation

Full method signatures, types, and options
For apps and UIs, prefer the timeline event APIs: onTimelineEvent() and receiveTimelineEvents(). They give you one typed stream for protocol messages, turn boundaries, broker events, and custom Axon events.

Installation

1

Install the SDK

Requirements:
  • Node.js 22+ or Bun
  • RUNLOOP_API_KEY
  • ANTHROPIC_API_KEY for Claude integrations
2

Install the Claude peer dependency if needed

Quick Comparison: ACP vs Claude

Pick your consumption pattern


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

Use onSessionUpdate() if you only care about ACP session payloads.
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 on ACPAxonConnection: For the full API surface — all methods, options, and type signatures — see the full SDK documentation.

ACP type guards

For onSessionUpdate() you can narrow with:
  • isUserMessageChunk()
  • isAgentMessageChunk()
  • isAgentTextChunk()
  • isAgentThoughtChunk()
  • isThoughtTextChunk()
  • isToolCall()
  • isToolCallProgress()
  • isPlan()
  • isUsageUpdate()
  • isAvailableCommandsUpdate()
  • isCurrentModeUpdate()
  • isConfigOptionUpdate()
  • isSessionInfoUpdate()
For timeline events you can narrow with:
  • 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 the claude_json broker protocol.

1. Create a connection

2. Send one prompt and iterate the response

4. Handle Claude control requests

Use onControlRequest() when you want to intercept Claude permission prompts or other control flow.

Claude Key Methods

The most commonly used methods on ClaudeAxonConnection: For the full API surface — all methods, options, and type signatures — see the full SDK documentation.

Claude timeline guards

Useful Claude-side guards include:
  • isClaudeProtocolEvent()
  • isClaudeAssistantEvent()
  • isClaudeAssistantTextEvent()
  • isClaudeResultEvent()
  • isClaudeQueryEvent()
  • isClaudeSystemInitEvent()
  • isClaudeControlRequestEvent()
  • isClaudeControlResponseEvent()
  • plus the shared guards like isTurnCompletedEvent(), isBrokerErrorEvent(), and isDevboxLifecycleEvent()

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 call connect(), 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
That is why refresh-and-recover flows work well with the timeline APIs.

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. The combined-app example uses:
  • lifecycle.after_idle.on_idle: "suspend"
  • resume_triggers.axon_event: true
That lets a conversation pause with the Devbox and recover cleanly when activity resumes.

Timeline Events

For apps, prefer the timeline event APIs. They give you one ordered stream that includes:
  • protocol events (acp_protocol or claude_protocol)
  • broker/system events (system)
  • custom Axon events (unknown)
Every timeline event has:

Custom events

Use publish() to emit custom Axon events and createCustomEventGuard<T>() or tryParseTimelinePayload<T>() to consume them safely.

Known Limitations

  • Call connect() before initialize(). Both modules require an explicit connection step.
  • ACP prompt() resolves before trailing session/update events are fully delivered. If you need precise turn boundaries, use onTimelineEvent().
  • 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 requestPermission or provide createClient() if you need custom handling.
  • Node 22+ is required.
  • @runloop/api-client is a peer dependency.
  • @anthropic-ai/claude-agent-sdk is 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:
Hello world scripts:

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.