Migrating Codex History
Overview
Reuse scripts/migrate_openai_history_to_aigate.sh to copy local Codex session history from one model_provider to another.
Script source priority:
- local repository path:
scripts/migrate_openai_history_to_aigate.sh - remote raw URL:
https://raw.githubusercontent.com/GcsSloop/ai-gate/main/scripts/migrate_openai_history_to_aigate.sh
Default behavior:
- source provider:
openai - target provider:
aigate - codex home:
~/.codex
The migration copies sessions. It does not overwrite the original source sessions.
When To Use
- The user wants official Codex or OpenAI sessions to appear under the current AI Gate provider.
- The user asks to migrate, duplicate, sync, or re-home Codex history between providers.
- The user wants a dry run before changing local session files.
Do not use this skill for remote exports, cloud backups, or non-Codex history formats.
Workflow
- Resolve the script path:
- if
scripts/migrate_openai_history_to_aigate.shexists in the current repository, use it - otherwise download
https://raw.githubusercontent.com/GcsSloop/ai-gate/main/scripts/migrate_openai_history_to_aigate.shto a temporary file and use that file
- if
- Detect the operating system:
- on macOS or Linux, the shell script can be executed directly
- on Windows, do not try to execute the
.shfile as-is; first convert the script logic into equivalent PowerShell or native Windows command steps, then run the Windows-adapted workflow
- Run a dry run first unless the user explicitly asks to skip it.
- Show the migration summary before making changes.
- Run the real migration with the approved options.
- Report the final summary and call out whether
state_5.sqliteandsession_index.jsonlwere updated.
Commands
If the repository is already present locally:
bash scripts/migrate_openai_history_to_aigate.sh --dry-run
If the repository is not present locally, download the script first:
tmp_script="$(mktemp)"
curl -fsSL "https://raw.githubusercontent.com/GcsSloop/ai-gate/main/scripts/migrate_openai_history_to_aigate.sh" -o "$tmp_script"
chmod +x "$tmp_script"
bash "$tmp_script" --dry-run
For Windows users:
- treat the downloaded
.shas the source of truth for migration behavior - translate its file scanning, JSON patching, UUID generation, and SQLite/session index updates into PowerShell before execution
- do not claim Windows support by directly invoking the shell script unless the environment explicitly provides a compatible Unix shell and the required tools
Default migration:
bash scripts/migrate_openai_history_to_aigate.sh
Migrate to a custom provider:
bash scripts/migrate_openai_history_to_aigate.sh \
--from-provider openai \
--to-provider router \
--dry-run
Align migrated source fields with the source-provider sessions:
bash scripts/migrate_openai_history_to_aigate.sh --sync-source-from-provider
Skip archived history:
bash scripts/migrate_openai_history_to_aigate.sh --skip-archived
Requirements
jquuidgencurlwhen downloading the remote script- optional
sqlite3forstate_5.sqlitesource reconciliation - on Windows, equivalent PowerShell support for JSON, file traversal, UUID generation, and optional SQLite updates
Safety Notes
- Source sessions stay untouched.
- Re-running the script does not duplicate already migrated sessions with the same
forked_from_id. - The script updates
session_index.jsonlso migrated sessions remain visible in local session lists. - The script may update
state_5.sqlitesource fields whensqlite3is available. - Prefer downloading to a temporary file and then executing it. Do not use
curl | bash. - On Windows, the AI must adapt the script behavior rather than pretend the
.shruns natively.
Response Format
When using this skill, report:
- the exact command that was run
- whether it was a dry run or a real migration
- the final
summary: copied=... patched_existing=... patched_db=... patched_index=... - any skipped conditions or missing tools
Source: GcsSloop/ai-gate — distributed by TomeVault.