【Bug已解决】codex: 全自动模式仍弹审批 — CodeX CLI 审批提示未跳过解决方案 【Bug已解决】codex: --full-auto still asks for approval / Full auto mode not skipping prompts — CodeX 全自动模式仍提示审批解决方案1. 问题描述CodeX CLI 使用--full-auto后仍然提示审批权限# --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%无 TTYCI/Docker约 25%版本不支持旧版本约 15%沙箱严格strict约 10%环境变量env 覆盖约 10%参数冲突多参数约 5%3. 解决方案方案一检查配置覆盖最推荐# 步骤 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, indent2) # 步骤 3验证 codex --full-auto task --max-turns 5 # 步骤 4或检查项目级配置 cat .codex/config.json | grep -i approve\|permission方案二使用 --print 模式# 步骤 1使用 --print 避免 TTY 依赖 codex --print --full-auto task --max-turns 10 # 步骤 2CI/CD 中 codex --print --full-auto --no-stream task --max-turns 10 21 # 步骤 3或组合 --auto-approve codex --print --auto-approve task --max-turns 10 # 步骤 4验证 codex --print --full-auto echo hello --max-turns 1方案三配置沙箱自动审批# 步骤 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方案四使用环境变量# 步骤 1设置环境变量 export CODEX_FULL_AUTOtrue export CODEX_AUTO_APPROVEtrue codex --print task --max-turns 10 # 步骤 2CI/CD 中 # GitHub Actions: env: CODEX_FULL_AUTOtrue codex --print task --max-turns 10 # 步骤 3永久设置 echo export CODEX_FULL_AUTOtrue ~/.bashrc source ~/.bashrc # 步骤 4验证 codex --print echo hello --max-turns 1方案五检查 TTY# 步骤 1检查 TTY tty # 如果报 not a tty # 步骤 2CI/CD 中使用 --print codex --print --full-auto task --max-turns 10 # 步骤 3Docker 中使用 -it docker run -it codex-env codex --full-auto task # 步骤 4或使用 script 命令 script -q /dev/null codex --full-auto task方案六更新版本# 步骤 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 14. 各方案对比总结方案适用场景推荐指数难度方案一检查配置配置覆盖⭐⭐⭐⭐⭐低方案二--printCI/CD⭐⭐⭐⭐⭐低方案三配置沙箱长期⭐⭐⭐⭐⭐低方案四环境变量CI/CD⭐⭐⭐⭐低方案五TTY无 TTY⭐⭐⭐⭐⭐低方案六更新版本⭐⭐⭐低5. 常见问题 FAQ5.1 --full-auto 和 --auto-approve 的区别--full-auto: 全自动模式沙箱自动审批--auto-approve: 仅自动审批工具调用5.2 CI/CD 中为什么卡住无 TTY 环境无法显示审批提示导致 CodeX 等待输入。5.3 如何在 CI/CD 中使用codex --print --full-auto task --max-turns 10 215.4 配置覆盖命令行参数config.json中的requireApproval: true会覆盖--full-auto。5.5 如何检查 TTYtty # 如果 not a tty说明无 TTY5.6 CODEX_FULL_AUTO 是什么环境变量启用全自动模式。5.7 sandbox.autoApprove 是什么在配置中设置autoApprove: true沙箱自动审批。5.8 Docker 中如何使用docker run -it codex-env codex --full-auto task # 或 docker run codex-env codex --print --full-auto task5.9 如何验证自动审批codex --print --full-auto echo hello --max-turns 15.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_AUTOtrue 环境变量 □ 7. tty 检查 TTY 环境 □ 8. Docker: -it 或 --print □ 9. script -q /dev/null 模拟 TTY □ 10. npm update 更新版本6. 总结根本原因--full-auto 不生效最常见原因是配置覆盖35%和无 TTY 环境25%最佳实践使用codex --print --full-auto task --max-turns 10组合配置沙箱在 config.json 中设置autoApprove: true环境变量export CODEX_FULL_AUTOtrue或CODEX_AUTO_APPROVEtrue最佳实践建议CI/CD 中使用codex --print --full-auto --no-stream task --max-turns 10 21故障排查流程图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_AUTOtrue] 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[✅ 长期方案]