codex-safe-switch
中文 | English
在官方 ChatGPT、第三方 relay、多组 API key 之间切换 Codex CLI 配置。
30 秒上手
先安装 uv,再安装本工具:
uv tool install codex-safe-switch
codex-safe-switch
第一次运行会从当前 ~/.codex/config.toml 导入 provider 配置切片。
已经安装过时,这样升级到最新版:
uv tool upgrade codex-safe-switch
之后常用的就三个命令:
codex-safe-switch ls # 看已有 profiles
codex-safe-switch use myrelay # 切到 relay / 自定义 provider
codex-safe-switch official # 切回官方 ChatGPT
保存一个新 profile
先把 Codex 手动配置到能用的状态。比如你已经配好了某个 relay,并确认 codex 能跑。
然后保存:
codex-safe-switch save myrelay
以后就可以这样切回去:
codex-safe-switch use myrelay
第一次用时会怎样
| 你现在的状态 | 会发生什么 |
|---|---|
| 正在用官方 ChatGPT | 自动保存成 official |
| 正在用 relay / 自定义 provider | 自动保存成当前 provider 名 |
| 登录过 ChatGPT,但当前正在用 relay | 先保存当前 relay;以后跑 codex-safe-switch official 回官方 |
还没有 ~/.codex/config.toml |
提示你先配置一次 Codex |
codex-safe-switch official 不需要提前存在 official profile。缺少时会自动创建默认官方配置再切换。
它不会碰登录信息
这个工具只保存和切换 provider 配置切片:model、model_provider、model_reasoning_effort、model_reasoning_summary、model_verbosity、wire_api、disable_response_storage、preferred_auth_method,以及当前 provider 对应的 [model_providers.<name>]。
切换 profile 时,这些顶层字段和整个 [model_providers] 会被目标 profile 替换;其他 provider block 不会作为备份保留或恢复。项目、插件、MCP 和 TUI 等其他配置保持不变。
它不会保存、复制或覆盖:
~/.codex/auth.json- ChatGPT 登录 token
- API key 文件
- trusted projects、插件、MCP、TUI 偏好
如果你切到官方后还没登录过 ChatGPT,Codex 会自己提示你登录。
历史会话不见了
通常不是历史丢了,只是历史记录里的 provider 跟当前 provider 对不上。
先看状态:
codex-safe-switch doctor-history
然后切到你想用的 profile,工具会自动对齐历史:
codex-safe-switch use myrelay
# 或
codex-safe-switch official
更多命令
codex-safe-switch 交互选择 profile
codex-safe-switch ls 列出 profiles
codex-safe-switch current 显示当前 profile
codex-safe-switch use <name> 切到指定 profile
codex-safe-switch official 切回官方 ChatGPT
codex-safe-switch save <name> 保存当前 provider 配置
codex-safe-switch show <name> 查看 profile 内容
codex-safe-switch rm <name> 删除 profile
codex-safe-switch restart-codex
重启 Codex app/server 进程
codex-safe-switch repair-session-index
预览缺失 ID 与标题冲突(默认不写入)
codex-safe-switch repair-session-index --apply
仅补充索引中缺失的 thread ID
codex-safe-switch merge-history --dry-run
预览历史修复
codex-safe-switch merge-history
修复历史 metadata
repair-session-index 不会覆盖 session_index.jsonl 中已有 thread ID 的标题,也不会修改 SQLite title;标题冲突只会显示在报告中。
use 和 official 可以加 --restart-codex:
codex-safe-switch use myrelay --restart-codex
文件位置和环境变量
Profiles 默认放在:
~/.codex/profiles/
├── .active
├── .official/
│ └── provider.toml
└── myrelay/
└── provider.toml
环境变量:
| 变量 | 默认值 | 用途 |
|---|---|---|
CODEX_PROFILE_ROOT |
~/.codex/profiles |
profile 存放位置 |
CODEX_HOME |
~/.codex |
Codex 配置目录 |
relay profile 示例见 examples/relay-profile/provider.toml。
License
MIT
Metadata
Release files for codex-safe-switch 1.0.6
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| codex_safe_switch-1.0.6.tar.gz | 28.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| codex_safe_switch-1.0.6-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 50.0 kB
Release files / codex_safe_switch-1.0.6.tar.gz
| Download URL | codex_safe_switch-1.0.6.tar.gz |
|---|---|
| Size | 28.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a40e821a9a97067fe486255fbe68c547a30e7bfb12dd545eb88cb1dece5a539a
|
|
BLAKE2b-256 checksum How to use checksums |
537054f09d564be96e3faa121a14e4e6576da49dbcd5262e9c029ca31070bde0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Release files / codex_safe_switch-1.0.6-py3-none-any.whl
| Download URL | codex_safe_switch-1.0.6-py3-none-any.whl |
|---|---|
| Size | 21.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b56e7ac7aac4b6a5499a2c1a1b7ad86c2ad497b703a35ce2a6ee2e4f1da6708f
|
|
BLAKE2b-256 checksum How to use checksums |
17a1110b3db32714a3bec44b4d955c2b3ce1e2298e6d15cff402eb4784aa5878
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|