atomic --mode json "First prompt" "Second prompt"), writes every session event as one JSON line to stdout, and exits. Use it for shell scripts, CI pipelines, and batch jobs that need structured output without interactive follow-up commands.
Need to send follow-up commands to a live process or embed Atomic in Node.js? Compare Print mode, JSON mode, RPC mode, and the TypeScript SDK on Choose an integration mode.
Input, prompts, and storage isolation
- Piped stdin and
@fileattachments: Like Print mode, JSON mode accepts piped stdin (git diff | atomic --mode json "Review this diff") and@fileor image arguments, merging piped stdin ahead of positional prompt text. - Extension commands as prompts: Positional prompts may invoke extension commands (such as
"/mycommand"). If an extension command queues turns throughatomic.sendMessage(), JSON mode waits for those queued turns to settle before continuing to the next prompt or exiting. - Per-process storage isolation: Pass
--storage '<json>',--storage-file <path>, or--session-store <path>(with optional--session-prefix <prefix>), or setATOMIC_STORAGEorATOMIC_SESSIONS_STORAGEin the environment, to isolate script or CI runs without changing saved settings. See Selecting storage per process.
If a saved default
provider/model names an unsupported provider or a storage override fails with StorageConfigError, JSON mode writes the diagnostic to stderr and exits with code 1. Stdout can contain loading events, but not a model reply. Supported providers with an unknown model or missing credentials fall back through normal model selection.Output format
Each line on stdout is one JSON object terminated by\n. Loading events come before the session header. Look for type: "session" rather than assuming it’s the first line. With --no-session the header describes the in-memory session:
blueprint_build_waiting event can also arrive before the session header.
Session events follow as they occur:
entryId or seq fields to message_end.
Streaming message_update wire format
On the wire, message_update omits cumulative snapshots to keep streaming lines compact:
- The top-level
messageproperty is stripped (unlike the in-memoryAgentSessionEventdelivered to SDK subscribers). Read the final message frommessage_end. assistantMessageEvent.partialis stripped.parentToolCallIdis omitted onmessage_updatewire lines (message_updatecarries onlytype,usage,assistantMessageEvent, and optionalendTurn).- When
assistantMessageEvent.typeis"toolcall_start", Atomic injectsidandtoolNamedirectly onassistantMessageEvent. - Top-level
usagecarries the latest cumulative provider-reported token usage (which may stay zero until completion if the provider reports usage only at the end). - Top-level
endTurnis included only when the provider reported an explicit end-of-turn signal (AssistantMessage.endTurn, such as OpenAI Codexend_turn).
message_update is treated as a protocol violation; Atomic throws instead of emitting fabricated usage.
Event reference
Session and agent events
Final assistant messages and tool results include optional
durationMs timing. On tool_execution_end, durationMs measures how long execute() ran with a monotonic clock and is omitted when the tool did not execute.
PostgreSQL storage reconnection (session_storage_reconnect)
When session storage is backed by PostgreSQL and a connection drops or refuses writes, Atomic holds the session’s ordered write queue until PostgreSQL reconnects. After 10 seconds (and every 60 seconds thereafter), it emits session_storage_reconnect with state: "waiting"; once saved after a reported wait, it emits state: "recovered":
--mode json, Atomic also writes a human-readable Warning: or Info: line to stderr while keeping stdout strictly JSONL.
Runner-level blueprint build events
When resuming a session whose worktree blueprint build is running in the background (see Start the first turn while the build runs), the CLI runner emits two events outsideAgentSessionEvent:
blueprint_build_waiting can arrive before the session header when waiting on another process’s build of the same worktree. notices is empty when the build completes cleanly (in -p text mode, those warnings go to stderr as Warning: ...).
Compaction and retry details
- Automatic compaction:
compaction_end.result.formis"cleared"when the context window was cleared and"compacted"when a compactor model or extension replaced it.willRetry: truemeans Atomic will automatically retry the interrupted turn (for example after context overflow). If overflow recovery is exhausted,unresolvedOverflow: trueanderrorMessageare set; checkresultanderrorMessageindependently because both can appear when a boundary saved before the next request still exceeded the provider’s input limit. - Branch summaries vs. compaction: Branch summaries use the retry policy and emit
summarization_retry_*events. Compaction does not retry a failing compactor call; it clears context instead and emits nocompaction_usagewhen clearing. agent_endvs.agent_settled:agent_endfinishes one low-level agent loop while automatic retries (retryPending: true), compaction recovery, or queued messages may still continue. Wait foragent_settledwhen tracking full turn-chain completion.
TypeScript AgentSessionEvent union (SDK reference)
TypeScript AgentSessionEvent union (SDK reference)
In-memory SDK events follow
AgentSessionEvent exported from @bastani/atomic. On the --mode json wire, message_update is rewritten to { type: "message_update", usage, assistantMessageEvent, endTurn? } (stripping message, assistantMessageEvent.partial, and parentToolCallId):Message types
Base messages come from@bastani/atomic-ai: UserMessage, AssistantMessage, and ToolResultMessage.
Atomic extends AgentMessage with three additional roles (documented with full JSON shapes in RPC protocol types and Session format):
BashExecutionMessage(role: "bashExecution")CustomMessage(role: "custom")BranchSummaryMessage(role: "branchSummary")
Exit codes and signals
A second termination signal forces immediate exit. JSON mode waits for in-progress background worktree blueprint builds to settle before exiting.
Filtering examples
Extract final assistant text withjq: