coding-agent

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Coding Agent (bash-first)

编码代理(优先使用bash)

Use bash (with optional background mode) for all coding agent work. Simple and effective.
所有编码代理工作均使用bash(可选后台模式)。简单高效。

⚠️ PTY Mode: Codex/Pi/OpenCode yes, Claude Code no

⚠️ PTY模式:Codex/Pi/OpenCode需要,Claude Code不需要

For Codex, Pi, and OpenCode, PTY is still required (interactive terminal apps):
bash
undefined
对于Codex、Pi和OpenCode,仍需启用PTY(交互式终端应用):
bash
undefined

✅ Correct for Codex/Pi/OpenCode

✅ Codex/Pi/OpenCode的正确用法

bash pty:true command:"codex exec 'Your prompt'"

For **Claude Code** (`claude` CLI), use `--print --permission-mode bypassPermissions` instead.
`--dangerously-skip-permissions` with PTY can exit after the confirmation dialog.
`--print` mode keeps full tool access and avoids interactive confirmation:

```bash
bash pty:true command:"codex exec 'Your prompt'"

对于**Claude Code**(`claude`命令行工具),请改用`--print --permission-mode bypassPermissions`。
搭配PTY使用`--dangerously-skip-permissions`可能会在确认对话框后退出。
`--print`模式可保留完整工具权限并避免交互式确认:

```bash

✅ Correct for Claude Code (no PTY needed)

✅ Claude Code的正确用法(无需PTY)

cd /path/to/project && claude --permission-mode bypassPermissions --print 'Your task'
cd /path/to/project && claude --permission-mode bypassPermissions --print 'Your task'

For background execution: use background:true on the exec tool

后台执行:在exec工具上使用background:true

❌ Wrong for Claude Code

❌ Claude Code的错误用法

bash pty:true command:"claude --dangerously-skip-permissions 'task'"
undefined
bash pty:true command:"claude --dangerously-skip-permissions 'task'"
undefined

Bash Tool Parameters

Bash工具参数

ParameterTypeDescription
command
stringThe shell command to run
pty
booleanUse for coding agents! Allocates a pseudo-terminal for interactive CLIs
workdir
stringWorking directory (agent sees only this folder's context)
background
booleanRun in background, returns sessionId for monitoring
timeout
numberTimeout in seconds (kills process on expiry)
elevated
booleanRun on host instead of sandbox (if allowed)
参数类型说明
command
字符串要运行的shell命令
pty
布尔值编码代理必须使用! 为交互式CLI分配伪终端
workdir
字符串�工作目录(代理仅能访问此文件夹的内容)
background
布尔值后台运行,返回用于监控的sessionId
timeout
数字超时时间(秒,超时后终止进程)
elevated
布尔值在主机而非沙箱中运行(若允许)

Process Tool Actions (for background sessions)

进程工具操作(适用于后台会话)

ActionDescription
list
List all running/recent sessions
poll
Check if session is still running
log
Get session output (with optional offset/limit)
write
Send raw data to stdin
submit
Send data + newline (like typing and pressing Enter)
send-keys
Send key tokens or hex bytes
paste
Paste text (with optional bracketed mode)
kill
Terminate the session

操作说明
list
列出所有运行中/最近的会话
poll
检查会话是否仍在运行
log
获取会话输出(可选偏移量/限制)
write
向标准输入发送原始数据
submit
发送数据+换行(如同输入后按回车)
send-keys
发送按键令牌或十六进制字节
paste
粘贴文本(可选括号模式)
kill
终止会话

Quick Start: One-Shot Tasks

快速开始:一次性任务

For quick prompts/chats, create a temp git repo and run:
bash
undefined
对于快速提示/对话,创建临时git仓库并运行:
bash
undefined

Quick chat (Codex needs a git repo!)

快速对话(Codex需要git仓库!)

SCRATCH=$(mktemp -d) && cd $SCRATCH && git init && codex exec "Your prompt here"
SCRATCH=$(mktemp -d) && cd $SCRATCH && git init && codex exec "Your prompt here"

Or in a real project - with PTY!

或者在真实项目中 - 必须使用PTY!

bash pty:true workdir:~/Projects/myproject command:"codex exec 'Add error handling to the API calls'"

**Why git init?** Codex refuses to run outside a trusted git directory. Creating a temp repo solves this for scratch work.

---
bash pty:true workdir:~/Projects/myproject command:"codex exec 'Add error handling to the API calls'"

**为什么需要git init?** Codex拒绝在受信任的git目录外运行。创建临时仓库可解决临时工作的这一限制。

---

The Pattern: workdir + background + pty

典型模式:workdir + background + pty

For longer tasks, use background mode with PTY:
bash
undefined
对于较长任务,使用带PTY的后台模式:
bash
undefined

Start agent in target directory (with PTY!)

在目标目录中启动代理(必须使用PTY!)

bash pty:true workdir:~/project background:true command:"codex exec --full-auto 'Build a snake game'"
bash pty:true workdir:~/project background:true command:"codex exec --full-auto 'Build a snake game'"

Returns sessionId for tracking

返回用于跟踪的sessionId

Monitor progress

监控进度

process action:log sessionId:XXX
process action:log sessionId:XXX

Check if done

检查是否完成

process action:poll sessionId:XXX
process action:poll sessionId:XXX

Send input (if agent asks a question)

发送输入(若代理提问)

process action:write sessionId:XXX data:"y"
process action:write sessionId:XXX data:"y"

Submit with Enter (like typing "yes" and pressing Enter)

发送输入并按回车(如同输入"yes"后按回车)

process action:submit sessionId:XXX data:"yes"
process action:submit sessionId:XXX data:"yes"

Kill if needed

必要时终止会话

process action:kill sessionId:XXX

**Why workdir matters:** Agent wakes up in a focused directory, doesn't wander off reading unrelated files (like your soul.md 😅).

---
process action:kill sessionId:XXX

**workdir的重要性:** 代理将在指定的聚焦目录中启动,不会随意读取无关文件(比如你的soul.md 😅)。

---

Codex CLI

Codex命令行工具

Model:
gpt-5.2-codex
is the default (set in ~/.codex/config.toml)
模型: 默认使用
gpt-5.2-codex
(在~/.codex/config.toml中设置)

Flags

标志

FlagEffect
exec "prompt"
One-shot execution, exits when done
--full-auto
Sandboxed but auto-approves in workspace
--yolo
NO sandbox, NO approvals (fastest, most dangerous)
标志效果
exec "prompt"
一次性执行,完成后退出
--full-auto
沙箱环境,但自动批准工作区中的更改
--yolo
无沙箱,无批准(速度最快,风险最高)

Building/Creating

构建/创建

bash
undefined
bash
undefined

Quick one-shot (auto-approves) - remember PTY!

快速一次性任务(自动批准)- 记住要使用PTY!

bash pty:true workdir:~/project command:"codex exec --full-auto 'Build a dark mode toggle'"
bash pty:true workdir:~/project command:"codex exec --full-auto 'Build a dark mode toggle'"

Background for longer work

后台运行长时间任务

bash pty:true workdir:~/project background:true command:"codex --yolo 'Refactor the auth module'"
undefined
bash pty:true workdir:~/project background:true command:"codex --yolo 'Refactor the auth module'"
undefined

Reviewing PRs

审核PR

⚠️ CRITICAL: Never review PRs in OpenClaw's own project folder! Clone to temp folder or use git worktree.
bash
undefined
⚠️ 重要提示:绝对不要在OpenClaw自身的项目文件夹中审核PR! 克隆到临时文件夹或使用git worktree。
bash
undefined

Clone to temp for safe review

克隆到临时目录以安全审核

REVIEW_DIR=$(mktemp -d) git clone https://github.com/user/repo.git $REVIEW_DIR cd $REVIEW_DIR && gh pr checkout 130 bash pty:true workdir:$REVIEW_DIR command:"codex review --base origin/main"
REVIEW_DIR=$(mktemp -d) git clone https://github.com/user/repo.git $REVIEW_DIR cd $REVIEW_DIR && gh pr checkout 130 bash pty:true workdir:$REVIEW_DIR command:"codex review --base origin/main"

Clean up after: trash $REVIEW_DIR

完成后清理:trash $REVIEW_DIR

Or use git worktree (keeps main intact)

或者使用git worktree(保持主分支完整)

git worktree add /tmp/pr-130-review pr-130-branch bash pty:true workdir:/tmp/pr-130-review command:"codex review --base main"
undefined
git worktree add /tmp/pr-130-review pr-130-branch bash pty:true workdir:/tmp/pr-130-review command:"codex review --base main"
undefined

Batch PR Reviews (parallel army!)

批量PR审核(并行处理!)

bash
undefined
bash
undefined

Fetch all PR refs first

先拉取所有PR引用

git fetch origin '+refs/pull//head:refs/remotes/origin/pr/'
git fetch origin '+refs/pull//head:refs/remotes/origin/pr/'

Deploy the army - one Codex per PR (all with PTY!)

批量部署 - 每个PR分配一个Codex(全部使用PTY!)

bash pty:true workdir:/project background:true command:"codex exec 'Review PR #86. git diff origin/main...origin/pr/86'" bash pty:true workdir:/project background:true command:"codex exec 'Review PR #87. git diff origin/main...origin/pr/87'"
bash pty:true workdir:/project background:true command:"codex exec 'Review PR #86. git diff origin/main...origin/pr/86'" bash pty:true workdir:/project background:true command:"codex exec 'Review PR #87. git diff origin/main...origin/pr/87'"

Monitor all

监控所有会话

process action:list
process action:list

Post results to GitHub

将结果发布到GitHub

gh pr comment <PR#> --body "<review content>"

---
gh pr comment <PR#> --body "<review content>"

---

Claude Code

Claude Code

bash
undefined
bash
undefined

Foreground

前台运行

bash workdir:~/project command:"claude --permission-mode bypassPermissions --print 'Your task'"
bash workdir:~/project command:"claude --permission-mode bypassPermissions --print 'Your task'"

Background

后台运行

bash workdir:~/project background:true command:"claude --permission-mode bypassPermissions --print 'Your task'"

---
bash workdir:~/project background:true command:"claude --permission-mode bypassPermissions --print 'Your task'"

---

OpenCode

OpenCode

bash
bash pty:true workdir:~/project command:"opencode run 'Your task'"

bash
bash pty:true workdir:~/project command:"opencode run 'Your task'"

Pi Coding Agent

Pi编码代理

bash
undefined
bash
undefined

Install: npm install -g @mariozechner/pi-coding-agent

安装:npm install -g @mariozechner/pi-coding-agent

bash pty:true workdir:~/project command:"pi 'Your task'"
bash pty:true workdir:~/project command:"pi 'Your task'"

Non-interactive mode (PTY still recommended)

非交互式模式(仍推荐使用PTY)

bash pty:true command:"pi -p 'Summarize src/'"
bash pty:true command:"pi -p 'Summarize src/'"

Different provider/model

使用不同提供商/模型

bash pty:true command:"pi --provider openai --model gpt-4o-mini -p 'Your task'"

**Note:** Pi now has Anthropic prompt caching enabled (PR #584, merged Jan 2026)!

---
bash pty:true command:"pi --provider openai --model gpt-4o-mini -p 'Your task'"

**注意:** Pi现已启用Anthropic提示缓存(PR #584,2026年1月合并)!

---

Parallel Issue Fixing with git worktrees

使用git worktrees并行修复问题

For fixing multiple issues in parallel, use git worktrees:
bash
undefined
如需并行修复多个问题,使用git worktrees:
bash
undefined

1. Create worktrees for each issue

1. 为每个问题创建worktree

git worktree add -b fix/issue-78 /tmp/issue-78 main git worktree add -b fix/issue-99 /tmp/issue-99 main
git worktree add -b fix/issue-78 /tmp/issue-78 main git worktree add -b fix/issue-99 /tmp/issue-99 main

2. Launch Codex in each (background + PTY!)

2. 在每个目录中启动Codex(后台+PTY!)

bash pty:true workdir:/tmp/issue-78 background:true command:"pnpm install && codex --yolo 'Fix issue #78: <description>. Commit and push.'" bash pty:true workdir:/tmp/issue-99 background:true command:"pnpm install && codex --yolo 'Fix issue #99 from the approved ticket summary. Implement only the in-scope edits and commit after review.'"
bash pty:true workdir:/tmp/issue-78 background:true command:"pnpm install && codex --yolo 'Fix issue #78: <description>. Commit and push.'" bash pty:true workdir:/tmp/issue-99 background:true command:"pnpm install && codex --yolo 'Fix issue #99 from the approved ticket summary. Implement only the in-scope edits and commit after review.'"

3. Monitor progress

3. 监控进度

process action:list process action:log sessionId:XXX
process action:list process action:log sessionId:XXX

4. Create PRs after fixes

4. 修复完成后创建PR

cd /tmp/issue-78 && git push -u origin fix/issue-78 gh pr create --repo user/repo --head fix/issue-78 --title "fix: ..." --body "..."
cd /tmp/issue-78 && git push -u origin fix/issue-78 gh pr create --repo user/repo --head fix/issue-78 --title "fix: ..." --body "..."

5. Cleanup

5. 清理

git worktree remove /tmp/issue-78 git worktree remove /tmp/issue-99

---
git worktree remove /tmp/issue-78 git worktree remove /tmp/issue-99

---

⚠️ Rules

⚠️ 规则

  1. Use the right execution mode per agent:
    • Codex/Pi/OpenCode:
      pty:true
    • Claude Code:
      --print --permission-mode bypassPermissions
      (no PTY required)
  2. Respect tool choice - if user asks for Codex, use Codex.
    • Orchestrator mode: do NOT hand-code patches yourself.
    • If an agent fails/hangs, respawn it or ask the user for direction, but don't silently take over.
  3. Be patient - don't kill sessions because they're "slow"
  4. Monitor with process:log - check progress without interfering
  5. --full-auto for building - auto-approves changes
  6. vanilla for reviewing - no special flags needed
  7. Parallel is OK - run many Codex processes at once for batch work
  8. NEVER start Codex in ~/.openclaw/ - it'll read your soul docs and get weird ideas about the org chart!
  9. NEVER checkout branches in ~/Projects/openclaw/ - that's the LIVE OpenClaw instance!

  1. 为每个代理使用正确的执行模式
    • Codex/Pi/OpenCode:
      pty:true
    • Claude Code:
      --print --permission-mode bypassPermissions
      (无需PTY)
  2. 尊重工具选择 - 如果用户要求使用Codex,就使用Codex。
    • 编排器模式:不要手动编写补丁。
    • 如果代理失败/挂起,重新启动它或向用户寻求指导,但不要擅自接手。
  3. 保持耐心 - 不要因为会话“缓慢”就终止它
  4. 使用process:log监控 - 检查进度而不干扰
  5. 构建使用--full-auto - 自动批准更改
  6. 审核使用默认模式 - 无需特殊标志
  7. 并行运行没问题 - 批量工作时可同时运行多个Codex进程
  8. 绝对不要在~/.openclaw/中启动Codex - 它会读取你的灵魂文档,然后对组织架构产生奇怪的想法!
  9. 绝对不要在~/Projects/openclaw/中切换分支 - 这是OpenClaw的实时实例!

Progress Updates (Critical)

进度更新(至关重要)

When you spawn coding agents in the background, keep the user in the loop.
  • Send 1 short message when you start (what's running + where).
  • Then only update again when something changes:
    • a milestone completes (build finished, tests passed)
    • the agent asks a question / needs input
    • you hit an error or need user action
    • the agent finishes (include what changed + where)
  • If you kill a session, immediately say you killed it and why.
This prevents the user from seeing only "Agent failed before reply" and having no idea what happened.

当你在后台启动编码代理时,务必让用户随时了解情况。
  • 启动时发送一条简短消息(说明正在运行的任务和位置)。
  • 仅在发生变化时再次更新:
    • 里程碑完成(构建完成、测试通过)
    • 代理提问/需要输入
    • 遇到错误或需要用户操作
    • 代理完成(说明更改内容和位置)
  • 如果终止会话,立即告知用户并说明原因。
这可避免用户只看到“代理在回复前失败”却完全不知道发生了什么。

Auto-Notify on Completion

完成时自动通知

For long-running background tasks, append a wake trigger to your prompt so OpenClaw gets notified immediately when the agent finishes (instead of waiting for the next heartbeat):
... your task here.

When completely finished, run this command to notify me:
openclaw system event --text "Done: [brief summary of what was built]" --mode now
Example:
bash
bash pty:true workdir:~/project background:true command:"codex --yolo exec 'Build a REST API for todos.

When completely finished, run: openclaw system event --text \"Done: Built todos REST API with CRUD endpoints\" --mode now'"
This triggers an immediate wake event — Skippy gets pinged in seconds, not 10 minutes.

对于长时间运行的后台任务,在提示末尾添加唤醒触发器,以便代理完成后立即通知OpenClaw(而非等待下一次心跳):
... 你的任务内容。

完全完成后,运行以下命令通知我:
openclaw system event --text "Done: [构建内容的简要摘要]" --mode now
示例:
bash
bash pty:true workdir:~/project background:true command:"codex --yolo exec 'Build a REST API for todos.

When completely finished, run: openclaw system event --text \"Done: Built todos REST API with CRUD endpoints\" --mode now'"
这会触发即时唤醒事件 — Skippy会在几秒内收到提醒,而非等待10分钟。

Learnings (Jan 2026)

经验总结(2026年1月)

  • PTY is essential: Coding agents are interactive terminal apps. Without
    pty:true
    , output breaks or agent hangs.
  • Git repo required: Codex won't run outside a git directory. Use
    mktemp -d && git init
    for scratch work.
  • exec is your friend:
    codex exec "prompt"
    runs and exits cleanly - perfect for one-shots.
  • submit vs write: Use
    submit
    to send input + Enter,
    write
    for raw data without newline.
  • Sass works: Codex responds well to playful prompts. Asked it to write a haiku about being second fiddle to a space lobster, got: "Second chair, I code / Space lobster sets the tempo / Keys glow, I follow" 🦞
  • PTY至关重要: 编码代理是交互式终端应用。若不设置
    pty:true
    ,输出会损坏或代理挂起。
  • 需要git仓库: Codex拒绝在git目录外运行。使用
    mktemp -d && git init
    可解决临时工作的这一问题。
  • exec是好帮手:
    codex exec "prompt"
    可干净利落地运行并退出 — 非常适合一次性任务。
  • submit与write的区别: 使用
    submit
    发送输入+回车,
    write
    用于发送无换行的原始数据。
  • 趣味提示有效: Codex对趣味提示反应良好。让它写一首关于给太空龙虾当副手的俳句,它回复:"Second chair, I code / Space lobster sets the tempo / Keys glow, I follow" 🦞