Schema Migration
July 18, 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 current persisted format is
schema_version = 4. - The compatibility guarantee for this release is migration from released schema
3to the final schema4format. - The legacy
version = 2loader remains available, but it is not the compatibility boundary for this change. - The current binary 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 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. - The guaranteed automatic migration is
schema_version = 3 -> schema_version = 4. - The existing legacy
version = 2loader also rewrites directly to schema4. - Users are not expected to install intermediate
codex-authversions.
Schema History
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 - - Persisted plans use final product semantics rather than backend identifiers
- Legacy
teambecomesbusiness - Legacy
businessbecomesenterprise - The same conversion applies to per-account
last_usage.plan_type
- 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.