Skip to main content
Atomic saves every session—messages, tool output, and worktree snapshots—in a session store. By default, sessions live in a local SQLite file (~/.atomic/workflows/journal.sqlite) and require no setup. Intercom keeps its own local files on each machine until you point machines at a shared database.

Local SQLite

Default single-machine store with zero setup, WAL concurrency, and low-level Node SQLite APIs.

JSONL

Plain text .jsonl files on one machine—easy to inspect, copy, or delete by hand.

PostgreSQL

Shared database for teams, CI fleets, and multi-machine Intercom, with PgBouncer and server tuning guides.

Custom adapters

Connect Atomic to another SQL or non-SQL database through your own adapter module.
Applications built on the SDK choose their store in code. See SDK session storage.
Two rules hold for every store:
  • No silent fallback. If the configured store fails to open, Atomic stops with an error rather than falling back to in-memory storage.
  • Subagents inherit the parent’s store. A subagent always writes to the same store as the session that launched it, regardless of its working directory or project settings. Subagent sessions are hidden from normal session lists. See Subagents.

Which store to choose

To move sessions between stores, see Exporting and importing sessions. Atomic 0.10.11 removed Turso and libSQL support; see Moving off libSQL.

Sharing storage across hosts

To share sessions and Intercom across machines, point every machine at the same PostgreSQL database with the same prefix. A prefix prepends a namespace to every table name so several teams can share one database without seeing each other’s data. Which setting you configure controls what is shared: Project settings (.atomic/settings.json) can choose where a project’s sessions go, never Intercom’s store. Sharing Intercom across machines enables multi-node routing: an agent on one machine can message an agent on another through the shared database. Atomic runs one Intercom broker per agent directory (usually one per machine or container). See Running Intercom across machines and Resume sessions on any machine.
  • Never put a local SQLite file on a network drive (NFS/SMB) or synced folder. File locks do not coordinate safely across hosts and can corrupt the database.
  • Database read access equals full session read access. A shared database holds sessions, tool output, worktree snapshots, and Intercom messages in transit. Grant database access only to people and services allowed to read those sessions.

Joining a machine to a shared database

Create the database and roles once with Set up the database, then connect each machine with Join a machine. atomic storage join <url> performs four steps:
  1. Validates the URL, adapter, and credentials, then runs SELECT 1 with a 15-second timeout. If any check fails, nothing is written.
  2. Copies --password-file into an owner-only file (~/.atomic/agent/storage-token.<id>, mode 600). A --token-file stays in place and is re-read for every new connection.
  3. Writes the top-level storage object (and prefix if --prefix is passed) to ~/.atomic/agent/settings.json, leaving all other settings untouched.
  4. Reports any environment variable or project setting that overrides the new configuration, and notes if a running Intercom broker still uses the previous store.
The URL must not include a password. Pass exactly one of --password-file <path>, --token-file <path>, or --auth azure|aws|gcp. atomic storage migrate --db <url> accepts the same authentication flags.
atomic storage join replaces any existing top-level storage setting without keeping a backup copy. Save your current storage value first if you still need it.

Checking the selected storage

Run atomic storage status in your project directory (or atomic storage status --json for scripts). For both sessions and Intercom, it reports:
  • the active store and where it came from (environment variable, project settings, global settings, or default);
  • any overridden or ignored selection (such as project settings in an untrusted project);
  • whether the adapter loads (15-second load timeout) and whether the database answers SELECT 1 (separate 15-second probe timeout), plus the server version on PostgreSQL or library version on SQLite;
  • the local Intercom broker state, active session count, multi-node routing status, and peer brokers sharing the database.
atomic storage status is read-only: it never creates files, directories, or tables, and opens local SQLite files read-only. It exits 1 when settings are unreadable, a selection is invalid, an adapter fails to load, or a database does not answer. Interactive sessions also warn at startup if the shared storage adapter fails to load.

Selecting storage per process

A launcher—such as a CI job or an app running atomic --mode rpc—can choose a store for one process without editing settings.json. Each option takes the same JSON object as the storage setting (adapter, options, secrets, prefix):
  • Pass --storage or --storage-file, not both.
  • An interactive session keeps --storage for its lifetime. Spawned child processes inherit environment variables (ATOMIC_STORAGE), not CLI flags.
  • Each agent directory runs one Intercom broker, which keeps the storage selection of the process that started it until it exits or atomic intercom restart replaces it. Project settings never select the broker’s store.

Which selection wins

For sessions, the first selection set wins (selections replace whole objects; fields are never merged):
  1. SDK options: sessionManager, then sessionStore, then createAgentSession({ storage })
  2. Session CLI flags: --session-store <file>, --no-session, or --session-dir <directory>
  3. Process CLI flags: --storage or --storage-file
  4. Session env vars: ATOMIC_SESSIONS_STORAGE or ATOMIC_CODING_AGENT_SESSION_DIR
  5. Shared env var: ATOMIC_STORAGE
  6. sessions.storage in settings
  7. storage in settings
  8. Default local SQLite file (~/.atomic/workflows/journal.sqlite)
Interaction rules:
  • Session flags (--session-dir, --session-store, --no-session) override --storage for sessions only; Intercom still uses --storage.
  • ATOMIC_CODING_AGENT_SESSION_DIR overrides ATOMIC_STORAGE for sessions only.
  • Combining a non-empty ATOMIC_CODING_AGENT_SESSION_DIR with ATOMIC_SESSIONS_STORAGE, --storage, or --storage-file fails startup with StorageConfigError (conflicting-overrides). Unset one of them or pass a session flag.
  • Relative path, dir, and secrets.file values resolve against the storage home. Relative adapter paths resolve from the agent directory. Relative --storage-file paths resolve from the current working directory. Empty environment variables count as unset.
Atomic validates --storage, --storage-file, ATOMIC_STORAGE, and ATOMIC_SESSIONS_STORAGE before any session starts, even when a higher-precedence selection wins. Invalid JSON, unknown fields, unreadable files, libSQL selections, or removed team-profile variables (ATOMIC_PROFILE, ATOMIC_TEAM_*) stop the CLI with exit code 1 and make the SDK throw StorageConfigError. Error messages name the variable or flag, never a secret.

Keeping credentials safe

  • Process-level options come from the launcher, so they apply even in an untrusted project (see Security).
  • Adapter modules run code with Atomic’s privileges. Select only adapters you trust.
  • Put passwords and tokens in secrets, never in options.
  • Prefer --storage-file or an environment variable over --storage for sensitive config—other local users can inspect command-line arguments.
  • In the SDK, inMemorySecret(value) keeps a secret in memory only. It serializes as [redacted] and is refused in settings, flags, and environment variables.

Storage home

Relative paths in storage settings (path, dir, secrets.file), relative --storage / ATOMIC_STORAGE paths, and shared repos/ and worktrees/ directories resolve against the storage home: An older layout stored a custom agent directory’s session database in its parent directory. When an older profile upgrades, the first profile that finds an existing parent session database continues using it and prints a one-time notice; profiles with their own database keep theirs. Relative secrets.file paths also fall back to an existing file in the parent directory. To share one local store across profiles intentionally, use absolute paths. A profile never takes over the store of a directory that other users share, one any user may write to or with the sticky bit set like /tmp, nor of a directory with more than 50,000 entries: it uses its own store there. A .atomic-storage-parent-owner claim already in such a directory is still honored, but is not made again once deleted. The profile that continues using a parent store is recorded in .atomic-storage-parent-owner in the parent directory, by its path and by an ID kept in .atomic-storage-owner-id in the profile. Each time the profile starts, Atomic records where it is in ~/.atomic/agent/storage-owners, one small file per ID, so a profile moved or renamed within its parent directory is found at once, however many entries that directory has. A copy of a profile gets an ID of its own. If the profile cannot be found that way, as with a claim written by an earlier version, or a profile copied to another file system, Atomic looks through the parent directory’s entries to find it. When none of them is that profile, Atomic records in the claim that its owner is missing, so later starts skip the search while the parent directory stays the same directory. A copy of the directory is searched again. If the profile comes back under another name, it uses the store again the next time it starts. If the parent directory is read-only, Atomic keeps that result in memory until an entry of the directory changes. Atomic checks at most 50,000 entries for at most 1 second, both for that search and for the check of whether another profile in the directory uses its store. Past either limit, the agent directory uses its own store. When the search for a claim’s profile stops at the limit, Atomic records that in the claim, and later starts skip the search for a day, unless the claim changes or the directory is copied. A read-only directory keeps the result in memory. Atomic reports why the search stopped once a day per claim, as a process warning and, in debug mode, in the debug log; it notes when it last did so in ~/.atomic/agent/storage-notices. To skip the search in a large directory such as /tmp, delete .atomic-storage-parent-owner if its profile is gone, or replace the file’s contents with the profile’s new absolute path. atomic storage status never creates a missing agent directory. A read-only agent directory works as long as the storage home is writable.

Locks in the agent directory

Processes sharing an agent directory coordinate writes to settings.json, auth.json, project trust decisions, and session claims through adjacent lock files. If a process exits while holding a lock, the next process takes it over.
Agent-directory locks work only between processes on one machine accessing the same local filesystem. Do not share an agent directory:
  • across machines via NFS, SMB, or a cloud-synced folder;
  • on one machine across both a host path and a container volume or bind mount.
Give each machine or container its own directory via ATOMIC_CODING_AGENT_DIR, and share state through a PostgreSQL database.
If Atomic warns that it cannot open or remove a lock file (such as settings.json.lock.takeover.lock), another user usually owns it—often from a previous sudo run. Fix ownership or delete the lock file (for example, sudo chown $USER ~/.atomic/agent/settings.json.lock.takeover.lock). Until resolved, Atomic takes over a stale lock after 10 seconds.

Tuning for many concurrent agents

Write concurrency depends on the store:
  • PostgreSQL: writes to different sessions run in parallel up to each process’s connection pool limit; writes to the same session wait in line. See Tuning for many concurrent agents and Server tuning.
  • Local SQLite: one writer at a time across the database file, with no settings.json knob to change. See Tuning local SQLite.
  • JSONL: writes to different sessions run in parallel; writes to the same session wait in line. Nothing to configure. See Several Atomic processes.

Exporting and importing sessions

atomic storage export <dir> writes sessions to portable JSONL files (one per session), and atomic storage import <dir> loads them into a target store. Use them to migrate between stores, move sessions to another machine, or cache sessions between CI runs.
Both commands also accept an optional --sessions compatibility flag (a no-op, because sessions are all they transfer). Each exported file is a complete, standalone copy of one session—including every branch, tool output, worktree snapshot, and the full inherited history of any shared-history fork. Importing writes standalone sessions, so deleting originals never affects imported copies.

Layout

Session IDs are URL-encoded (encodeURIComponent(id)) in filenames so IDs containing special characters stay portable. Import reads only *.jsonl files in <dir>/sessions and ignores everything else (including temporary files from an interrupted export). If <dir>/sessions does not exist, import adds nothing.

Export

By default, export writes every session across all projects, including hidden subagent sessions so subagent history travels with its parent. Export writes each file to a temporary path and atomically renames it when complete. Unchanged files are skipped, and existing files in <dir> are never deleted—prune old exports yourself.

Import

Import validates every file before writing anything. A malformed line, unsupported format version, or conflicting history stops the import with the filename and line number before any data changes. For each file (matched by session ID):
  • Sessions absent from the store are added.
  • Sessions present with fewer entries receive the newer entries.
  • Sessions already up to date are skipped.
Importing the same directory twice is safe and idempotent. If a write fails partway through, import exits 1 and lists which sessions succeeded and which did not (StorageImportIncompleteError in the SDK); re-run the same command to finish. Imported sessions work immediately with --session, /resume, and history://sessions.

Selecting storage for export and import

By default, both commands use the store selected in the current directory. They refuse when that store is a shared database or in-memory store (machines on a shared database already see its sessions). To export from or import into a specific store—including a shared PostgreSQL database—pass --storage <json> or --storage-file <path>:
  • A relative path in --storage / --storage-file resolves against the current directory, not the storage home. Make relative SQLite paths from settings.json absolute first. A relative secrets.file still resolves against the storage home so atomic storage join’s password file works as-is.
  • JSONL { "dir": "..." } and empty {} selections are refused with --storage / --storage-file. (To export from a JSONL directory selected via --session-dir, set ATOMIC_SESSIONS_STORAGE instead; see Move to SQLite or PostgreSQL.)
Example—copying local SQLite sessions into a new PostgreSQL database:

Session file format and redaction

Export files use session format version 4 (the same format as JSONL directories and atomic --import <file>). Line 1 is the session header, and each subsequent line is an entry in append order:
Files contain every branch of the session. Tool output and worktree snapshot blobs are embedded once each in base64 and verified by SHA-256 on import. You can redact secrets (for example replacing a token with ***) before sharing an export file, provided every line remains valid JSON in its original order and you keep these fields unchanged:
  • Header: type, version, id, and createdAt (cwd determines the project).
  • Every entry: id, parentId, and type.
  • Every base64 value and blobs object (hash-verified on import).

Persisting sessions between CI runs

On a CI runner that caches $STATE_DIR between jobs:
Use --since or --limit to bound cache size, and resume an imported session with atomic --session <id>.

Moving off libSQL

Atomic 0.10.11 removed libSQL support (Turso, self-hosted sqld, and libSQL file: databases). To migrate existing sessions to PostgreSQL or local SQLite, export them with 0.10.11-alpha.2 (the last release that reads every libSQL schema, including stores upgraded for shared-history forks) and import them with your current release. Forks retain their full history and worktree snapshots keep their content. Before you start:
  • Export before running atomic storage join, which overwrites the libSQL storage setting.
  • Run the migration once from a single machine. Other machines sharing that database only need to upgrade Atomic and join the new database.
  • Requires Node.js with npx (matching Atomic’s minimum Node.js version) to run @bastani/[email protected].
  • Only sessions transfer. Undelivered Intercom messages are left behind, and forks import as full copies (using more space than shared forks).
1

Save the libSQL setting to a file

Extract your top-level storage setting (or .sessions.storage if libSQL was configured there):
If you already overwrote the setting, create old-storage.json manually:
2

Export sessions with Atomic 0.10.11-alpha.2

If it reports Cannot find module '@bastani/atomic-storage-libsql', install that version’s adapter and re-run the export:
3

Import into PostgreSQL or local SQLite

To move to PostgreSQL, set up the database, join it, and import by name:
To keep sessions on this machine, remove the libSQL storage (and any libSQL sessions.storage) entries from ~/.atomic/agent/settings.json, then import into default local SQLite:
4

Verify and remove the old adapter

Confirm atomic storage status shows the new store and atomic -r lists your project’s sessions, then uninstall the retired adapter:
Until you remove libSQL references (or legacy ATOMIC_PROFILE / ATOMIC_TEAM_* variables), Atomic exits with a libsql-removed configuration error pointing to this section.

Size limits

Long sessions, large pasted logs, inline images, and large worktree snapshots work across every store because Atomic splits large payloads into chunks automatically. Search indexing limits differ by search surface:
  • /resume picker search indexes up to 65,536 characters (64K UTF-16 code units) per user or assistant message so session listings stay compact.
  • history:// search indexes entries up to 8,388,608 characters (8M characters) across rendered content and scans any larger entry directly on demand.
If a single database value still exceeds the backend’s limit (~1 GB per value on local SQLite and PostgreSQL), the write fails with StoragePayloadTooLargeError (not retryable). Reduce the value size or raise the limit on a custom backend. For older local SQLite files that need offline snapshot chunk-table migration, see Moving snapshot data in an old SQLite file.

Upgrading older stores

Some Atomic releases perform one-way store layout upgrades that earlier versions cannot read:
  • Large session entries: Saving a session entry over 1 MiB on Atomic 0.9.88 or later upgrades the store; older releases then fail with StorageSchemaVersionError.
  • Shared-history forks: Atomic 0.10.11+ upgrades stores for shared-history forks once no earlier release has an open session on the store. See Older Atomic versions.
Upgrade all machines sharing a database together.

Moving snapshot data in an old SQLite file

Earlier Atomic versions stored worktree snapshot chunks in an older table layout. On local SQLite files, Atomic migrates those chunks automatically in the background when enough free disk space is available. If free disk space is tight (so the WAL file cannot hold a single-pass copy), or if SQLite refuses the automatic ALTER TABLE RENAME because of a custom view or trigger referencing the old chunk table, run the offline batched migration:
1

Stop all Atomic processes using the SQLite file

Ensure every session and Intercom broker targeting the database has closed cleanly so its -wal file is empty. If SQLite reported a view or trigger blocking the rename, drop or update that view/trigger first.
2

Run the batched chunk migration

The file must be a local SQLite database in WAL mode without auto_vacuum=FULL. PostgreSQL databases do not need this step.
After a crash, never delete a SQLite -wal file by hand—doing so can lose committed data or corrupt the database. Open the database with Atomic or SQLite first so WAL recovery completes cleanly.

Shared-history forks

When you fork a session (/fork, /clone, atomic --fork, or a subagent with context: "fork"), SQLite and PostgreSQL stores do not duplicate the parent’s history. The fork shares the parent’s prior entries and stores only new entries added after the fork.
  • Fast and compact: Forking a long session takes the same time as a short one and adds minimal storage overhead.
  • Zero setup on SQLite: Handled automatically. On PostgreSQL, run atomic storage migrate once as the owner role (see Older Atomic versions).
  • Independent copy semantics: A fork shows the parent’s history up to the fork point only. Later edits or deletes on the parent never alter the fork—before modifying shared history, Atomic detaches affected parts for forks, and deleting a parent hides it immediately while retaining shared segments until no fork needs them.
  • Full copies on export: Anything that exports a fork out of its store writes a self-contained copy: /export, /share, atomic storage export, and cross-store forks. (atomic --export <file> only converts an existing .jsonl file on disk to HTML and does not read SQLite or PostgreSQL stores.)
JSONL directories and in-memory stores always write full copies on fork.

Older Atomic versions

Shared-history forks require Atomic 0.10.11 (or 0.10.11-alpha.2) or newer. Once a store upgrades, earlier releases refuse to open it with Unsupported sessions storage schema version 3.
  • Atomic upgrades a store automatically on open once no earlier release has an active session on it across any machine (crashed sessions expire after about a minute). Until then, forks remain full copies so older releases continue working.
  • On PostgreSQL, the least-privilege runtime role cannot create the shared-fork tables. Forks stay full copies without error until the owner runs atomic storage migrate.
To upgrade cleanly: upgrade every machine sharing the database to 0.10.11+, then run atomic storage migrate as the owner role on PostgreSQL. To move sessions back to an earlier release after an upgrade, run atomic storage export (which writes full copies) and import them into a fresh store with the older release. With debug mode enabled, Atomic logs why an upgrade was deferred.

Workflow data from earlier releases

Releases before 0.10.0 stored workflow runs under workflows/journal/, workflows/pool/, workflows/runs/, and wf_* tables. Atomic no longer runs those workflows and leaves their data untouched so downgrading remains safe:
  • atomic storage status, migrate, export, and import operate on sessions and Intercom only. On PostgreSQL, atomic storage migrate still moves existing wf_* tables from public to atomic so a database is not split across schemas.
  • Worktree snapshot garbage collection continues preserving snapshots referenced by old workflow runs.
  • atomic storage adopt, consolidate, --workflows, --run, --unfinished, ATOMIC_WORKFLOWS_JOURNAL, ATOMIC_WORKFLOW_JOURNAL_PATH, workflows.journal, and createAgentSession({ journal }) no longer select a store.
To migrate legacy workflow definitions, see Migrating workflows.

Storage errors

This reference covers the typed errors Atomic raises from storage operations. In code, inspect the error class, code, and structured fields rather than matching message text. Unless noted otherwise, classes are exported from @bastani/atomic/storage (and re-exported from @bastani/atomic).

Common errors

Session errors

Other session errors: SessionNotFoundError (sessionId), SessionExistsError (sessionId), SessionIdMismatchError (requested, found), SessionConflictError (sessionId, expectedSeq, actualSeq), SessionFormatVersionError (path, found, supported), SessionInvalidTextError (field, reason), SessionInvalidTimestampError (field, reason, value), and JsonlStoragePoisonedError (location, cause, rollbackCause). After SessionConflictError, another process wrote first—reopen the session before writing again.
When a live PostgreSQL session is waiting to save: Leave it running if you see Waiting for PostgreSQL to save this session. Atomic keeps retrying pending saves in order, even in print and JSON modes. See What to do while PostgreSQL is unavailable for notices, wait settings, and a PgBouncer example.When a save fails instead of waiting: Atomic reports could not persist the <role> message along with the reason and stops the current run. Print and JSON modes exit 1. Interactive mode stays open so you can fix the reported problem and try again.

Database handle errors

Raised by direct SqliteDatabase handles opened in SDK applications. The first four apply to local SQLite handles only (see SDK and local SQLite API).

Handling errors in code

  • Cross-process type guards: isStorageConfigError, isStorageWriteLockTimeoutError, isStorageUnsupportedOperationError, isStorageWriterQueueDegradedError, isStorageWriterQueueUnusableError, isStorageTransientError, isSessionBlobError, isSessionSpillError, and isStorageError. Code lists: STORAGE_TRANSIENT_ERROR_CODES, SESSION_BLOB_ERROR_CODES, and SESSION_SPILL_ERROR_CODES.
  • Cause-chain inspection: findStorageWriteLockTimeoutError(error) and isRetryableStorageError(error) inspect up to 8 levels of cause.
  • Cross-process serialization: serializeStorageError(error) and rehydrateStorageError(json) preserve class, fields, cause, rollbackCause, and cleanupCause. Unknown subclasses rehydrate as StorageError retaining name, code, and fields.
  • Cancellation: Session listings accept an AbortSignal and reject with the signal’s reason (such as AbortError).

Errors from atomic storage join

atomic storage join, atomic storage migrate --db, atomic team status, and the SDK’s getTeamProfile() raise TeamProfileConfigError (invalid inputs; nothing changed) or TeamProfileError (runtime failure after inputs validated). Error messages name variables, flags, and file paths, never credentials. TeamProfileError carries code, subject, hint, retryable, and optional detail and cause: In code, check these across processes with isTeamProfileError(), isTeamProfileTimeoutError(), isTeamProfileConfigError(), and isRetryableTeamProfileError() (walks up to 8 levels of cause). Use serializeTeamError(error) and rehydrateTeamError(json) to pass them across processes without credentials. POSTGRES_STORAGE_JOIN_HINT holds atomic storage join <postgres-url> --password-file <path>.