【Bug已解决】codex: 全自动模式仍弹审批 — CodeX CLI 审批提示未跳过解决方案

【Bug已解决】codex: --full-auto still asks for approval / Full auto mode not skipping prompts --- CodeX 全自动模式仍提示审批解决方案

1. 问题描述

CodeX CLI 使用 --full-auto 后仍然提示审批权限:

bash 复制代码
# --full-auto 仍提示
$ codex --full-auto "修改 src/index.js" --max-turns 10
# 仍然弹出: Approve write to src/index.js? [y/n]

# 或 --auto-approve 不生效
$ codex --auto-approve "task" --max-turns 10
# 仍然等待审批输入

# 或 CI/CD 中卡住
$ codex --print --full-auto "task" --max-turns 10
# CI 管道超时,卡在审批步骤

# 或 Docker 中不工作
$ docker run codex-env codex --full-auto "task"
# Error: Cannot prompt in non-interactive mode

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

  • 配置覆盖命令行参数
  • 无 TTY 环境
  • 版本不支持 --full-auto
  • 沙箱配置严格
  • 环境变量冲突
  • 参数顺序错误

2. 原因分析

原因分类表

原因分类 具体表现 占比
配置覆盖 requireApproval 约 35%
无 TTY CI/Docker 约 25%
版本不支持 旧版本 约 15%
沙箱严格 strict 约 10%
环境变量 env 覆盖 约 10%
参数冲突 多参数 约 5%

3. 解决方案

方案一:检查配置覆盖(最推荐)

bash 复制代码
# 步骤 1:检查配置
cat ~/.codex/config.json | grep -i "approve\|permission\|require"

# 步骤 2:删除冲突配置
python3 -c "
import json
with open('/root/.codex/config.json') as f:
    config = json.load(f)
config.pop('requireApproval', None)
config.pop('interactiveApproval', None)
config['autoApprove'] = True
with open('/root/.codex/config.json', 'w') as f:
    json.dump(config, f, indent=2)
"

# 步骤 3:验证
codex --full-auto "task" --max-turns 5

# 步骤 4:或检查项目级配置
cat .codex/config.json | grep -i "approve\|permission"

方案二:使用 --print 模式

bash 复制代码
# 步骤 1:使用 --print 避免 TTY 依赖
codex --print --full-auto "task" --max-turns 10

# 步骤 2:CI/CD 中
codex --print --full-auto --no-stream "task" --max-turns 10 2>&1

# 步骤 3:或组合 --auto-approve
codex --print --auto-approve "task" --max-turns 10

# 步骤 4:验证
codex --print --full-auto "echo hello" --max-turns 1

方案三:配置沙箱自动审批

bash 复制代码
# 步骤 1:在配置中设置
cat > .codex/config.json << 'EOF'
{
  "model": "o1",
  "sandbox": {
    "enabled": true,
    "autoApprove": true,
    "allowedDirectories": ["./src", "./tests"]
  }
}
EOF

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

# 步骤 3:测试
codex --print "修改 src/index.js" --max-turns 5

# 步骤 4:验证
codex --print "echo hello" --max-turns 1

方案四:使用环境变量

bash 复制代码
# 步骤 1:设置环境变量
export CODEX_FULL_AUTO=true
export CODEX_AUTO_APPROVE=true
codex --print "task" --max-turns 10

# 步骤 2:CI/CD 中
# GitHub Actions: env: CODEX_FULL_AUTO=true
codex --print "task" --max-turns 10

# 步骤 3:永久设置
echo 'export CODEX_FULL_AUTO=true' >> ~/.bashrc
source ~/.bashrc

# 步骤 4:验证
codex --print "echo hello" --max-turns 1

方案五:检查 TTY

bash 复制代码
# 步骤 1:检查 TTY
tty  # 如果报 "not a tty"

# 步骤 2:CI/CD 中使用 --print
codex --print --full-auto "task" --max-turns 10

# 步骤 3:Docker 中使用 -it
docker run -it codex-env codex --full-auto "task"

# 步骤 4:或使用 script 命令
script -q /dev/null codex --full-auto "task"

方案六:更新版本

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

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

# 步骤 3:验证 --full-auto 支持
codex --help | grep -i "full-auto\|auto-approve"

# 步骤 4:测试
codex --print --full-auto "echo hello" --max-turns 1

4. 各方案对比总结

方案 适用场景 推荐指数 难度
方案一:检查配置 配置覆盖 ⭐⭐⭐⭐⭐
方案二:--print CI/CD ⭐⭐⭐⭐⭐
方案三:配置沙箱 长期 ⭐⭐⭐⭐⭐
方案四:环境变量 CI/CD ⭐⭐⭐⭐
方案五:TTY 无 TTY ⭐⭐⭐⭐⭐
方案六:更新 版本 ⭐⭐⭐

5. 常见问题 FAQ

5.1 --full-auto 和 --auto-approve 的区别

  • --full-auto: 全自动模式(沙箱+自动审批)
  • --auto-approve: 仅自动审批工具调用

5.2 CI/CD 中为什么卡住

无 TTY 环境无法显示审批提示,导致 CodeX 等待输入。

5.3 如何在 CI/CD 中使用

bash 复制代码
codex --print --full-auto "task" --max-turns 10 2>&1

5.4 配置覆盖命令行参数

config.json 中的 requireApproval: true 会覆盖 --full-auto

5.5 如何检查 TTY

bash 复制代码
tty  # 如果 "not a tty",说明无 TTY

5.6 CODEX_FULL_AUTO 是什么

环境变量,启用全自动模式。

5.7 sandbox.autoApprove 是什么

在配置中设置 "autoApprove": true,沙箱自动审批。

5.8 Docker 中如何使用

bash 复制代码
docker run -it codex-env codex --full-auto "task"
# 或
docker run codex-env codex --print --full-auto "task"

5.9 如何验证自动审批

bash 复制代码
codex --print --full-auto "echo hello" --max-turns 1

5.10 排查清单速查表

复制代码
□ 1. cat config.json | grep approve 检查
□ 2. 删除 requireApproval 配置
□ 3. codex --print --full-auto "task"
□ 4. --no-stream CI/CD 稳定
□ 5. sandbox.autoApprove: true
□ 6. CODEX_FULL_AUTO=true 环境变量
□ 7. tty 检查 TTY 环境
□ 8. Docker: -it 或 --print
□ 9. script -q /dev/null 模拟 TTY
□ 10. npm update 更新版本

6. 总结

  1. 根本原因:--full-auto 不生效最常见原因是配置覆盖(35%)和无 TTY 环境(25%)
  2. 最佳实践 :使用 codex --print --full-auto "task" --max-turns 10 组合
  3. 配置沙箱 :在 config.json 中设置 "autoApprove": true
  4. 环境变量export CODEX_FULL_AUTO=trueCODEX_AUTO_APPROVE=true
  5. 最佳实践建议 :CI/CD 中使用 codex --print --full-auto --no-stream "task" --max-turns 10 2>&1

故障排查流程图

flowchart TD A[--full-auto 不生效] --> B[cat config.json | grep approve] B --> C{有 requireApproval?} C -->|是| D[删除 requireApproval] C -->|否| E[使用 --print 模式] D --> F[设置 autoApprove: true] F --> G[codex --print --full-auto "task"] E --> G G --> H{成功?} H -->|是| I[✅ 问题解决] H -->|否| j[检查 TTY] j --> K[tty 命令] K --> L{有 TTY?} L -->|否| M[使用 --print] L -->|是| N[检查环境变量] M --> G N --> O[env | grep CODEX] O --> P{env 覆盖?} P -->|是| Q[unset 冲突变量] P -->|否| R[使用环境变量] Q --> G R --> S[CODEX_FULL_AUTO=true] S --> G G --> T{成功?} T -->|是| I T -->|否| U[配置沙箱] U --> V[sandbox.autoApprove: true] V --> G G --> W{成功?} W -->|是| I W -->|否| X[更新版本] X --> Y[npm update -g @openai/codex] Y --> G I --> Z[CI/CD: --print + --full-auto + --no-stream] Z --> AA[✅ 长期方案]
相关推荐
AI大模型-小雄16 小时前
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
孤狼GPT2 天前
Codex没有GPT-5.6 Sol选项怎么办?ChatGPT账号和API Key区别讲清楚
chatgpt·ai编程·codex·api key·gpt-5.6
仙逆GPT2 天前
Codex客户端找不到GPT-5.6模型怎么办?版本、配置和入口排查
chatgpt·ai编程·codex·sol·gpt-5.6