AgentSession directly with the TypeScript SDK or use the typed RpcClient exported from @bastani/atomic (see Connect with RPC clients). Compare all four programmatic modes on Choose an integration mode.
Reference pages
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.Starting RPC mode
--provider <name>: select the model provider (anthropic,openai,google, and others).--model <pattern>: select a model byprovider/idor pattern, with optional:<thinking>level.--models <patterns>: restrict scoped models (comma-separated patterns).--thinking <level>: set the initial thinking level.--session <id>/--continue(-c) /--resume(-r): open or resume a stored session.--name <name>/-n <name>: set the session display name at startup.--no-session: run without a resumable session (released idle history may still page to disk; see Sessions).--session-dir <path>: select a JSONL session storage and lookup directory.--session-store <path>: select a SQLite session database file (cannot be combined with--session-diror--no-session).--session-prefix <prefix>: table prefix for--session-store(requires--session-store; defaults to empty).--storage '<json>'/--storage-file <path>: select storage for this process’s sessions.--tools <list>/--no-tools/--exclude-tools <list>: control which tools are active.
@file CLI arguments are not supported in RPC mode; passing any @file argument writes an error to stderr and exits immediately with code 1. Send file content 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 storage selections fail at startup with StorageConfigError. See Selecting storage per process.
Protocol overview
- 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 send id, the matching response echoes the same id.
If a saved default provider/model names a provider that remains unsupported after startup, the process stays alive and prompt returns a correlated error containing 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 a cycle_model that switches to a different available model (an unchanged or null cycle does not clear it). Supported providers with an unknown model or missing credentials fall back automatically as usual.
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.
Waiting for turns to finish (agent_settled vs. agent_end)
A single prompt can trigger retries, model fallbacks, automatic compaction recovery, or queued turns:
- Check the
promptresponse’sdata.dispositionfirst. Ifdispositionis"handled", an extension command or input hook consumed the message and no turn started — do not wait foragent_endoragent_settled. agent_endfires after one low-level agent loop finishes, even when a retry (retryPending: true), post-compaction continuation, or queued follow-up is about to run next.agent_settledfires once the entire turn chain finishes with no automatic work remaining ({ "type": "agent_settled", "aborted": false }). Wait foragent_settledrather thanagent_endbefore closing stdin or treating a multi-step prompt as done.
Command execution and concurrency
Atomic dispatches stdin frames across two lanes so cancellations and extension UI replies are never blocked behind slow commands:
Because the first sequential frame starts synchronously before the next line is read, a follow-up interrupt sent immediately after a command cannot overtake the command’s initialization.
Framing
RPC mode uses strict JSONL framing with LF (\n) as the only record delimiter.
Atomic imposes no line-size cap on RPC JSONL records; commands, responses, and events serialize in full. Account for memory and latency on large tool outputs or images, and do not enforce smaller line limits unless you intend to reject valid output.
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
- Closing stdin,
SIGTERM, andSIGHUPstart an orderly shutdown that disposes the active session before exiting. Once shutdown begins, closing stdin or sending a single signal does not interrupt cleanup, so closing stdin and sendingSIGTERMtogether still lets disposal finish. - Standalone RPC mode does not register
SIGHUPon Windows, and skipsSIGHUPon Unix when the process inheritsSIG_IGN(for example undernohup). - A second signal exits immediately (
143forSIGTERM,129forSIGHUP), andSIGKILLalways terminates 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). - 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 once compaction completes. abortholds queued messages (like pressingEscin the TUI) so a client can abort and close stdin safely, preserving queued completion notices for the next session instead of failing disposal.
Example Python client
This minimal client reads stdout as binary lines split strictly on\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 (covering any retries or continuations), and closes stdin for orderly shutdown: