Codex config.toml configuration lost after switching provider - CC Switch
Quick fix
Upgrade cc-switch to v3.17.0+, which changes to incremental merge instead of full overwrite of config.toml.
Symptom
Section titled “Symptom”codex 切换供应商 config.toml 被重置codex switch provider config.toml is reset
When switching Codex providers or restarting the local router, early versions of cc-switch used a full replacement logic to write `config.toml`, causing user-defined non-provider fields such as MCP servers, sandbox configurations, and desktop preferences to be overwritten and lost. Additionally, early versions had defects in handling TOML, such as `base_url` being incorrectly written into the `[windows]` section, general configurations being infinitely duplicated, and `model_provider` being forcibly changed to `ccswitch`, causing historical sessions to disappear.
Starting from v3.12.2, Section-Aware TOML Editing was introduced to fix field position errors and duplication issues; v3.13.0 fixed MCP configuration loss during switching; v3.16.0 resolved the issue of forcibly overwriting `model_provider`; v3.17.0 moved the merge and write-back to the backend `toml_edit` process, implementing incremental merge to preserve non-provider fields. Some users reported that after v3.17.0, specific configurations (such as `node_repl`, color settings) were still being restored after restart, indicating that overwrite issues in edge cases may still exist.
Upgrade cc-switch to v3.17.0 or higher. This version refactored the merge and write-back logic for Codex general configurations, changing to incremental merge, which only overwrites provider-related fields and preserves user-defined sections.
~/.codex/config.toml # 保留 [mcp_servers.*], [desktop], [features] 等用户配置段If using an older version (such as v3.12.x) and encountering `base_url` being written to the wrong location or general configurations infinitely increasing, upgrade to v3.12.2+, which fixes Section-Aware TOML Editing.
~/.codex/config.toml [model_providers.custom]name = "custom"wire_api = "responses"base_url = "https://your-api-url/v1" # base_url 正确写入对应供应商段下For MCP configurations, do not manually write them into `config.toml`. Add and enable them to Codex through cc-switch's "MCP Server Management" interface to avoid being overwritten.
# 通过 cc-switch UI 管理 MCP,而非手动编辑 ~/.codex/config.tomlIf `model_provider` is forcibly changed to `ccswitch` after switching providers, causing historical sessions to disappear, upgrade to v3.16.0+, which implements Codex Live Config Preservation and no longer forcibly rewrites this field.
If specific configurations (such as `js_repl`, color settings) are still restored after restart following an upgrade, check if local routing is enabled. The live/backup rebuild of local routing may still overwrite some configurations. Try disabling local routing or manually modifying the `original_config` field in the database `proxy_live_backup` table as a temporary workaround.
Affected Versions
Section titled “Affected Versions”Source Issues
Section titled “Source Issues”This page is distilled from 40 real issues
- #95切回Codex官key的时候提示切换失败,检查配置
- #161切换 ‘启用’ 内容会乱
- #178[BUG] 编辑Codex 提供商页面提取API请求地址的逻辑默认是第一个出现的 model_provider
- #200codex无法自动生成可用模板
- #305在版本v3.7.1中新增Codex的自定义供应商后启用报错JSON 解析错误
- #457codex 配置,添加新配置,只添加 apikey 和url 然后使用 codex 会一直提示 Reconnecting...
- #482IO 错误: /Users/dabu/.codex/config.toml: No such file or directory (os error 2)
- #829版本v3.10.2 codex配置不能覆盖和写入
- #1088cc-switch导致codex的MCP、模型等设置直接丢失无法找回
- #1136更新到3.11.0后,无法保存部分配置
- #1364codex 配置无限增加问题
- #1404CC Switch v3.12.0 bug
- #1441BUG:CODEX新增渠道无法使用(Windows 11)
- #1677config.toml 文件配置mcp_servers保存失败
- #1863codex 切换供应商 config.toml 被重置
- #2030Codex 配置无法覆盖
- #2717cc switch读取已存在的codex配置再修改会少生成很多字段
- #2847model provider被强制更改为ccswitch
- #3021CODEX 路由与故障转移失效
- #3357Codex配置好了路由并启用,在Codex中输入命令报错,但是如果再启用其他配置,就可以正常响应
- #3582MCP中不能包含codex这个名字,不然codex会丢失会话
- #3605自定义模型在codex desktop端的模型选择又不见了。
- #4038开启ccswitch之后与codex或claude对话时,会莫名截断
- #4142关闭/打开本地路由导致config.toml丢失
- #4147how to use cc-switch for Jetbrains ai assistant?
- #4358在Codex中各种设置,重启Codex之后 一切复原,
- #4655auth.json中key被修改为其他key,实际使用key在config.toml文件里
- #4780Codex config serialization splits parent and child TOML tables, causing `[projects]` to appear between `[model_providers]` and `[model_providers.xxx]`
- #49163.16.5的版本mimo2.5pro可以在codex使用,但2.5不行
- #5051安装ccswitch后 codex的会话还有插件被全部清空,去ccswitch中看会话管理列表里面东西也没有任何记录
- #5052切换供应商会导致codex沙箱配置出问题
- #5137ccs上改codex的node_repl这个配置, 改成true之后重启codex后 又会变成false
- #5205按照教程修改 ccs 之后,所有模型都无法输入图片
- #5665config.toml 右边的选中状态重新打开又变成未选中
- #5797Codex Desktop model picker does not show OpenCode Go model mappings
- #6007Add Codex sub-agent default model and reasoning effort settings
- #6097MCP注入异常
- #6411设置了codex的颜色这些,当退出ccswitch的时候config.toml的颜色这些配置会被还原,每次都要修改一下
- #6670开启本地路由后claudecodecli 下面opus模型总是显示opus4.8
- #6827更新供应商key失败,显示保存成功,但是保存的是另外的key
- Why does my manually added MCP configuration in config.toml disappear after switching providers?
- Early versions of cc-switch used full replacement logic to overwrite config.toml when switching providers. Upgrade to v3.17.0+, or manage MCP configurations centrally through cc-switch's "MCP Server Management" interface to avoid manual writes being overwritten.
- After upgrading to the latest version, why do node_repl or color settings still revert to false after restarting Codex?
- Although v3.17.0 moved the merge logic to the backend toml_edit, the live/backup rebuild of local routing may still overwrite some edge configurations. If you encounter this issue, try disabling local routing, or manually modify the original_config field in the database proxy_live_backup table as a temporary workaround.
- After switching providers, all historical session records in Codex disappeared. How to recover?
- This is because old versions of cc-switch forcibly changed model_provider in config.toml to ccswitch, and Codex reads session records based on this field. Upgrade to v3.16.0+ to avoid this issue. For already lost records, manually change model_provider back to the original value (e.g., OpenAI) to attempt recovery.
- base_url was written under the [windows] section, causing Codex to be unable to read it. How to fix?
- This is a known bug in v3.12.0, fixed in v3.12.2. After upgrading to the latest version, base_url will be correctly written under the corresponding provider's section, such as [model_providers.custom].
- After checking "Write general configuration", the configuration content infinitely duplicates. What to do?
- This is a defect in the TOML merge logic of early versions, which did not perform Section-Aware processing. It has been fixed in v3.12.2, and upgrading will resolve it.
- Cannot see custom models in Codex Desktop, only official models. What to do?
- This may be related to Codex Desktop's local cache or path resolution. Try completely exiting Codex Desktop and reopening it, or reinstall/upgrade Codex Desktop. Also check if model_catalog_json and ~/.codex/cc-switch-model-catalog.json exist in ~/.codex/config.toml.
- After enabling local routing, the opus model in Claude Code CLI always shows opus4.8 instead of the configured opus5?
- After enabling local routing, cc-switch overwrites the default_opus_model field in config.toml. This is currently a known issue; disabling local routing can restore normal display. Wait for an official fix.
- After saving the provider configuration, the displayed key is another provider's key. How to fix?
- This is a known issue in v3.20.0, where the edit box prioritized reading the key from the shared auth.json, causing cross-contamination. It has been fixed in v3.20.1, changed to rebuild from the provider's own bearer token in config.toml. Contaminated keys before the fix need to be manually re-entered.
Related problems
Section titled “Related problems”This is an unofficial community wiki with no affiliation to the cc-switch authors or the project itself. Its content is compiled from the project's public GitHub issues. This site distributes no software.