Restore Codex Conversations
Restore local conversation visibility with a backup-first, evidence-driven workflow. Treat database rows, rollout metadata, the session index, and project mappings as one consistency set.
Safety rules
- Limit writes to the current computer's active Codex home, normally
%USERPROFILE%\.codex or $CODEX_HOME.
- Treat attached old system or project disks as read-only unless the user explicitly authorizes writes or path remapping on those disks.
- Preserve archived threads, subagent threads, original timestamps, cwd values, sandbox boundaries, and rollout history unless a verified compatibility requirement says otherwise.
- Back up the SQLite database consistently, the global state, the session index, and every target rollout before mutation.
- Derive
model_provider and cli_version from a currently visible official-account main thread. Never copy provider/version constants from examples.
- Request the required filesystem approval before writing outside the workspace. Do not work around a denied write.
- Never delete Electron Local Storage or Session Storage as a first-line recovery step.
Workflow
1. Establish scope
- Resolve the active Codex home and verify that
state_5.sqlite, .codex-global-state.json, session_index.jsonl, and sessions/ belong to the current installation.
- If the user requested diagnosis or explanation only, remain read-only and report the consistency gaps. Execute repairs only when the request authorizes restoration.
- If old disks are attached, distinguish the current Codex home from historical copies before any mutation.
2. Inspect before changing
- Read references/restore-project-conversations.md completely before performing a migration. For a read-only diagnosis, read the sections covering scope, template selection, target selection, and validation.
- Locate a usable
sqlite3 executable from --sqlite, $SQLITE3_PATH, or PATH rather than assuming one installation path.
- Count main, archived, and subagent threads separately.
- Verify every selected
rollout_path exists on the current computer and begins with {, not a UTF-8 BOM.
- Compare database main-thread IDs with
session_index.jsonl, thread-writable-roots, and thread-project-assignments.
- Select a current visible official main thread as the provider/version template.
3. Choose the repair path
Prefer scripts/restore_codex_conversations.js when the active schema matches the reference and the user requested restoration. Run it without --apply first; the default mode is a read-only preflight. Review the selected template and targets, then rerun with --apply only after the repair scope is confirmed.
Use the manual procedure in the reference when:
- the schema differs from the script's expected
threads columns;
- the target is a small, explicitly named subset;
- rollout metadata is malformed beyond the first line;
- project-path migration is also requested;
- the script's preflight validation fails.
Do not run the script if no currently visible official main thread exists; first ask the user to create one so the compatibility template is observable.
4. Execute narrowly
- Migrate unarchived main threads whose provider is incompatible with the current template.
- Exclude guardian, reviewer, and other subagent rows.
- Keep
source semantics, cwd, archived state, timestamps, and sandbox policy unless the current schema requires a documented change.
- Update only rollout line 1 when repairing
session_meta; preserve the remaining bytes.
- Write JSON and JSONL as UTF-8 without BOM.
- Add missing session-index rows without replacing existing human-friendly thread names.
- Add or repair
local-projects, thread-writable-roots, and thread-project-assignments using exact or longest-root matching.
- Never mechanically replace old drive letters with attached-disk drive letters.
5. Verify at every layer
- Run
PRAGMA integrity_check; use wal_checkpoint(TRUNCATE) after the client exits or PASSIVE while it remains open.
- Recount official-compatible, archived, and subagent rows.
- Parse each changed rollout first line and confirm the first byte is
7B.
- Parse every session-index line and the entire global-state JSON.
- Confirm backup and manifest files exist.
- If Codex thread tools are available, search for and read an old thread. Do not send it a new task merely to test restoration.
- Fully restart Codex Desktop, then verify the old conversation appears under its project and opens with historical turns.
Bundled resources
references/restore-project-conversations.md: detailed schema notes, SQL examples, backup requirements, project mappings, failure modes, and manual checklist.
scripts/restore_codex_conversations.js: deterministic migration used successfully on the source machine. It resolves the active Codex home and sqlite3 portably, defaults to a read-only preflight, dynamically chooses a current-account template, creates backups on --apply, updates compatibility metadata and mappings, and performs integrity checks.
Treat the script as a migration tool, not a Codex runtime dependency. Review its default paths and arguments on every new machine or client schema.
1---2name: restore-codex-conversations3description: Diagnose, back up, restore, and verify local Codex Desktop conversations whose rollout JSONL files still exist but disappear from the sidebar or project grouping after an account, model-provider, authentication, or client-version change. Use when Codex must inspect or repair state_5.sqlite, session_index.jsonl, rollout session_meta, .codex-global-state.json project mappings, or reuse the bundled recovery script. Do not use for cloud-chat export/import or for remapping project files between disks without an explicit path-migration request.4---56# Restore Codex Conversations78Restore local conversation visibility with a backup-first, evidence-driven workflow. Treat database rows, rollout metadata, the session index, and project mappings as one consistency set.910## Safety rules11121. Limit writes to the current computer's active Codex home, normally `%USERPROFILE%\.codex` or `$CODEX_HOME`.132. Treat attached old system or project disks as read-only unless the user explicitly authorizes writes or path remapping on those disks.143. Preserve archived threads, subagent threads, original timestamps, cwd values, sandbox boundaries, and rollout history unless a verified compatibility requirement says otherwise.154. Back up the SQLite database consistently, the global state, the session index, and every target rollout before mutation.165. Derive `model_provider` and `cli_version` from a currently visible official-account main thread. Never copy provider/version constants from examples.176. Request the required filesystem approval before writing outside the workspace. Do not work around a denied write.187. Never delete Electron Local Storage or Session Storage as a first-line recovery step.1920## Workflow2122### 1. Establish scope2324- Resolve the active Codex home and verify that `state_5.sqlite`, `.codex-global-state.json`, `session_index.jsonl`, and `sessions/` belong to the current installation.25- If the user requested diagnosis or explanation only, remain read-only and report the consistency gaps. Execute repairs only when the request authorizes restoration.26- If old disks are attached, distinguish the current Codex home from historical copies before any mutation.2728### 2. Inspect before changing2930- Read [references/restore-project-conversations.md](references/restore-project-conversations.md) completely before performing a migration. For a read-only diagnosis, read the sections covering scope, template selection, target selection, and validation.31- Locate a usable `sqlite3` executable from `--sqlite`, `$SQLITE3_PATH`, or PATH rather than assuming one installation path.32- Count main, archived, and subagent threads separately.33- Verify every selected `rollout_path` exists on the current computer and begins with `{`, not a UTF-8 BOM.34- Compare database main-thread IDs with `session_index.jsonl`, `thread-writable-roots`, and `thread-project-assignments`.35- Select a current visible official main thread as the provider/version template.3637### 3. Choose the repair path3839Prefer [scripts/restore_codex_conversations.js](scripts/restore_codex_conversations.js) when the active schema matches the reference and the user requested restoration. Run it without `--apply` first; the default mode is a read-only preflight. Review the selected template and targets, then rerun with `--apply` only after the repair scope is confirmed.4041Use the manual procedure in the reference when:4243- the schema differs from the script's expected `threads` columns;44- the target is a small, explicitly named subset;45- rollout metadata is malformed beyond the first line;46- project-path migration is also requested;47- the script's preflight validation fails.4849Do not run the script if no currently visible official main thread exists; first ask the user to create one so the compatibility template is observable.5051### 4. Execute narrowly5253- Migrate unarchived main threads whose provider is incompatible with the current template.54- Exclude guardian, reviewer, and other subagent rows.55- Keep `source` semantics, cwd, archived state, timestamps, and sandbox policy unless the current schema requires a documented change.56- Update only rollout line 1 when repairing `session_meta`; preserve the remaining bytes.57- Write JSON and JSONL as UTF-8 without BOM.58- Add missing session-index rows without replacing existing human-friendly thread names.59- Add or repair `local-projects`, `thread-writable-roots`, and `thread-project-assignments` using exact or longest-root matching.60- Never mechanically replace old drive letters with attached-disk drive letters.6162### 5. Verify at every layer6364- Run `PRAGMA integrity_check`; use `wal_checkpoint(TRUNCATE)` after the client exits or `PASSIVE` while it remains open.65- Recount official-compatible, archived, and subagent rows.66- Parse each changed rollout first line and confirm the first byte is `7B`.67- Parse every session-index line and the entire global-state JSON.68- Confirm backup and manifest files exist.69- If Codex thread tools are available, search for and read an old thread. Do not send it a new task merely to test restoration.70- Fully restart Codex Desktop, then verify the old conversation appears under its project and opens with historical turns.7172## Bundled resources7374- `references/restore-project-conversations.md`: detailed schema notes, SQL examples, backup requirements, project mappings, failure modes, and manual checklist.75- `scripts/restore_codex_conversations.js`: deterministic migration used successfully on the source machine. It resolves the active Codex home and `sqlite3` portably, defaults to a read-only preflight, dynamically chooses a current-account template, creates backups on `--apply`, updates compatibility metadata and mappings, and performs integrity checks.7677Treat the script as a migration tool, not a Codex runtime dependency. Review its default paths and arguments on every new machine or client schema.