> ## Documentation Index
> Fetch the complete documentation index at: https://docs.bastani.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Export and import sessions

> Copy Atomic sessions between stores, machines, and CI runs with atomic storage export and atomic storage import.

Use this guide if you move Atomic sessions from one store to another, copy them to another machine, or keep them between CI runs. By the end of this page, you can export sessions to portable JSONL files, import them into a supported target store, choose which store each command reads or writes, and redact an export before you share it. To choose a store in the first place, see [Storage](https://docs.bastani.ai/storage.md).

`atomic storage export <dir>` writes sessions to portable JSONL files (one per session), and `atomic storage import <dir>` loads them into a target store. Both commands take a folder and an optional store selection:

```bash theme={null}
atomic storage export <dir> [--limit <n>] [--since <time>] [--storage <json> | --storage-file <path>]
atomic storage import <dir> [--storage <json> | --storage-file <path>]
```

Both commands also accept an optional `--sessions` compatibility flag, which does nothing, 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](https://docs.bastani.ai/storage.md#shared-history-forks). Importing writes standalone sessions, so deleting originals never affects imported copies.

## Export folder layout

An export folder holds one file per session:

```text theme={null}
<dir>/
  sessions/<encodedSessionId>.jsonl   one session per file
```

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 sessions

By default, `atomic storage export` writes every session across all projects, including hidden subagent sessions so subagent history travels with its parent.

The following options limit which sessions it writes:

| Option | Effect |
| - | - |
| `--limit <n>` | Export only the `n` most recently modified sessions (`n >= 1`). |
| `--since <time>` | Export only sessions modified at or after `<time>`. A bare date like `2026-11-01` means midnight UTC; a date-time without a zone (`2026-11-01T09:30:00`) uses local time. Add `Z` or an offset (`2026-11-01T09:30:00Z`) to be explicit. |

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 sessions

`atomic storage import` validates every file before it writes anything. A malformed line, unsupported format version, or conflicting history stops the import with the filename and line number before any data changes.

Import matches each file to a session by session ID, then does the following:

* 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`.

## Choose the store to export from or import into

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 with `--session-dir`, set `ATOMIC_SESSIONS_STORAGE` instead; see [Move to SQLite or PostgreSQL](https://docs.bastani.ai/storage/jsonl.md#move-to-sqlite-or-postgresql).)

To copy local SQLite sessions into a new PostgreSQL database:

1. Export the sessions from the local store:

   ```bash theme={null}
   atomic storage export ~/moved
   ```

2. Save the runtime role's password to a private file, join the database, and delete the file. `atomic storage join` keeps its own copy:

   ```bash theme={null}
   (umask 077; printf 'Runtime password: '; read -rs password; printf '\n'; printf '%s' "$password" > ~/atomic-db-password)
   atomic storage join 'postgresql://atomic_runtime@db.example.com:5432/atomic' --password-file ~/atomic-db-password
   rm ~/atomic-db-password
   ```

3. Save the new `storage` setting to a file, and import the sessions into that store:

   ```bash theme={null}
   jq .storage ~/.atomic/agent/settings.json > new-storage.json
   atomic storage import ~/moved --storage-file new-storage.json
   ```

Confirm that `atomic storage status` names the PostgreSQL store and that `atomic -r` lists your project's sessions.

## Export 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 later line is an entry, in the order it was appended. For example:

```json theme={null}
{"type":"session","version":4,"id":"...","createdAt":"2026-11-12T09:30:00.000Z","cwd":"/repo"}
{"type":"message","id":"a1b2c3d4","parentId":null,"timestamp":"2026-11-12T09:30:05.000Z","message":{"role":"user","content":"..."}}
```

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).

## Keep sessions between CI runs

On a CI runner that caches `$STATE_DIR` between jobs, import the cached sessions at the start of the job and export them at the end:

```bash theme={null}
# Start of the job, after cache restore
mkdir -p "$STATE_DIR" && atomic storage import "$STATE_DIR"

# ... run Atomic ...

# End of the job, before cache save
atomic storage export "$STATE_DIR"
```

Use `--since` or `--limit` to bound cache size, and resume an imported session with `atomic --session <id>`.

## What's next

* [Storage](https://docs.bastani.ai/storage.md): choose a store and share it across machines.
* [Session file format](https://docs.bastani.ai/session-format.md): every entry type an export file can hold.
* [Storage errors](https://docs.bastani.ai/storage/errors.md): what `StorageTransferError` and `StorageImportIncompleteError` mean.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.