Skip to main content
JSON mode runs one or more positional prompts in sequence (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 @file attachments: Like Print mode, JSON mode accepts piped stdin (git diff | atomic --mode json "Review this diff") and @file or 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 through atomic.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 set ATOMIC_STORAGE or ATOMIC_SESSIONS_STORAGE in 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:
When resuming a session whose worktree blueprint build is running in another process, a blueprint_build_waiting event can also arrive before the session header. Session events follow as they occur:
Unlike RPC mode, JSON mode does not add 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 message property is stripped (unlike the in-memory AgentSessionEvent delivered to SDK subscribers). Read the final message from message_end.
  • assistantMessageEvent.partial is stripped.
  • parentToolCallId is omitted on message_update wire lines (message_update carries only type, usage, assistantMessageEvent, and optional endTurn).
  • When assistantMessageEvent.type is "toolcall_start", Atomic injects id and toolName directly on assistantMessageEvent.
  • Top-level usage carries the latest cumulative provider-reported token usage (which may stay zero until completion if the provider reports usage only at the end).
  • Top-level endTurn is included only when the provider reported an explicit end-of-turn signal (AssistantMessage.endTurn, such as OpenAI Codex end_turn).
A non-assistant message on 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":
In --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 outside AgentSessionEvent:
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.form is "cleared" when the context window was cleared and "compacted" when a compactor model or extension replaced it. willRetry: true means Atomic will automatically retry the interrupted turn (for example after context overflow). If overflow recovery is exhausted, unresolvedOverflow: true and errorMessage are set; check result and errorMessage independently 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 no compaction_usage when clearing.
  • agent_end vs. agent_settled: agent_end finishes one low-level agent loop while automatic retries (retryPending: true), compaction recovery, or queued messages may still continue. Wait for agent_settled when tracking full turn-chain completion.
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 with jq:
Stream text deltas live as they arrive: