# Importing other agents' sessions

A listing summarises each transcript cheaply. An import parses the chosen ones into a neutral shape, removes credentials, compares with the ledger, and writes native nodes with ids derived from the source, then records the result in the ledger.

| Module | Job |
| --- | --- |
| `claude_code.py`, `codex.py`, `deepseek_harness.py`, `antigravity.py`, `cursor.py`, `hermes.py` | Find, summarise and parse each format |
| `model.py` | Neutral shape: turns of user text and ordered reply blocks |
| `sanitize.py` | Drop host scaffolding, remove credentials |
| `writer.py` | Write turns as the DAG a native turn produces |
| `tool_names.py` | Other apps' calls as OpenProgram's own tools |
| `app_removals.py` | Archived or deleted in the app, archived here |
| `ledger.py` | What was imported where |
| `service.py` | `list_candidates`, `plan_imports`, `import_transcripts` |
| `live.py` | The loop that follows the apps as they write |
| `claude_live.py`, `codex_live.py` | A session read as it grows; what it is doing now |

Entry points: `openprogram sessions import`, `/api/sessions/import`, the Import settings tab. The CLI sends batches to a running Worker, else writes the store directly. Product page: [Session import](https://openprogram.io/docs/reference/session-import.html).

## Reading the formats

|  | Claude Code | Codex |
| --- | --- | --- |
| Files | `projects/<slug>/<id>.jsonl` | `sessions/YYYY/MM/DD/rollout-*.jsonl` |
| Source id | File name; `sessionId` is copied into forks | `session_meta.id` |
| Conversation order | Chain walked back from the newest record through `parentUuid` / `logicalParentUuid` | File order; compaction and forks do not rewrite it |
| Title | `custom-title`, then `ai-title`, then `summary` | `session_index.jsonl`, latest rename |
| Model, cwd | `message.model`, record `cwd` | `turn_context.model`, `session_meta.cwd` |
| Skipped | `isMeta`, `isSidechain`, compact summaries, API error records | Sub-agent rollouts, injected context blocks, encrypted reasoning |

A line that is not a JSON object, or a record still being written, is skipped; the rest of the file still imports.

## Decisions

| Choice | Why |
| --- | --- |
| Read the conversation the way its own agent resumes it | Claude Code's resume follows the parent chain from the newest record; Codex replays the rollout in order. The imported conversation is then the one the user last saw there, not abandoned branches. |
| Write native nodes, not an attachment | Search, export, rewind and continuing the conversation work unchanged. Tool calls whose tools do not exist here are replayed to the model as text. |
| Ids derived from agent, source id and turn index | Writing a turn twice is a no-op, so a grown source appends in place. Same principle as OpenCode's import, which keys an imported session by its original id. |
| Ledger with last fingerprint and head | Unchanged sources are skipped without a parse. A rewound source, or a session continued here, becomes a new session, so nothing already here is rewritten. |
| Listing recency from the last message | A running agent keeps appending bookkeeping records to a transcript whose conversation has not moved, so the import list sorts by the last message. The live sync wakes on any write instead: reading what was appended costs a fraction of a millisecond, and a turn whose text did not change is not written again. |
| Credentials removed with the request-redaction shapes | An imported turn is replayed to whichever model continues it. The high-precision shapes from `models/providers/request_hygiene/redaction.py` catch keys and tokens without rewriting prose that only mentions a key or a token; export's broader rules would. A title is cleaned before it is cut to length, since a key cut short no longer matches its shape; the listing's scan cache keeps its first message and titles cleaned too. Sign-in files are never opened. |
| Placed in the folder's project | Same as opening that folder here; the original cwd stays in `imported_from.cwd`. |
| `--dry-run` beside `--list` | `--list` shows every transcript and its state; `--dry-run` shows only what the same command would create or append to. It runs `plan_imports`, the same decision the import makes, so a rewound source shows as a new conversation, not an append. |
| Codex app conversations synced, not imported | The Codex app's and CLI's threads come in by themselves through `codex_sync.py`, which reuses this reader, writer and ledger but links each conversation to its Codex thread and appends turns made in the app, skipping turns OpenProgram ran on it; see [Harness engines](https://openprogram.io/docs/reference/design/integrations/harness-engines.html#synced). |
| Synced conversations' projects | Synced conversations of every app get their folder's project as an import does, except in a folder the app made for one chat (the Codex app's `~/Documents/Codex/<day>/…`, the Claude app's scratch workspaces) a temporary one, or a folder whose project the person removed, which stay in the default project. One synced before its folder got a project moves there once. |
| Messages sent from here | The person's own messages reach Codex, Claude Code and DeepSeek Harness as typed; messages that came through a channel, the owner's there included, keep OpenProgram's speaker envelope so the agent can tell who spoke. An envelope an earlier version sent is unwrapped when the transcript is read, and once in conversations already synced, their title too |
| Pictures | A picture the person sent in the app (Claude Code's base64 image block, Codex's `data:` image) is kept in the conversation's `media/` and shown where it sat, as a picture sent here is, and sent again when a turn here reads the message. One whose bytes the transcript lacks stays `[image]`. Conversations synced before get theirs once, a few per sync. |
| Pictures in peers | Cline keeps Claude Code's image blocks and drops Codex's pictures; Hermes Agent shows `[image]` and drops Codex's |
| The Claude app and DeepSeek Harness synced too | `app_sync.py` brings in the Claude app's Code tab conversations and DeepSeek Harness's (`deepseek_harness.py` reads its zstd event log) with the same ledger, and appends turns the app adds after whatever was said here; a conversation rewound in the app is left as it is here. Conversations started with `claude` in a terminal (`entrypoint: cli`) come in too. |
| Antigravity synced, both ways | `antigravity.py` reads the plain-text step log the desktop app and its `agy` command both keep (`brain/<id>/.system_generated/logs/transcript_full.jsonl`) and the name and folder from `conversation_summaries.db`, as magpie does. A conversation that goes on here goes on in the app, on its engine ([Harness Engines](https://openprogram.io/docs/reference/design/integrations/harness-engines.html#antigravity)). |
| Antigravity subagents | A subagent's conversation is read into the conversation at the top of its chain: what it did (each call, with its first argument) and said becomes the result of the call that started it, the one whose result names its id, else the last `invoke_subagent` or `browser_subagent` before it began. |
| Antigravity documents | A document Antigravity wrote for the person (a file in `brain/<id>/` beside its `.metadata.json`) shows in the reply as it reads now, after the last call that wrote it. |
| Cursor and Hermes synced | `cursor.py` reads the editor's agent chats from its `globalStorage/state.vscdb` (`composerData:` and `bubbleId:` rows, read-only and by key: the store is gigabytes) and `cursor-agent`'s from `~/.cursor/chats/*/*/store.db`; `hermes.py` reads Hermes Agent's `state.db` and each profile's, a compaction's continuation read as the same conversation. Both follow magpie; subagents' chats and hidden rows stay out. A `cursor-agent` chat and a Hermes conversation go on in their agent ([Harness Engines](https://openprogram.io/docs/reference/design/integrations/harness-engines.html#cursor)); an editor chat goes on in OpenProgram's own, since `cursor-agent` cannot resume it. |
| Cursor's busy store | Cursor writes its store all the time it runs, so a listing reads each chat's size and `lastUpdatedAt`, and the whole chat only of those that moved. |
| Their calls as OpenProgram's tools | A call with an OpenProgram counterpart is written as that tool, its arguments as that tool takes them (`run_command`, `run_terminal_command_v2` and `terminal` as `bash`; edits as `edit` with the text before and after), so its card shows a command, a diff or a checklist. A Cursor `edit_file_v2` names the file's text before and after by content id; both are read from its store. A call starting a subagent keeps its app's name. Conversations synced before are named again once. |
| Archived or deleted in the app | On every full pass a conversation its app archived or no longer has is archived here, and one it shows again comes back; one taken out of the archive here stays out. DeepSeek Harness, Antigravity, Cursor and Hermes: gone once the app lists it no more (an empty listing counts for nothing). Claude Code and Codex, which can be imported by hand: archived in the app, or its transcript deleted. |
| They continue in their agent | A DeepSeek Harness or Claude conversation is linked to its session on that agent's engine; the turns the engine ran are known by the id of their last assistant message or record and skipped. |

## Following the apps as they write

Three things wake the loop: file notices, a look every quarter second at files being written, and a full pass every minute. A wake reads only the lines appended, folds them onto the conversation, writes the turn here, running while the app still answers, and tells clients what each conversation is doing.

While the person works in the Claude app, `claude` in a terminal, Codex, DeepSeek Harness or Antigravity, the conversation here shows each block within a fraction of a second of the app writing it, its reply shows Thinking… and the running tool as a turn of OpenProgram's own does, and its sidebar row shows running.

| Choice | Why, and whose design |
| --- | --- |
| Woken by the file system, a hot-file look and a full pass | `watchfiles` gathers notices for 50 ms; magpie watches the same roots through FSEvents with a 10 ms latency. macOS tells of a write to a file held open only once it closes and Codex holds its rollout open (magpie's finding), so the files written in the last ten minutes are looked at every 250 ms, as Ping Island watches each transcript. A notice can be dropped, so everything is read again every minute, as magpie relists. |
| Only what was appended is read | The offset after the last whole line, trusted while the 64 bytes before it hash the same (`state/store/appended_lines.py`, shared with the usage reader; Filebeat's and Vector's fingerprint plus offset). A 470 MB transcript takes 2 s to parse and 2 s more to clean of secrets; a grown one takes under a millisecond. |
| New records folded onto the chain | Records that hang off the last one read are fed to the same fold the whole reading uses; one that hangs off an earlier record (a rewind, a fork) reads the file whole again. Turns before the last two keep only their fingerprint and ids, so a long session stays small. claude-code-ui tails the same way but replays history to rebuild state. |
| No waiting for a file to rest | Only whole lines are read, so a session is read as far as it is written. The 4 s rest and 10 s poll this replaces hid a turn until it ended. |
| Running, from Claude Code's registry first | `~/.claude/sessions/<pid>.json` says `busy` or `idle` for each live `claude`, its process checked alive (claudecodeui's liveness). The transcript says what it does: a prompt, a tool result or an `api-request` is thinking, an unanswered `tool_use` names the tool, `end_turn`, a stop-hook summary or an interruption ends it. Codex: `task_started` until `task_complete` or `turn_aborted`, an unanswered call names the tool. |
| Running, in DeepSeek Harness | `turn/start` until `turn/end`, a `tool-call` with no `tool/result` names the tool. The app appends each write as a zstd frame of its own, so only the whole frames after the last one read are read; a log that shrank or whose start changed is read again from the beginning. |
| Running, in Antigravity | The person's message, a tool's result or a reply whose calls are unanswered is running, a reply with no call ends it, and the conversation runs while a subagent it started still does, shown as that subagent. |
| Running, in Cursor and Hermes | The last turn's unanswered call is the tool running, its reply the end; their stores' write-ahead logs are the files looked at often. In every app a turn counts as running at most ten minutes after the last write. |
| No hooks | Hooks (claude-code-ui, Ping Island, Orca) add the one thing files lack, a wait for a permission answer, but run a command on every event of every session and edit the person's own settings. magpie installs none, and the person answers that prompt in the app they are using. |
| The turn written running | The reply is written with status `running` and each call without a result running, so the transcript draws it with the rows a turn here uses; when the app's turn ends it is written again, done. |
| Activity told apart from turns here | An `app_activity` frame, and the same field on each session-list row, not a run slot: the turn is not OpenProgram's to stop, and the slot's admission and cleanup belong to turns run here. |
| A message sent here meanwhile waits | Two processes writing one Claude Code session would fork it. A turn sent here on the Claude engine waits while the registry says the app's process is busy in that session, then a moment for the sync to write that turn, then plans its handoff from it. |
| Text a block at a time | Claude Code writes a message's blocks when the model's response is complete, so text arrives block by block; nothing that reads its files can show tokens. A harness on the [Model Gateway](https://openprogram.io/docs/reference/design/integrations/model-gateway.html) streams through the Worker itself. |

## Implementation status

- Only the default homes (or `$CLAUDE_CONFIG_DIR`, `$CODEX_HOME`) are scanned; a copied folder from another machine cannot be named on the command line.
- A session imported before credentials were removed keeps what it holds until its source grows; then only the last imported turn is rewritten clean. A turn's fingerprint is taken from its text as read, so redaction never turns such a source into a duplicate session.
