Skip to main content
This guide is for developers integrating Atomic into editors, integrated development environments (IDEs), custom UIs, or non-Node.js services. By the end of this page, you can start Atomic in headless Remote Procedure Call (RPC) mode, send correlated JSON Lines (JSONL) commands, wait reliably for turns to settle, follow strict framing rules, and shut down the process cleanly. If you are building a Node.js or TypeScript app, you can embed 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:
Common startup options from atomic --help include:
  • --provider <name>: Select the provider to search for --model (requires --model).
  • --model <pattern>: Select a model by provider/id or 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, or max).
  • --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-dir or --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.
To isolate an RPC subprocess’s session storage without changing user settings, start it with 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.
Every command accepts an optional 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 single prompt can trigger automatic retries, model fallbacks, compaction recovery, or queued turns:
  • Check data.disposition first: On the prompt response, if data.disposition is "handled", an extension command or input hook consumed the message and no turn started. Don’t wait for agent_end or agent_settled.
  • Don’t stop on agent_end: agent_end fires 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 for agent_settled before 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 \n only.
  • Strip an optional trailing \r from \r\n lines.
  • Avoid generic line readers that split on Unicode line separators (U+2028, U+2029) or bare \r.
Node.js’s readline module isn’t protocol-compliant because it splits on U+2028 and U+2029, which are valid unescaped inside JSON strings. Similarly, Python’s text=True universal newlines mode splits on bare \r. Always read raw bytes and split strictly on b"\n".

Shutdown and signals

RPC mode shuts down cleanly when stdin closes or when the process receives a termination signal:
  • Orderly shutdown: Closing stdin, SIGTERM, and SIGHUP start 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 sending SIGTERM together still lets disposal finish.
  • Platform SIGHUP rules: Standalone RPC mode doesn’t register SIGHUP on Windows, and skips SIGHUP on Unix when the process inherits SIG_IGN (for example under nohup).
  • Forced exit and exit codes: A second signal exits immediately (143 for SIGTERM, 129 for SIGHUP), and SIGKILL always stops the process immediately. Orderly shutdown exits with code 0. If disposal fails, Atomic emits a shutdown_error event and exits with code 1 (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: abort holds 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 on b"\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:
Confirm that the script prints the assistant’s sentence to stdout and exits with status 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.