AgentSession in-process with the TypeScript SDK or use the typed RpcClient in Connect with RPC clients. To compare all four programmatic modes, see Choose an integration mode.
RPC protocol reference
Every RPC command, streamed event, structured error code, and JSON wire type.
Handle extension UI over RPC
Answer extension dialogs, notifications, widgets, questionnaires, and OAuth prompts.
Connect with RPC clients
TypeScript
RpcClient recipes, caveats, and a standalone Node.js client.Stored session summaries
Inspect saved sessions with
get_session_summary and list_sessions without starting a model turn.Before you begin
Before you launch an RPC process, confirm that you have:- The Atomic CLI installed on
PATH(see Installation). - At least one model provider signed in or configured with an API key (see Authentication).
Start RPC mode
To launch Atomic in headless RPC mode, run:atomic --help include:
--provider <name>: Select the provider to search for--model(requires--model).--model <pattern>: Select a model byprovider/idor pattern, with an optional:<thinking>level.--models <patterns>: Restrict scoped models using comma-separated patterns.--thinking <level>: Set the initial thinking level (off,minimal,low,medium,high,xhigh, ormax).--session <id|prefix>,--continue(-c), or--resume(-r): Open or resume a stored session.--name <name>(-n <name>): Set the session display name at startup.--no-session: Run without saving a resumable session (see Sessions).--session-dir <dir>: Select a JSONL session storage and lookup directory.--session-store <path>: Select a SQLite session database file (can’t be combined with--session-diror--no-session).--session-prefix <prefix>: Set a table prefix for--session-store(defaults to empty).--storage <json>or--storage-file <path>: Select session storage for this process.--tools <tools>,--no-tools,--no-builtin-tools, or--exclude-tools <tools>: Control which tools are active.
@file CLI arguments aren’t supported in RPC mode. Passing any @file argument writes an error to stderr and exits immediately with code 1. Send file text or base64 images inside prompt, steer, or follow_up commands instead.ATOMIC_STORAGE or --storage set to the same JSON object as the storage setting (for example, an adapter config reading secrets from { "env": "..." }). list_sessions reports that store while other atomic processes keep their own settings. Invalid session storage selections fail at startup with StorageConfigError. See Selecting storage per process.
Protocol overview
RPC mode exchanges three kinds of JSON Lines frames over stdin and stdout:- Commands: JSON objects written to stdin, one per line.
- Responses: JSON objects with
type: "response"reporting command success or failure. - Events: Session events streamed to stdout as JSON lines.
id string for request correlation. When you include id, the matching response echoes the same id.
If a saved default provider/model names a provider that stays unsupported after startup, the process stays alive and prompt returns a correlated error with the configuration diagnostic before emitting any event. Non-prompt commands such as get_available_models keep working. Clear the error state with a successful explicit set_model, or with a cycle_model that switches to a different available model (an unchanged or null cycle doesn’t clear it). Supported providers with an unknown model or missing credentials fall back automatically.
On compacted or branched sessions, get_entries and get_tree return the loaded context window, while get_fork_messages still includes prompts from older branches using short picker labels. Use get_history_page (following nextCursor) and get_history_chunk to read older entries and oversized items.
Wait for turns to finish
A singleprompt can trigger automatic retries, model fallbacks, compaction recovery, or queued turns:
- Check
data.dispositionfirst: On thepromptresponse, ifdata.dispositionis"handled", an extension command or input hook consumed the message and no turn started. Don’t wait foragent_endoragent_settled. - Don’t stop on
agent_end:agent_endfires after one low-level agent loop finishes, even when a retry (retryPending: true), post-compaction continuation, or queued follow-up runs next. - Wait for
agent_settled:{ "type": "agent_settled", "aborted": false }fires after the entire turn chain finishes with no automatic work remaining. Wait foragent_settledbefore closing stdin or treating a prompt as complete.
Command execution and concurrency
Atomic dispatches stdin frames across two lanes so cancellations and extension UI replies aren’t blocked behind slow commands. The following table compares the two lanes:
Because the first sequential frame starts synchronously before the next line is read, a follow-up interrupt sent immediately after a command can’t overtake the command’s initialization.
Frame format and line delimiters
RPC mode uses strict JSONL framing with line feed (LF,\n) as the only record delimiter. Atomic imposes no line-size cap on RPC JSONL records, so commands, responses, and events serialize in full. Account for memory and latency on large tool outputs or images, and don’t enforce smaller line limits unless you intend to reject valid output.
Follow these client framing rules:
- Split records on
\nonly. - Strip an optional trailing
\rfrom\r\nlines. - Avoid generic line readers that split on Unicode line separators (
U+2028,U+2029) or bare\r.
Shutdown and signals
RPC mode shuts down cleanly when stdin closes or when the process receives a termination signal:- Orderly shutdown: Closing stdin,
SIGTERM, andSIGHUPstart an orderly shutdown that disposes of the active session before exiting. After shutdown starts, closing stdin or sending a single signal doesn’t interrupt cleanup, so closing stdin and sendingSIGTERMtogether still lets disposal finish. - Platform
SIGHUPrules: Standalone RPC mode doesn’t registerSIGHUPon Windows, and skipsSIGHUPon Unix when the process inheritsSIG_IGN(for example undernohup). - Forced exit and exit codes: A second signal exits immediately (
143forSIGTERM,129forSIGHUP), andSIGKILLalways stops the process immediately. Orderly shutdown exits with code0. If disposal fails, Atomic emits ashutdown_errorevent and exits with code1(or the signal’s exit code when a signal started shutdown). - Extension-driven shutdown: An extension can call
ctx.shutdown()to end an idle RPC session without another client command. Shutdown waits for any active command response and running turn; a request sent during extension-started compaction outside a turn runs after compaction completes. - Abort before exit:
abortholds queued messages (like pressing Esc in the terminal UI (TUI)) so a client can abort and close stdin safely, preserving queued completion notices for the next session instead of failing disposal.
Run a Python RPC client
The following Python client reads stdout as raw bytes split strictly onb"\n", sends one correlated prompt, checks data.disposition in case an extension command handled it without starting a turn, streams text deltas, waits for agent_settled, and closes stdin for orderly shutdown:
0:
Troubleshooting
Use the following table to resolve common RPC mode issues:Next steps
Connect with RPC clients
Use the typed
RpcClient in TypeScript or a standalone Node.js client with strict framing.Handle extension UI over RPC
Implement dialogs, notifications, widgets, questionnaires, and OAuth prompts.
RPC protocol reference
Look up every command, streamed event, and structured error code.
Parse JSON event streams
Run one-shot prompts with
--mode json when you don’t need follow-up commands.