【Bug已解决】codex: 模型参数被忽略 — CodeX CLI 指定模型未生效解决方案

【Bug已解决】codex: --model flag ignored / Wrong model used despite flag --- CodeX 模型参数被忽略解决方案

1. 问题描述

CodeX CLI 的 --model 参数被忽略,使用了错误的模型:

bash 复制代码
# --model 被忽略
$ codex --model o1 "task"
# 实际使用 gpt-4o,而非 o1

# 或配置覆盖命令行
$ cat .codex/config.json
{"model": "gpt-4o"}
$ codex --model o1 "task"
# 仍然使用 gpt-4o

# 或环境变量覆盖
$ export CODEX_MODEL=gpt-4o
$ codex --model o1 "task"
# 仍然使用 gpt-4o

# 或旧模型名不识别
$ codex --model gpt-4 "task"
Error: model_not_found
Model 'gpt-4' is deprecated.

这个问题在以下场景中特别常见:

  • 配置文件覆盖命令行
  • 环境变量覆盖
  • 模型名已弃用
  • 大小写错误
  • 版本不支持
  • 参数顺序错误

2. 原因分析

原因分类表

原因分类 具体表现 占比
配置覆盖 config.json 约 35%
环境变量 CODEX_MODEL 约 25%
模型弃用 gpt-4 约 20%
大小写 O1 vs o1 约 10%
版本不支持 旧版本 约 5%
参数顺序 --model 在后 约 5%

3. 解决方案

方案一:清除配置覆盖(最推荐)

bash 复制代码
# 步骤 1:检查配置
cat ~/.codex/config.json | grep model
cat .codex/config.json | grep model

# 步骤 2:删除配置中的 model
python3 -c "
import json
with open('/root/.codex/config.json') as f:
    config = json.load(f)
config.pop('model', None)
with open('/root/.codex/config.json', 'w') as f:
    json.dump(config, f, indent=2)
"

# 步骤 3:验证
codex --model o1 "task" --max-turns 5

# 步骤 4:或使用 --model 覆盖
codex --model o1 --debug "task" 2>&1 | grep -i "model"

方案二:清除环境变量

bash 复制代码
# 步骤 1:检查环境变量
env | grep -i CODEX

# 步骤 2:清除环境变量
unset CODEX_MODEL
unset CODEX_DEFAULT_MODEL

# 步骤 3:验证
codex --model o1 "task" --max-turns 5

# 步骤 4:或永久清除
sed -i '/CODEX_MODEL/d' ~/.bashrc
source ~/.bashrc

方案三:使用正确的模型名

bash 复制代码
# 步骤 1:查看可用模型
codex --list-models
# 或
codex --help | grep -A20 model

# 步骤 2:使用正确的名称
codex --model o1 "task"
codex --model o1-mini "task"
codex --model gpt-4o "task"
codex --model gpt-4o-mini "task"

# 步骤 3:避免弃用的名称
# 错误: gpt-4, gpt-3.5-turbo(弃用)
# 正确: gpt-4o, gpt-4o-mini

# 步骤 4:验证
codex --model o1 --debug "task" 2>&1 | grep -i "model"

方案四:验证模型使用

bash 复制代码
# 步骤 1:使用 --debug 验证
codex --model o1 --debug "task" 2>&1 | grep -i "model\|using"

# 步骤 2:检查实际使用的模型
codex --model o1 --debug "what model are you?" --max-turns 5 2>&1

# 步骤 3:对比
codex --model gpt-4o --debug "what model are you?" --max-turns 5 2>&1

# 步骤 4:确认
codex --model o1 "hello" --max-turns 1

方案五:更新配置

bash 复制代码
# 步骤 1:更新 config.json
cat > .codex/config.json << 'EOF'
{
  "model": "o1"
}
EOF

# 步骤 2:验证
python3 -m json.tool .codex/config.json

# 步骤 3:测试
codex "task" --max-turns 5

# 步骤 4:验证模型
codex --debug "task" 2>&1 | grep -i "model"

方案六:更新版本

bash 复制代码
# 步骤 1:检查版本
codex --version

# 步骤 2:更新
npm update -g @openai/codex

# 步骤 3:验证 --model 支持
codex --help | grep -i model

# 步骤 4:测试
codex --model o1 "hello" --max-turns 1
codex --debug "hello" 2>&1 | grep -i "model"

4. 各方案对比总结

方案 适用场景 推荐指数 难度
方案一:清除配置 配置覆盖 ⭐⭐⭐⭐⭐
方案二:清除环境变量 env 覆盖 ⭐⭐⭐⭐⭐
方案三:正确模型名 弃用 ⭐⭐⭐⭐⭐
方案四:验证模型 排查 ⭐⭐⭐⭐⭐
方案五:更新配置 长期 ⭐⭐⭐⭐⭐
方案六:更新 版本 ⭐⭐⭐

5. 常见问题 FAQ

5.1 如何查看可用模型

bash 复制代码
codex --list-models
# 或
codex --help | grep -A20 model

5.2 哪些模型可用

通常: o1, o1-mini, gpt-4o, gpt-4o-mini。

5.3 配置和环境变量哪个优先级高

环境变量 > 配置文件 > 命令行参数(某些版本)。

5.4 如何验证使用的模型

bash 复制代码
codex --model o1 --debug "task" 2>&1 | grep -i "model"

5.5 gpt-4 为什么不可用

已弃用。使用 gpt-4o 代替。

5.6 如何清除环境变量

bash 复制代码
unset CODEX_MODEL

5.7 大小写重要吗

是的。使用小写 o1,不是 O1

5.8 配置中的 model 字段

.codex/config.json 中设置 "model": "o1"

5.9 命令行 --model 的优先级

取决于版本。某些版本配置/环境变量覆盖命令行。

5.10 排查清单速查表

复制代码
□ 1. cat config.json | grep model 检查
□ 2. env | grep CODEX 检查环境变量
□ 3. unset CODEX_MODEL 清除
□ 4. 删除 config.json 中的 model
□ 5. codex --list-models 查看可用
□ 6. 使用 o1/gpt-4o(非 gpt-4)
□ 7. 小写: o1 非 O1
□ 8. codex --debug | grep model 验证
□ 9. 更新 config.json: "model": "o1"
□ 10. npm update 更新版本

6. 总结

  1. 根本原因:--model 被忽略最常见原因是配置覆盖(35%)和环境变量覆盖(25%)
  2. 最佳实践 :清除 config.json 中的 model 字段和 CODEX_MODEL 环境变量
  3. 正确模型名 :使用 o1gpt-4o(小写),避免弃用的 gpt-4
  4. 验证方法codex --model o1 --debug "task" 2>&1 | grep -i model
  5. 最佳实践建议 :在 config.json 中设置 "model": "o1",用 --debug 验证

故障排查流程图

flowchart TD A[--model 被忽略] --> B[codex --debug | grep model] B --> C{用的哪个模型?} C -->|是配置中的| D[清除 config.json model] C -->|是环境变量| E[unset CODEX_MODEL] C -->|是默认| F[检查模型名] D --> G[python3 删除 model 字段] E --> H[sed -i 删除 ~/.bashrc] G --> I[codex --model o1 验证] H --> I F --> j{名称正确?} j -->|否| k[使用 o1/gpt-4o] j -->|是| L[检查大小写] k --> I L --> M{小写?} M -->|否| N[使用小写 o1] M -->|是| O[更新版本] N --> I O --> P[npm update -g @openai/codex] P --> I I --> Q{模型正确?} Q -->|是| R[✅ 问题解决] Q -->|否| S[更新 config.json] S --> T["model": "o1"] T --> I I --> U{成功?} U -->|是| R U -->|否| V[codex --list-models 查看] V --> W[确认可用模型] W --> I R --> X[长期: config.json + --debug 验证] X --> Y[✅ 长期方案]
相关推荐
孤狼GPT2 小时前
Codex还是看不到GPT-5.6?CLI、App和模型入口排查
ai编程·codex·codex cli·gpt-5.6·chatgpt桌面版
向哆哆2 小时前
【Bug已解决】codex: 全自动模式仍弹审批 — CodeX CLI 审批提示未跳过解决方案
cli·codex·报错解决
AI大模型-小雄17 小时前
2026 年 7 月国内怎么开通 ChatGPT Pro?5x / 20x 区别、适合人群与避坑指南
人工智能·gpt·chatgpt·ai编程·开发工具·codex·chatgpt pro
AI大模型-小雄1 天前
升级 ChatGPT Pro 后,如何用 Codex 做项目重构?一套更稳的实战流程
gpt·chatgpt·重构·ai编程·开发工具·codex·chatgpt pro
孤狼GPT1 天前
GPT-5.6找不到Extra High正常吗?Plus和Pro推理等级讲清楚
codex·ai工具·chatgpt plus·chatgpt pro·gpt-5.6
咩咩大主教1 天前
Windows/WSL Codex Cli配置火山方舟Coding Plan
火山引擎·codex·deepseek·火山方舟
云卷云舒___________1 天前
Grok CLI 泄密用户文件、Codex推理优化、GPT-5.6 Sol 登顶 Arena 前端榜 | 7月13日 AI日报
openai·codex·xai·ai日报·grokcli·gpt56sol·designarena
带刺的坐椅2 天前
SolonCode v2026.7.13 发布:多工作区协同、推理水平可控、子代理任务分组、工程体验再进化
llm·agent·codex·solon-ai·claudecode·opencode
林小果12 天前
LinkAGI:面向 Claude Code、Codex 与 Gemini CLI 的统一 API 接入服务
api·codex·claude code·gemini cli