codex
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseCodex CLI
Codex CLI
Delegate coding tasks to Codex via the Hermes terminal. Codex is OpenAI's autonomous coding agent CLI.
通过Hermes终端将编码任务委托给Codex。Codex是OpenAI的自主编码Agent CLI。
When to use
使用场景
- Building features
- Refactoring
- PR reviews
- Batch issue fixing
Requires the codex CLI and a git repository.
- 功能开发
- 代码重构
- PR评审
- 批量修复问题
需要安装codex CLI并处于git仓库环境中。
Prerequisites
前置条件
- Codex installed:
npm install -g @openai/codex - OpenAI auth configured: either or Codex OAuth credentials from the Codex CLI login flow
OPENAI_API_KEY - Must run inside a git repository — Codex refuses to run outside one
- Use in terminal calls — Codex is an interactive terminal app
pty=true
For Hermes itself, uses Hermes-managed Codex
OAuth from after . For the
standalone Codex CLI, a valid CLI OAuth session may live under
; do not treat a missing alone as proof
that Codex auth is missing.
model.provider: openai-codex~/.hermes/auth.jsonhermes auth add openai-codex~/.codex/auth.jsonOPENAI_API_KEY- 已安装Codex:
npm install -g @openai/codex - 已配置OpenAI认证:可通过或Codex CLI登录流程获取的Codex OAuth凭证
OPENAI_API_KEY - 必须在git仓库内运行——Codex拒绝在仓库外运行
- 在终端调用中使用——Codex是交互式终端应用
pty=true
对于Hermes本身,会使用Hermes管理的Codex OAuth,该凭证存储在中,需先执行。对于独立的Codex CLI,有效的CLI OAuth会话可能存储在中;不要仅因缺少就判定Codex认证缺失。
model.provider: openai-codex~/.hermes/auth.jsonhermes auth add openai-codex~/.codex/auth.jsonOPENAI_API_KEYOne-Shot Tasks
一次性任务
terminal(command="codex exec 'Add dark mode toggle to settings'", workdir="~/project", pty=true)For scratch work (Codex needs a git repo):
terminal(command="cd $(mktemp -d) && git init && codex exec 'Build a snake game in Python'", pty=true)terminal(command="codex exec 'Add dark mode toggle to settings'", workdir="~/project", pty=true)对于临时工作(Codex需要git仓库):
terminal(command="cd $(mktemp -d) && git init && codex exec 'Build a snake game in Python'", pty=true)Background Mode (Long Tasks)
后台模式(长时任务)
undefinedundefinedStart in background with PTY
启动带PTY的后台任务
terminal(command="codex exec --full-auto 'Refactor the auth module'", workdir="~/project", background=true, pty=true)
terminal(command="codex exec --full-auto 'Refactor the auth module'", workdir="~/project", background=true, pty=true)
Returns session_id
返回session_id
Monitor progress
监控进度
process(action="poll", session_id="<id>")
process(action="log", session_id="<id>")
process(action="poll", session_id="<id>")
process(action="log", session_id="<id>")
Send input if Codex asks a question
当Codex提问时发送输入
process(action="submit", session_id="<id>", data="yes")
process(action="submit", session_id="<id>", data="yes")
Kill if needed
必要时终止任务
process(action="kill", session_id="<id>")
undefinedprocess(action="kill", session_id="<id>")
undefinedKey Flags
关键参数
| Flag | Effect |
|---|---|
| One-shot execution, exits when done |
| Sandboxed but auto-approves file changes in workspace |
| No sandbox, no approvals (fastest, most dangerous) |
| 参数 | 作用 |
|---|---|
| 一次性执行,完成后退出 |
| 沙箱环境下自动批准工作区中的文件变更 |
| 无沙箱、无批准(速度最快,风险最高) |
PR Reviews
PR评审
Clone to a temp directory for safe review:
terminal(command="REVIEW=$(mktemp -d) && git clone https://github.com/user/repo.git $REVIEW && cd $REVIEW && gh pr checkout 42 && codex review --base origin/main", pty=true)克隆到临时目录以安全评审:
terminal(command="REVIEW=$(mktemp -d) && git clone https://github.com/user/repo.git $REVIEW && cd $REVIEW && gh pr checkout 42 && codex review --base origin/main", pty=true)Parallel Issue Fixing with Worktrees
使用工作树批量修复问题
undefinedundefinedCreate worktrees
创建工作树
terminal(command="git worktree add -b fix/issue-78 /tmp/issue-78 main", workdir="/project")
terminal(command="git worktree add -b fix/issue-99 /tmp/issue-99 main", workdir="/project")
terminal(command="git worktree add -b fix/issue-78 /tmp/issue-78 main", workdir="/project")
terminal(command="git worktree add -b fix/issue-99 /tmp/issue-99 main", workdir="/project")
Launch Codex in each
在每个工作树中启动Codex
terminal(command="codex --yolo exec 'Fix issue #78: <description>. Commit when done.'", workdir="/tmp/issue-78", background=true, pty=true)
terminal(command="codex --yolo exec 'Fix issue #99: <description>. Commit when done.'", workdir="/tmp/issue-99", background=true, pty=true)
terminal(command="codex --yolo exec 'Fix issue #78: <description>. Commit when done.'", workdir="/tmp/issue-78", background=true, pty=true)
terminal(command="codex --yolo exec 'Fix issue #99: <description>. Commit when done.'", workdir="/tmp/issue-99", background=true, pty=true)
Monitor
监控任务
process(action="list")
process(action="list")
After completion, push and create PRs
完成后推送并创建PR
terminal(command="cd /tmp/issue-78 && git push -u origin fix/issue-78")
terminal(command="gh pr create --repo user/repo --head fix/issue-78 --title 'fix: ...' --body '...'")
terminal(command="cd /tmp/issue-78 && git push -u origin fix/issue-78")
terminal(command="gh pr create --repo user/repo --head fix/issue-78 --title 'fix: ...' --body '...'")
Cleanup
清理工作树
terminal(command="git worktree remove /tmp/issue-78", workdir="~/project")
undefinedterminal(command="git worktree remove /tmp/issue-78", workdir="~/project")
undefinedBatch PR Reviews
批量PR评审
undefinedundefinedFetch all PR refs
获取所有PR引用
terminal(command="git fetch origin '+refs/pull//head:refs/remotes/origin/pr/'", workdir="~/project")
terminal(command="git fetch origin '+refs/pull//head:refs/remotes/origin/pr/'", workdir="~/project")
Review multiple PRs in parallel
并行评审多个PR
terminal(command="codex exec 'Review PR #86. git diff origin/main...origin/pr/86'", workdir="/project", background=true, pty=true)
terminal(command="codex exec 'Review PR #87. git diff origin/main...origin/pr/87'", workdir="/project", background=true, pty=true)
terminal(command="codex exec 'Review PR #86. git diff origin/main...origin/pr/86'", workdir="/project", background=true, pty=true)
terminal(command="codex exec 'Review PR #87. git diff origin/main...origin/pr/87'", workdir="/project", background=true, pty=true)
Post results
发布评审结果
terminal(command="gh pr comment 86 --body '<review>'", workdir="~/project")
undefinedterminal(command="gh pr comment 86 --body '<review>'", workdir="~/project")
undefinedRules
规则
- Always use — Codex is an interactive terminal app and hangs without a PTY
pty=true - Git repo required — Codex won't run outside a git directory. Use for scratch
mktemp -d && git init - Use for one-shots —
execruns and exits cleanlycodex exec "prompt" - for building — auto-approves changes within the sandbox
--full-auto - Background for long tasks — use and monitor with
background=truetoolprocess - Don't interfere — monitor with /
poll, be patient with long-running taskslog - Parallel is fine — run multiple Codex processes at once for batch work
- 始终使用——Codex是交互式终端应用,没有PTY会挂起
pty=true - 必须使用git仓库——Codex不会在git目录外运行。临时工作可使用
mktemp -d && git init - 一次性任务使用——
exec运行完成后会干净退出codex exec "prompt" - 开发时使用——在沙箱内自动批准变更
--full-auto - 长时任务使用后台模式——使用并通过
background=true工具监控process - 不要干预——使用/
poll监控,对长时任务保持耐心log - 支持并行运行——可同时运行多个Codex进程处理批量任务