Schema Migration
June 1, 2026 · View on GitHub
This document defines how codex-auth versions the on-disk ~/.codex/accounts/registry.json file.
Terms
app_versionis the CLI release version fromsrc/version.zig.schema_versionis the registry file format version stored inregistry.json.schema_versionis about migration only; it is not the same thing as the CLI release version.
Current Policy
- The latest binary supports every released schema. Right now that means:
- legacy
version = 2 - current
schema_version = 4
- legacy
- The current binary also accepts current-layout files that still use the old top-level key
version = 3, or still carry the old globallast_attributed_rolloutshape, and rewrites them once to normalizedschema_version = 4. - If the binary sees a newer
schema_versionthan it understands, it fails withUnsupportedRegistryVersionand must not write the file.
Upgrade Behavior
- User-visible behavior is always “upgrade directly to the latest supported schema”.
- Internally, migrations are implemented as a chain of
Vn -> Vn+1steps. - In the current code, supported automatic migration is
version = 2 -> schema_version = 4; older current-layout schema3files are rewritten once as schema4. - Current-layout schema
4files are also rewritten once when they are missing normalized current fields such asprevious_active_account_key. - Users are not expected to install intermediate
codex-authversions.
Released Schemas
version = 2- Email-keyed account snapshots
active_email- Email-based account identity
schema_version = 3- Record-key-based account snapshots
active_account_keyactive_account_activated_at_ms- Per-account
last_local_rollout - Legacy top-level
apiblock, now ignored and omitted on rewrite - Per-account
account_key - Each account also stores
chatgpt_account_idandchatgpt_user_id
schema_version = 4- Same account layout as schema
3 - Live refresh interval stored as top-level
interval_seconds - Older
live.interval_secondsand removedauto_switchblocks are omitted on rewrite - Adds top-level
previous_active_account_keyforcodex-auth -andcodex-auth switch -
- Same account layout as schema
When To Bump schema_version
Before bumping schema_version, ask the user whether this change should bump the schema. Do not bump it silently.
Bump the schema version whenever the persisted registry.json shape or semantics change. That includes:
- Adding, removing, or renaming a persisted field
- Changing a field type
- Changing identity keys such as
active_emailtoactive_account_key - Changing snapshot filename conventions or any other rule needed to find persisted files
- Reinterpreting an existing field with incompatible semantics
Do not bump the schema version for:
- CLI output changes
- Pure in-memory logic changes
- Help text or documentation changes
- Runtime behavior changes that do not alter persisted registry data
Migration Rules
- A supported older schema must auto-migrate on load and then rewrite
registry.jsonin the current format. - Supported migrations should preserve account records, active account selection, and account snapshot usability.
- Migration rewrites create the usual
registry.json.bak.*backup before replacing the file. import --purgeremains a manual recovery path if a registry is corrupted or too old for the current binary, but it is not the normal path between supported schemas.