Codex Provider Sync
Overview
Use the installed codex-provider CLI from codex-provider-sync to repair Codex session visibility metadata. The tool updates rollout metadata, SQLite thread metadata, and project workspace cache data; do not manually edit only one of those stores unless the tool is unavailable and the user explicitly asks for manual repair.
Read references/behavior.md when you need command semantics, output interpretation, risk boundaries, or troubleshooting details.
Default Workflow
- Confirm the target Codex home. Default to
${CODEX_HOME} when set, otherwise ~/.codex. Pass --codex-home PATH only when the user gives a non-default home.
- Ensure the
codex-provider CLI is available:
- Run
command -v codex-provider on macOS/Linux or where codex-provider on Windows.
- If missing, follow
references/behavior.md#new-environment-installation before continuing.
- After installing or locating the CLI, run
codex-provider status to verify it starts.
- Run
codex-provider status first unless the user explicitly gave a backup restore path or a specific command to run.
- Read
Current provider, rollout provider counts, SQLite provider counts, project visibility diagnostics, locked rollout file count, encrypted content warnings, and backup root.
- Choose the narrowest command:
- Use
codex-provider sync when the user already switched provider/auth elsewhere and wants old sessions visible under the current provider.
- Use
codex-provider sync --provider <id> when the target provider is clear but config.toml should not be changed.
- Use
codex-provider switch <id> when the user wants the root model_provider changed and session metadata synced in one operation.
- Use
codex-provider restore <backup-dir> when the user wants to roll back a previous sync or synced to the wrong provider.
- Use
codex-provider prune-backups --keep <n> only for managed backup cleanup.
- Report the final provider, whether rollout files and SQLite are aligned, backup location for sync/switch operations, and any partial success caused by locked rollout files.
Commands
codex-provider status
codex-provider sync
codex-provider sync --provider openai
codex-provider switch apigather
codex-provider restore ~/.codex/backups_state/provider-sync/<timestamp>
codex-provider prune-backups --keep 5
With an explicit Codex home:
codex-provider status --codex-home /path/to/.codex
codex-provider sync --codex-home /path/to/.codex
codex-provider switch openai --codex-home /path/to/.codex
When the CLI is missing and Node.js 24+ is available:
npm install -g git+https://github.com/Dailin521/codex-provider-sync.git
codex-provider status
Safety Rules
- Treat
status as read-only.
- Expect
sync and switch to create backups under ~/.codex/backups_state/provider-sync/<timestamp>.
- Do not edit
auth.json, login state, message content, titles, or updated_at.
- Do not force old sessions into Codex Desktop's recent 50 by changing timestamps.
- Warn that histories containing
encrypted_content from another provider/account may become visible but can still fail on continue or compact with invalid_encrypted_content.
- If the CLI is missing, first check whether the user installed it globally or locally. Prefer using the installed
codex-provider command; otherwise install it with user approval or run it from a located local project.
Error Handling
- If
state_5.sqlite is currently in use, tell the user to close Codex, Codex Desktop/App, and app-server, then rerun the same command.
- If output reports skipped locked rollout files, treat the operation as partial success. List the skipped paths shown in output and tell the user to rerun
codex-provider sync after the active session ends.
- If
switch <provider-id> says the provider is unavailable, tell the user to define it in config.toml or switch auth/provider with their existing provider tool first, then run codex-provider sync.
- If
state_5.sqlite is malformed or unreadable, stop. Tell the user the tool refused to sync and that the database must be backed up, repaired, or restored before retrying.
1---2name: codex-provider-sync3description: Restore Codex historical session visibility after switching model_provider or provider/account. Use when Codex Desktop, Codex CLI /resume, or project recent sessions stop showing old conversations after a provider switch; when the user asks to resync Codex history, recover missing sessions, inspect provider/session metadata, install or run codex-provider-sync, switch provider and sync metadata, or restore a provider-sync backup.4---56# Codex Provider Sync78## Overview910Use the installed `codex-provider` CLI from `codex-provider-sync` to repair Codex session visibility metadata. The tool updates rollout metadata, SQLite thread metadata, and project workspace cache data; do not manually edit only one of those stores unless the tool is unavailable and the user explicitly asks for manual repair.1112Read `references/behavior.md` when you need command semantics, output interpretation, risk boundaries, or troubleshooting details.1314## Default Workflow15161. Confirm the target Codex home. Default to `${CODEX_HOME}` when set, otherwise `~/.codex`. Pass `--codex-home PATH` only when the user gives a non-default home.172. Ensure the `codex-provider` CLI is available:18 - Run `command -v codex-provider` on macOS/Linux or `where codex-provider` on Windows.19 - If missing, follow `references/behavior.md#new-environment-installation` before continuing.20 - After installing or locating the CLI, run `codex-provider status` to verify it starts.213. Run `codex-provider status` first unless the user explicitly gave a backup restore path or a specific command to run.224. Read `Current provider`, rollout provider counts, SQLite provider counts, project visibility diagnostics, locked rollout file count, encrypted content warnings, and backup root.235. Choose the narrowest command:24 - Use `codex-provider sync` when the user already switched provider/auth elsewhere and wants old sessions visible under the current provider.25 - Use `codex-provider sync --provider <id>` when the target provider is clear but `config.toml` should not be changed.26 - Use `codex-provider switch <id>` when the user wants the root `model_provider` changed and session metadata synced in one operation.27 - Use `codex-provider restore <backup-dir>` when the user wants to roll back a previous sync or synced to the wrong provider.28 - Use `codex-provider prune-backups --keep <n>` only for managed backup cleanup.296. Report the final provider, whether rollout files and SQLite are aligned, backup location for sync/switch operations, and any partial success caused by locked rollout files.3031## Commands3233```bash34codex-provider status35codex-provider sync36codex-provider sync --provider openai37codex-provider switch apigather38codex-provider restore ~/.codex/backups_state/provider-sync/<timestamp>39codex-provider prune-backups --keep 540```4142With an explicit Codex home:4344```bash45codex-provider status --codex-home /path/to/.codex46codex-provider sync --codex-home /path/to/.codex47codex-provider switch openai --codex-home /path/to/.codex48```4950When the CLI is missing and Node.js 24+ is available:5152```bash53npm install -g git+https://github.com/Dailin521/codex-provider-sync.git54codex-provider status55```5657## Safety Rules5859- Treat `status` as read-only.60- Expect `sync` and `switch` to create backups under `~/.codex/backups_state/provider-sync/<timestamp>`.61- Do not edit `auth.json`, login state, message content, titles, or `updated_at`.62- Do not force old sessions into Codex Desktop's recent 50 by changing timestamps.63- Warn that histories containing `encrypted_content` from another provider/account may become visible but can still fail on continue or compact with `invalid_encrypted_content`.64- If the CLI is missing, first check whether the user installed it globally or locally. Prefer using the installed `codex-provider` command; otherwise install it with user approval or run it from a located local project.6566## Error Handling6768- If `state_5.sqlite is currently in use`, tell the user to close Codex, Codex Desktop/App, and app-server, then rerun the same command.69- If output reports skipped locked rollout files, treat the operation as partial success. List the skipped paths shown in output and tell the user to rerun `codex-provider sync` after the active session ends.70- If `switch <provider-id>` says the provider is unavailable, tell the user to define it in `config.toml` or switch auth/provider with their existing provider tool first, then run `codex-provider sync`.71- If `state_5.sqlite` is malformed or unreadable, stop. Tell the user the tool refused to sync and that the database must be backed up, repaired, or restored before retrying.