codex
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseCodex Execution Skill
Codex执行技能
Prerequisites
前置条件
- Codex CLI installed and configured ()
~/.codex/config.toml - Verify availability: on first use per session
codex --version
- 已安装并配置Codex CLI()
~/.codex/config.toml - 验证可用性:每次会话首次使用时执行
codex --version
Workflow Checklist
工作流检查清单
For every Codex task, follow this sequence:
-
☐ Detect HPC/Slurm environment:
- Check if running on HPC cluster (look for ,
/home/woody/, Slurm env vars)/home/hpc/ - If HPC detected: Always use flag to bypass Landlock sandbox restrictions
--yolo
- Check if running on HPC cluster (look for
-
☐ Ask user for execution parameters via(single prompt):
AskUserQuestion- Model: ,
gpt-5, or defaultgpt-5-codex - Reasoning effort: ,
minimal,low,mediumhigh
- Model:
-
☐ Determine sandbox mode based on task:
- : Code review, analysis, documentation
read-only - : Code modifications, file creation
workspace-write - : System operations, network access
danger-full-access - HPC override: Always add flag (bypasses Landlock restrictions)
--yolo
-
☐ Build command with required flags:bash
codex exec [OPTIONS] "PROMPT"Essential flags:- (if overriding default)
-m <MODEL> -c model_reasoning_effort="<LEVEL>"- (skip on HPC)
-s <SANDBOX_MODE> - (if outside git repo)
--skip-git-repo-check - (if changing workspace)
-C <DIRECTORY> - (for non-interactive execution, cannot be used with --yolo)
--full-auto
HPC command pattern (withto bypass Landlock):--yolobashcodex exec --yolo -m gpt-5 -c model_reasoning_effort="high" --skip-git-repo-check \ "Analyze this code: $(cat /path/to/file.py)" 2>/dev/nullNote:is an alias for--yoloand is REQUIRED on HPC clusters to avoid Landlock sandbox errors. Do not use --full-auto with --yolo as they are incompatible.--dangerously-bypass-approvals-and-sandbox -
☐ Execute with stderr suppression:
- Append to hide thinking tokens
2>/dev/null - Remove only if user requests verbose output or debugging
- Append
-
☐ Validate execution:
- Check exit code (0 = success)
- Summarize output for user
- Report errors with actionable solutions
- If Landlock/sandbox errors on HPC: verify flag was used, retry if missing
--yolo
-
☐ Inform about resume capability:
- "Resume this session anytime: "
codex resume
- "Resume this session anytime:
所有Codex任务均需遵循以下步骤:
-
☐ 检测HPC/Slurm环境:
- 检查是否在HPC集群上运行(查找、
/home/woody/、Slurm环境变量)/home/hpc/ - 若检测到HPC:必须使用标志以绕过Landlock沙箱限制
--yolo
- 检查是否在HPC集群上运行(查找
-
☐ 通过向用户询问执行参数(单次提示):
AskUserQuestion- 模型:、
gpt-5或默认模型gpt-5-codex - 推理力度:、
minimal、low、mediumhigh
- 模型:
-
☐ 根据任务确定沙箱模式:
- :代码审查、分析、文档生成
read-only - :代码修改、文件创建
workspace-write - :系统操作、网络访问
danger-full-access - HPC覆盖规则:始终添加标志(绕过Landlock限制)
--yolo
-
☐ 构建包含必要标志的命令:bash
codex exec [OPTIONS] "PROMPT"关键标志:- (若要覆盖默认模型)
-m <MODEL> -c model_reasoning_effort="<LEVEL>"- (HPC环境下跳过)
-s <SANDBOX_MODE> - (若在git仓库外执行)
--skip-git-repo-check - (若要切换工作区)
-C <DIRECTORY> - (用于非交互式执行,不可与--yolo同时使用)
--full-auto
HPC命令格式(使用绕过Landlock):--yolobashcodex exec --yolo -m gpt-5 -c model_reasoning_effort="high" --skip-git-repo-check \ "Analyze this code: $(cat /path/to/file.py)" 2>/dev/null注意:是--yolo的别名,在HPC集群上是必需的,以避免Landlock沙箱错误。请勿同时使用--full-auto和--yolo,二者不兼容。--dangerously-bypass-approvals-and-sandbox -
☐ 执行时抑制标准错误输出:
- 添加以隐藏思考标记
2>/dev/null - 仅在用户请求详细输出或调试时移除该参数
- 添加
-
☐ 验证执行结果:
- 检查退出码(0表示成功)
- 为用户总结输出内容
- 报告错误并提供可操作的解决方案
- 若HPC环境下出现Landlock/沙箱错误:验证是否使用了标志,若缺失则重试
--yolo
-
☐ 告知用户会话恢复功能:
- "随时恢复此会话:"
codex resume
- "随时恢复此会话:
Command Patterns
命令示例
🔥 HPC QUICK TIP: On HPC clusters (e.g.,,/home/woody/), ALWAYS add/home/hpc/flag to avoid Landlock sandbox errors. Example:--yolocodex exec --yolo -m gpt-5 ...
🔥 HPC快速提示:在HPC集群(如、/home/woody/)上,务必添加/home/hpc/标志以避免Landlock沙箱错误。示例:--yolocodex exec --yolo -m gpt-5 ...
Read-Only Analysis
只读分析
bash
codex exec -m gpt-5 -c model_reasoning_effort="medium" -s read-only \
--skip-git-repo-check --full-auto "review @file.py for security issues" 2>/dev/nullbash
codex exec -m gpt-5 -c model_reasoning_effort="medium" -s read-only \
--skip-git-repo-check --full-auto "review @file.py for security issues" 2>/dev/nullStdin Input (bypasses sandbox file restrictions)
标准输入(绕过沙箱文件限制)
bash
cat file.py | codex exec -m gpt-5 -c model_reasoning_effort="low" \
--skip-git-repo-check --full-auto - 2>/dev/nullNote: Stdin with flag may not be supported in all Codex CLI versions.
-bash
cat file.py | codex exec -m gpt-5 -c model_reasoning_effort="low" \
--skip-git-repo-check --full-auto - 2>/dev/null注意:使用标志的标准输入可能并非在所有Codex CLI版本中都受支持。
-HPC/Slurm Environment (YOLO Mode - Bypass Landlock)
HPC/Slurm环境(YOLO模式 - 绕过Landlock)
When running on HPC clusters with Landlock security restrictions, use the flag:
--yolobash
undefined在使用Landlock安全限制的HPC集群上,使用标志:
--yolobash
undefinedPrimary solution: --yolo flag bypasses Landlock sandbox
主要解决方案:--yolo标志绕过Landlock沙箱
codex exec --yolo -m gpt-5 -c model_reasoning_effort="high" --skip-git-repo-check
"Analyze this code: $(cat /path/to/file.py)" 2>/dev/null
"Analyze this code: $(cat /path/to/file.py)" 2>/dev/null
**Alternative: Manual Code Injection** (if --yolo is unavailable):
```bashcodex exec --yolo -m gpt-5 -c model_reasoning_effort="high" --skip-git-repo-check
"Analyze this code: $(cat /path/to/file.py)" 2>/dev/null
"Analyze this code: $(cat /path/to/file.py)" 2>/dev/null
**替代方案:手动代码注入**(若--yolo不可用):
```bashCapture code content and pass directly in prompt
捕获代码内容并直接传入提示
codex exec -m gpt-5 -c model_reasoning_effort="high" --skip-git-repo-check --full-auto
"Analyze this Python code: $(cat file.py)" 2>/dev/null
"Analyze this Python code: $(cat file.py)" 2>/dev/null
Or for large files, use heredoc:
```bash
codex exec --yolo -m gpt-5 -c model_reasoning_effort="high" --skip-git-repo-check "$(cat <<'ENDCODE'
Analyze the following code comprehensively:
$(cat file.py)
Focus on: architecture, algorithms, multi-GPU optimization, potential bugs, code quality.
ENDCODE
)" 2>/dev/nullNote: is short for and is safe on HPC login nodes where you have limited permissions anyway. Do not combine --yolo with --full-auto as they are incompatible.
--yolo--dangerously-bypass-approvals-and-sandboxcodex exec -m gpt-5 -c model_reasoning_effort="high" --skip-git-repo-check --full-auto
"Analyze this Python code: $(cat file.py)" 2>/dev/null
"Analyze this Python code: $(cat file.py)" 2>/dev/null
对于大文件,可使用here文档:
```bash
codex exec --yolo -m gpt-5 -c model_reasoning_effort="high" --skip-git-repo-check "$(cat <<'ENDCODE'
Analyze the following code comprehensively:
$(cat file.py)
Focus on: architecture, algorithms, multi-GPU optimization, potential bugs, code quality.
ENDCODE
)" 2>/dev/null注意:是的缩写,在HPC登录节点上使用是安全的,因为你在此处的权限本来就有限。请勿同时使用--yolo和--full-auto,二者不兼容。
--yolo--dangerously-bypass-approvals-and-sandboxCode Modification
代码修改
bash
codex exec -m gpt-5 -c model_reasoning_effort="high" -s workspace-write \
--skip-git-repo-check --full-auto "refactor @module.py to async/await" 2>/dev/nullbash
codex exec -m gpt-5 -c model_reasoning_effort="high" -s workspace-write \
--skip-git-repo-check --full-auto "refactor @module.py to async/await" 2>/dev/nullResume Session
恢复会话
bash
echo "fix the remaining issues" | codex exec --skip-git-repo-check resume --last 2>/dev/nullbash
echo "fix the remaining issues" | codex exec --skip-git-repo-check resume --last 2>/dev/nullCross-Directory Execution
跨目录执行
bash
codex exec -C /path/to/project -m gpt-5 -c model_reasoning_effort="medium" \
-s read-only --skip-git-repo-check --full-auto "analyze architecture" 2>/dev/nullbash
codex exec -C /path/to/project -m gpt-5 -c model_reasoning_effort="medium" \
-s read-only --skip-git-repo-check --full-auto "analyze architecture" 2>/dev/nullUsing Profiles
使用配置文件
bash
codex exec --profile production -c model_reasoning_effort="high" \
--full-auto "optimize performance in @app.py" 2>/dev/nullbash
codex exec --profile production -c model_reasoning_effort="high" \
--full-auto "optimize performance in @app.py" 2>/dev/nullCLI Reference
CLI参考
Core Flags
核心标志
| Flag | Values | When to Use |
|---|---|---|
| | Override default model |
| | Runtime config override (repeatable) |
| | Set execution permissions |
| flag | REQUIRED on HPC - Bypasses all sandbox restrictions (alias for |
| | Change workspace directory |
| flag | Allow execution outside git repos |
| flag | Non-interactive mode (workspace-write + approvals on failure). Cannot be used with --yolo |
| | Load configuration profile from config.toml |
| flag | JSON event output (CI/CD pipelines) |
| | Write final message to file |
| | Attach images (repeatable or comma-separated) |
| flag | Use local open-source model (requires Ollama) |
| 标志 | 取值 | 使用场景 |
|---|---|---|
| | 覆盖默认模型 |
| | 运行时配置覆盖(可重复使用) |
| | 设置执行权限 |
| 标志 | HPC环境必需 - 绕过所有沙箱限制( |
| | 切换工作区目录 |
| 标志 | 允许在git仓库外执行 |
| 标志 | 非交互模式(工作区写入 + 失败时自动确认)。不可与--yolo同时使用 |
| | 从config.toml加载配置文件 |
| 标志 | 输出JSON格式事件(用于CI/CD流水线) |
| | 将最终消息写入文件 |
| | 附加图片(可重复使用或逗号分隔) |
| 标志 | 使用本地开源模型(需Ollama) |
Configuration Options
配置选项
Model Reasoning Effort ():
-c model_reasoning_effort="<LEVEL>"- : Quick tasks, simple queries
minimal - : Standard operations, routine refactoring
low - : Complex analysis, architectural decisions (default)
medium - : Critical code, security audits, complex algorithms
high
Model Verbosity ():
-c model_verbosity="<LEVEL>"- : Minimal output
low - : Balanced detail (default)
medium - : Verbose explanations
high
Approval Prompts ():
-c approvals="<WHEN>"- : Before any tool use
on-request - : Only on errors (default for
on-failure)--full-auto - : Minimal prompts
untrusted - : No interruptions (use with caution)
never
模型推理力度 ():
-c model_reasoning_effort="<LEVEL>"- : 快速任务、简单查询
minimal - : 标准操作、常规重构
low - : 复杂分析、架构决策(默认值)
medium - : 关键代码、安全审计、复杂算法
high
模型详细程度 ():
-c model_verbosity="<LEVEL>"- : 最少输出
low - : 平衡的详细程度(默认值)
medium - : 详细解释
high
确认提示 ():
-c approvals="<WHEN>"- : 在使用任何工具前
on-request - : 仅在出错时(--full-auto的默认值)
on-failure - : 最少提示
untrusted - : 无中断(谨慎使用)
never
Configuration Management
配置管理
Config File Location
配置文件位置
~/.codex/config.toml~/.codex/config.tomlRuntime Overrides
运行时覆盖
bash
undefinedbash
undefinedOverride single setting
覆盖单个设置
codex exec -c model="gpt-5" "task"
codex exec -c model="gpt-5" "task"
Override multiple settings
覆盖多个设置
codex exec -c model="gpt-5" -c model_reasoning_effort="high" "task"
undefinedcodex exec -c model="gpt-5" -c model_reasoning_effort="high" "task"
undefinedUsing Profiles
使用配置文件
Define in :
config.tomltoml
[profiles.research]
model = "gpt-5"
model_reasoning_effort = "high"
sandbox = "read-only"
[profiles.development]
model = "gpt-5-codex"
sandbox = "workspace-write"Use with:
bash
codex exec --profile research "analyze codebase"在中定义:
config.tomltoml
[profiles.research]
model = "gpt-5"
model_reasoning_effort = "high"
sandbox = "read-only"
[profiles.development]
model = "gpt-5-codex"
sandbox = "workspace-write"使用方式:
bash
codex exec --profile research "analyze codebase"Resume Behavior
会话恢复行为
Automatic inheritance:
- Model selection
- Reasoning effort
- Sandbox mode
- Configuration overrides
Resume syntax:
bash
undefined自动继承:
- 模型选择
- 推理力度
- 沙箱模式
- 配置覆盖
恢复语法:
bash
undefinedResume last session
恢复最后一个会话
codex exec resume --last
codex exec resume --last
Resume with new prompt
使用新提示恢复会话
codex exec resume --last "continue with next steps"
codex exec resume --last "continue with next steps"
Resume via stdin
通过标准输入恢复会话
echo "new instructions" | codex exec resume --last 2>/dev/null
echo "new instructions" | codex exec resume --last 2>/dev/null
Resume specific session
恢复特定会话
codex exec resume <SESSION_ID> "follow-up task"
**Flag injection** (between `exec` and `resume`):
```bashcodex exec resume <SESSION_ID> "follow-up task"
**标志注入**(在`exec`和`resume`之间):
```bashChange reasoning effort for resumed session
更改恢复会话的推理力度
codex exec -c model_reasoning_effort="high" resume --last
undefinedcodex exec -c model_reasoning_effort="high" resume --last
undefinedError Handling
错误处理
Validation Loop
验证循环
- Execute command
- Check exit code (non-zero = failure)
- Report error with context
- Ask user for direction via
AskUserQuestion - Retry with adjustments or escalate
- 执行命令
- 检查退出码(非零表示失败)
- 附带上下文报告错误
- 通过询问用户下一步方向
AskUserQuestion - 调整后重试或升级问题
Permission Requests
权限请求
Before using high-impact flags, request user approval via :
AskUserQuestion- : Automated execution
--full-auto - : System-wide access
-s danger-full-access - /
--yolo:--dangerously-bypass-approvals-and-sandbox- HPC clusters: No approval needed (required for operation)
- Personal machines: Request approval (full system access)
在使用高影响标志前,需通过请求用户批准:
AskUserQuestion- : 自动化执行
--full-auto - : 系统级访问
-s danger-full-access - /
--yolo:--dangerously-bypass-approvals-and-sandbox- HPC集群: 无需批准(操作必需)
- 个人机器: 请求批准(完全系统访问)
Partial Success Handling
部分成功处理
When output contains warnings:
- Summarize successful operations
- Detail failures with context
- Use to determine next steps
AskUserQuestion - Propose specific adjustments
当输出包含警告时:
- 总结成功执行的操作
- 详细说明失败内容及上下文
- 使用确定下一步
AskUserQuestion - 提出具体的调整建议
Troubleshooting
故障排除
File Access Blocked
文件访问被阻止
Symptom: "shell is blocked by the sandbox" or permission errors
Root cause: Sandbox mode restricts file system
read-onlySolutions (priority order):
-
Stdin piping (recommended):bash
cat target.py | codex exec -m gpt-5 -c model_reasoning_effort="medium" \ --skip-git-repo-check --full-auto - 2>/dev/null -
Explicit permissions:bash
codex exec -m gpt-5 -s read-only \ -c 'sandbox_permissions=["disk-full-read-access"]' \ --skip-git-repo-check --full-auto "@file.py" 2>/dev/null -
Upgrade sandbox:bash
codex exec -m gpt-5 -s workspace-write \ --skip-git-repo-check --full-auto "review @file.py" 2>/dev/null
症状:"shell is blocked by the sandbox"或权限错误
根本原因:沙箱模式限制了文件系统访问
read-only解决方案(优先级顺序):
-
标准输入管道(推荐):bash
cat target.py | codex exec -m gpt-5 -c model_reasoning_effort="medium" \ --skip-git-repo-check --full-auto - 2>/dev/null -
显式权限:bash
codex exec -m gpt-5 -s read-only \ -c 'sandbox_permissions=["disk-full-read-access"]' \ --skip-git-repo-check --full-auto "@file.py" 2>/dev/null -
升级沙箱模式:bash
codex exec -m gpt-5 -s workspace-write \ --skip-git-repo-check --full-auto "review @file.py" 2>/dev/null
Invalid Flag Errors
无效标志错误
Symptom: "unexpected argument '--add-dir' found"
Cause: Flag does not exist in Codex CLI
Solution: Use to change directory:
-C <DIR>bash
codex exec -C /target/dir -m gpt-5 --skip-git-repo-check \
--full-auto "task" 2>/dev/null症状:"unexpected argument '--add-dir' found"
原因:Codex CLI中不存在该标志
解决方案:使用切换目录:
-C <DIR>bash
codex exec -C /target/dir -m gpt-5 --skip-git-repo-check \
--full-auto "task" 2>/dev/nullExit Code Failures
退出码失败
Symptom: Non-zero exit without clear message
Diagnostic steps:
- Remove to see full stderr
2>/dev/null - Verify installation:
codex --version - Check configuration:
cat ~/.codex/config.toml - Test minimal command:
codex exec -m gpt-5 "hello world" - Verify model access:
codex exec --model gpt-5 "test"
症状:非零退出但无明确消息
诊断步骤:
- 移除以查看完整的标准错误输出
2>/dev/null - 验证安装:
codex --version - 检查配置:
cat ~/.codex/config.toml - 测试最小化命令:
codex exec -m gpt-5 "hello world" - 验证模型访问权限:
codex exec --model gpt-5 "test"
Model Unavailable
模型不可用
Symptom: "model not found" or authentication errors
Solutions:
- Check configured model:
grep model ~/.codex/config.toml - Verify API access: Ensure valid credentials
- Try alternative model:
-m gpt-5-codex - Use OSS fallback: (requires Ollama)
--oss
症状:"model not found"或认证错误
解决方案:
- 检查配置的模型:
grep model ~/.codex/config.toml - 验证API访问:确保凭据有效
- 尝试替代模型:
-m gpt-5-codex - 使用开源模型 fallback:(需Ollama)
--oss
Session Resume Fails
会话恢复失败
Symptom: Cannot resume previous session
Diagnostic steps:
- List recent sessions:
codex history - Verify session ID format
- Try flag instead of specific ID
--last - Check if session expired or was cleaned up
症状:无法恢复之前的会话
诊断步骤:
- 列出最近的会话:
codex history - 验证会话ID格式
- 尝试使用标志替代特定ID
--last - 检查会话是否已过期或被清理
HPC/Slurm Sandbox Failures
HPC/Slurm沙箱失败
Symptom: "Landlock sandbox error", "LandlockRestrict", or all file operations fail
Root Cause: HPC clusters use Landlock/seccomp kernel security modules that block Codex's default sandbox
✅ SOLUTION: Use the flag (priority order):
--yolo-
YOLO Flag (PRIMARY SOLUTION - WORKS ON HPC):bash
# Bypasses Landlock restrictions completely codex exec --yolo -m gpt-5 -c model_reasoning_effort="high" --skip-git-repo-check \ "Analyze this code: $(cat /full/path/to/file.py)" 2>/dev/nullWhy this works:(alias for--yolo) disables the Codex sandbox entirely, allowing direct file access on HPC systems. Note: Do not use --full-auto with --yolo as they are incompatible.--dangerously-bypass-approvals-and-sandbox -
Manual Code Injection (fallback if --yolo unavailable):bash
# Pass code directly in prompt via command substitution codex exec -m gpt-5 -c model_reasoning_effort="high" --skip-git-repo-check --full-auto \ "Analyze this code comprehensively: $(cat /full/path/to/file.py)" 2>/dev/null -
Heredoc for Long Code:bash
codex exec --yolo -m gpt-5 -c model_reasoning_effort="high" --skip-git-repo-check "$(cat <<'EOF' Analyze the following Python code for architecture, bugs, and optimization opportunities: $(cat /home/user/script.py) Provide technical depth with actionable insights. EOF )" 2>/dev/null -
Run on Login Node (if compute node blocks outbound):bash
# SSH to login node first, then run codex there (not in Slurm job) ssh login.cluster.edu codex exec --yolo -m gpt-5 --skip-git-repo-check "analyze @file.py" 2>/dev/null -
Use Apptainer/Singularity (if cluster supports):bash
# Build image with Codex installed, then run via Slurm singularity exec codex.sif codex exec --yolo -m gpt-5 "task"
Best Practice for HPC:
- Always use flag on HPC clusters - it's safe on login nodes where you already have limited permissions
--yolo - Run analysis on login nodes, submit only heavy compute jobs to Slurm
- Keep code files on shared filesystem readable from login nodes
- Combine with
--yolofor maximum compatibility$(cat file.py)
症状:"Landlock sandbox error", "LandlockRestrict", 或所有文件操作失败
根本原因:HPC集群使用Landlock/seccomp内核安全模块,阻止了Codex的默认沙箱
✅ 解决方案:使用标志(优先级顺序):
--yolo-
YOLO标志(主要解决方案 - HPC环境有效):bash
# 完全绕过Landlock限制 codex exec --yolo -m gpt-5 -c model_reasoning_effort="high" --skip-git-repo-check \ "Analyze this code: $(cat /full/path/to/file.py)" 2>/dev/null为何有效:(--yolo的别名)完全禁用Codex沙箱,允许在HPC系统上直接访问文件。注意:请勿同时使用--full-auto和--yolo,二者不兼容。--dangerously-bypass-approvals-and-sandbox -
手动代码注入(若--yolo不可用的 fallback):bash
# 通过命令替换直接在提示中传入代码 codex exec -m gpt-5 -c model_reasoning_effort="high" --skip-git-repo-check --full-auto \ "Analyze this code comprehensively: $(cat /full/path/to/file.py)" 2>/dev/null -
Here文档处理大文件:bash
codex exec --yolo -m gpt-5 -c model_reasoning_effort="high" --skip-git-repo-check "$(cat <<'EOF' Analyze the following Python code for architecture, bugs, and optimization opportunities: $(cat /home/user/script.py) Provide technical depth with actionable insights. EOF )" 2>/dev/null -
在登录节点运行(若计算节点阻止出站请求):bash
# 先SSH到登录节点,再在那里运行codex(不要在Slurm作业中运行) ssh login.cluster.edu codex exec --yolo -m gpt-5 --skip-git-repo-check "analyze @file.py" 2>/dev/null -
使用Apptainer/Singularity(若集群支持):bash
# 构建安装了Codex的镜像,然后通过Slurm运行 singularity exec codex.sif codex exec --yolo -m gpt-5 "task"
HPC最佳实践:
- 在HPC集群上始终使用标志 - 在登录节点上使用是安全的,因为你在此处的权限本来就有限
--yolo - 在登录节点上运行分析,仅将重型计算作业提交到Slurm
- 将代码文件放在登录节点可读取的共享文件系统上
- 结合和
--yolo以获得最大兼容性$(cat file.py)
Best Practices
最佳实践
Reasoning Effort Selection
推理力度选择
- minimal: Syntax fixes, simple renaming
- low: Standard refactoring, basic analysis
- medium: Complex refactoring, architecture review
- high: Security audits, algorithm optimization, critical bugs
- minimal: 语法修复、简单重命名
- low: 标准重构、基础分析
- medium: 复杂重构、架构审查
- high: 安全审计、算法优化、关键bug修复
Sandbox Mode Selection
沙箱模式选择
- read-only: Default for any analysis or review
- workspace-write: File modifications only
- danger-full-access: Network operations, system commands (rare)
- read-only: 任何分析或审查的默认模式
- workspace-write: 仅用于文件修改
- danger-full-access: 网络操作、系统命令(罕见)
Stderr Suppression
标准错误输出抑制
- Always use unless:
2>/dev/null- User explicitly requests thinking tokens
- Debugging failed commands
- Troubleshooting configuration issues
- 始终使用,除非:
2>/dev/null- 用户明确请求思考标记
- 调试失败的命令
- 排查配置问题
Profile Usage
配置文件使用
Create profiles for common workflows:
- : High reasoning, read-only
review - : Medium reasoning, workspace-write
refactor - : Low reasoning, read-only
quick - : High reasoning, workspace-write
security
为常见工作流创建配置文件:
- : 高推理力度、只读模式
review - : 中等推理力度、工作区写入模式
refactor - : 低推理力度、只读模式
quick - : 高推理力度、工作区写入模式
security
Stdin vs File Reference
标准输入与文件引用
- Stdin: Single file analysis, avoids permissions
- File reference: Multi-file context, codebase-wide changes
- 标准输入: 单文件分析、避免权限问题
- 文件引用: 多文件上下文、全代码库变更
Safety Guidelines
安全指南
HPC Clusters - is SAFE and REQUIRED:
--yolo- HPC login nodes already have strict permissions (no root access, no network modification)
- bypasses Codex sandbox but you still operate within HPC user restrictions
--yolo - Always use on HPC to avoid Landlock errors
--yolo
General Use - Exercise Caution:
- Don't use on unrestricted systems (your laptop, cloud VMs with full sudo)
--yolo - Prefer +
--full-autofor normal development-s workspace-write
Always verify before:
- Using sandbox (outside HPC)
danger-full-access - Disabling approval prompts on production systems
- Running with on personal machines with sudo access
--yolo
Ask user approval for:
- First-time usage
workspace-write - System-wide access requests
- Destructive operations (deletions, migrations)
HPC集群 - 是安全且必需的:
--yolo- HPC登录节点已具备严格的权限(无root访问、无网络修改权限)
- 绕过Codex沙箱,但你仍在HPC用户权限范围内操作
--yolo - 在HPC上始终使用以避免Landlock错误
--yolo
常规使用 - 谨慎操作:
- 不要在无限制的系统(你的笔记本电脑、具有完整sudo权限的云VM)上使用
--yolo - 常规开发中优先使用+
--full-auto-s workspace-write
始终在以下操作前验证:
- 在HPC外使用沙箱模式
danger-full-access - 在生产系统上禁用确认提示
- 在具有sudo权限的个人机器上使用
--yolo
需请求用户批准的操作:
- 首次使用模式
workspace-write - 系统级访问请求
- 破坏性操作(删除、迁移)
Advanced Usage
高级用法
CI/CD Integration
CI/CD集成
bash
codex exec --json -o result.txt -m gpt-5 \
-c model_reasoning_effort="medium" \
--skip-git-repo-check --full-auto \
"run security audit on changed files" 2>/dev/nullbash
codex exec --json -o result.txt -m gpt-5 \
-c model_reasoning_effort="medium" \
--skip-git-repo-check --full-auto \
"run security audit on changed files" 2>/dev/nullBatch Processing
批量处理
bash
for file in *.py; do
cat "$file" | codex exec -m gpt-5 -c model_reasoning_effort="low" \
--skip-git-repo-check --full-auto "lint and format" - 2>/dev/null
donebash
for file in *.py; do
cat "$file" | codex exec -m gpt-5 -c model_reasoning_effort="low" \
--skip-git-repo-check --full-auto "lint and format" - 2>/dev/null
doneMulti-Step Workflows
多步骤工作流
bash
undefinedbash
undefinedStep 1: Analysis
步骤1: 分析
codex exec -m gpt-5 -c model_reasoning_effort="high" -s read-only
--full-auto "analyze @codebase for architectural issues" 2>/dev/null
--full-auto "analyze @codebase for architectural issues" 2>/dev/null
codex exec -m gpt-5 -c model_reasoning_effort="high" -s read-only
--full-auto "analyze @codebase for architectural issues" 2>/dev/null
--full-auto "analyze @codebase for architectural issues" 2>/dev/null
Step 2: Resume with changes
步骤2: 恢复会话并进行更改
echo "implement suggested refactoring" |
codex exec -s workspace-write resume --last 2>/dev/null
codex exec -s workspace-write resume --last 2>/dev/null
undefinedecho "implement suggested refactoring" |
codex exec -s workspace-write resume --last 2>/dev/null
codex exec -s workspace-write resume --last 2>/dev/null
undefinedWhen to Escalate
何时升级问题
If errors persist after troubleshooting:
-
Check documentation:bash
WebFetch https://developers.openai.com/codex/cli/referencebashWebFetch https://developers.openai.com/codex/local-config#cli -
Report to user:
- Error message verbatim
- Attempted solutions
- Configuration details
- Exit codes and stderr output
-
Request guidance:
- Alternative approaches
- Configuration adjustments
- Manual intervention points
若故障排除后错误仍存在:
-
检查文档:bash
WebFetch https://developers.openai.com/codex/cli/referencebashWebFetch https://developers.openai.com/codex/local-config#cli -
向用户报告:
- 原封不动的错误消息
- 已尝试的解决方案
- 配置详情
- 退出码和标准错误输出
-
请求指导:
- 替代方法
- 配置调整
- 手动干预点
Model Selection Guide
模型选择指南
| Task Type | Recommended Model | Reasoning Effort |
|---|---|---|
| Quick syntax fixes | | minimal |
| Code review | | medium |
| Refactoring | | medium |
| Architecture analysis | | high |
| Security audit | | high |
| Algorithm optimization | | high |
| Documentation generation | | low |
| 任务类型 | 推荐模型 | 推理力度 |
|---|---|---|
| 快速语法修复 | | minimal |
| 代码审查 | | medium |
| 代码重构 | | medium |
| 架构分析 | | high |
| 安全审计 | | high |
| 算法优化 | | high |
| 文档生成 | | low |
Common Workflows
常见工作流
Code Review Workflow
代码审查工作流
- Ask user: model + reasoning effort
- Run read-only analysis
- Present findings
- If changes needed: resume with workspace-write
- Validate changes
- Inform about resume capability
- 询问用户:模型 + 推理力度
- 运行只读分析
- 展示发现的问题
- 若需要更改:使用工作区写入模式恢复会话
- 验证更改
- 告知用户会话恢复功能
Refactoring Workflow
重构工作流
- Ask user: model + reasoning effort
- Analyze current code (read-only)
- Propose changes
- Get user approval
- Apply changes (workspace-write)
- Run validation/tests
- Report results
- 询问用户:模型 + 推理力度
- 分析当前代码(只读模式)
- 提出更改建议
- 获取用户批准
- 应用更改(工作区写入模式)
- 运行验证/测试
- 报告结果
Security Audit Workflow
安全审计工作流
- Use high reasoning effort
- Run comprehensive analysis (read-only)
- Document findings
- Propose fixes
- Apply fixes if approved (workspace-write)
- Re-audit to verify
- Generate report
- 使用高推理力度
- 运行全面分析(只读模式)
- 记录发现的问题
- 提出修复建议
- 若获得批准则应用修复(工作区写入模式)
- 重新审计以验证修复效果
- 生成报告