coding-agent
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseCoding Agent (bash-first)
编码Agent(优先使用bash)
Use bash (with optional background mode) for all coding agent work. Simple and effective.
所有编码Agent相关工作都使用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:
```bashbash pty:true command:"codex exec 'Your prompt'"
对于**Claude Code**(`claude` CLI),请改用`--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'"
undefinedbash pty:true command:"claude --dangerously-skip-permissions 'task'"
undefinedBash Tool Parameters
Bash工具参数
| Parameter | Type | Description |
|---|---|---|
| string | The shell command to run |
| boolean | Use for coding agents! Allocates a pseudo-terminal for interactive CLIs |
| string | Working directory (agent sees only this folder's context) |
| boolean | Run in background, returns sessionId for monitoring |
| number | Timeout in seconds (kills process on expiry) |
| boolean | Run on host instead of sandbox (if allowed) |
| 参数名 | 类型 | 描述 |
|---|---|---|
| string | 要运行的shell命令 |
| boolean | 编码Agent必须使用! 为交互式CLI分配伪终端 |
| string | 工作目录(Agent仅能看到该文件夹的上下文) |
| boolean | 后台运行,返回sessionId用于监控 |
| number | 超时时间(秒,到期后将杀死进程) |
| boolean | 在主机而非沙箱中运行(如果有权限) |
Process Tool Actions (for background sessions)
进程工具操作(用于后台会话)
| Action | Description |
|---|---|
| List all running/recent sessions |
| Check if session is still running |
| Get session output (with optional offset/limit) |
| Send raw data to stdin |
| Send data + newline (like typing and pressing Enter) |
| Send key tokens or hex bytes |
| Paste text (with optional bracketed mode) |
| Terminate the session |
| 操作名 | 描述 |
|---|---|
| 列出所有正在运行/近期的会话 |
| 检查会话是否仍在运行 |
| 获取会话输出(可指定offset/limit参数) |
| 向stdin发送原始数据 |
| 发送数据+换行(类似输入后按回车键) |
| 发送按键指令或十六进制字节 |
| 粘贴文本(可选择括号模式) |
| 终止会话 |
Quick Start: One-Shot Tasks
快速入门:一次性任务
For quick prompts/chats, create a temp git repo and run:
bash
undefined对于快速提问/对话,创建临时git仓库后运行:
bash
undefinedQuick 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
undefinedStart agent in target directory (with PTY!)
在目标目录启动Agent(开启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)
发送输入(如果Agent询问问题)
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很重要:** Agent会在指定目录下工作,不会乱跑读取无关文件(比如你的soul.md 😅)。
---Codex CLI
Codex CLI
Model: is the default (set in ~/.codex/config.toml)
gpt-5.2-codex模型: 默认使用(可在~/.codex/config.toml中设置)
gpt-5.2-codexFlags
可用参数
| Flag | Effect |
|---|---|
| One-shot execution, exits when done |
| Sandboxed but auto-approves in workspace |
| NO sandbox, NO approvals (fastest, most dangerous) |
| 参数名 | 作用 |
|---|---|
| 一次性执行,完成后自动退出 |
| 沙箱环境,但在工作区内自动审批操作 |
| 无沙箱、无审批(速度最快,风险最高) |
Building/Creating
构建/创建功能
bash
undefinedbash
undefinedQuick 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'"
undefinedbash pty:true workdir:~/project background:true command:"codex --yolo 'Refactor the auth module'"
undefinedReviewing 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
undefinedClone 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"
undefinedgit worktree add /tmp/pr-130-review pr-130-branch
bash pty:true workdir:/tmp/pr-130-review command:"codex review --base main"
undefinedBatch PR Reviews (parallel army!)
批量PR审核(并行处理!)
bash
undefinedbash
undefinedFetch 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
undefinedbash
undefinedForeground
前台运行
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编码Agent
bash
undefinedbash
undefinedInstall: 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
undefined1. 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. 为每个worktree启动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
⚠️ 规则
- Use the right execution mode per agent:
- Codex/Pi/OpenCode:
pty:true - Claude Code: (no PTY required)
--print --permission-mode bypassPermissions
- Codex/Pi/OpenCode:
- 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.
- Be patient - don't kill sessions because they're "slow"
- Monitor with process:log - check progress without interfering
- --full-auto for building - auto-approves changes
- vanilla for reviewing - no special flags needed
- Parallel is OK - run many Codex processes at once for batch work
- NEVER start Codex in ~/.openclaw/ - it'll read your soul docs and get weird ideas about the org chart!
- NEVER checkout branches in ~/Projects/openclaw/ - that's the LIVE OpenClaw instance!
- 根据Agent类型选择正确的执行模式:
- Codex/Pi/OpenCode:开启
pty:true - Claude Code:使用(无需PTY)
--print --permission-mode bypassPermissions
- Codex/Pi/OpenCode:开启
- 尊重工具选择 - 如果用户要求使用Codex,就使用Codex。
- 编排模式:不要自己手动编写补丁。
- 如果Agent运行失败/挂起,可以重启它或询问用户方向,不要默默接管任务。
- 保持耐心 - 不要因为会话运行“慢”就杀死它
- 使用process:log监控 - 查看进度而不干扰运行
- 构建任务使用--full-auto - 自动审批变更
- 审核任务使用默认配置 - 无需特殊参数
- 支持并行运行 - 可以同时运行多个Codex进程处理批量任务
- 绝对不要在~/.openclaw/目录下启动Codex - 它会读取你的私密文档,对组织架构产生奇怪的认知!
- 绝对不要在~/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.
当你在后台启动编码Agent时,要及时同步用户进度。
- 启动时发送1条短消息,说明运行的任务和所在目录。
- 仅在发生变化时再次更新:
- 完成一个里程碑(构建完成、测试通过)
- Agent询问问题/需要输入
- 遇到错误或需要用户操作
- Agent运行完成(说明变更内容和所在位置)
- 如果你终止了一个会话,立即告知用户终止的原因。
这可以避免用户只看到“Agent在回复前失败”,完全不知道发生了什么。
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 nowExample:
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.
对于长时间运行的后台任务,可以在提示词末尾添加唤醒触发器,这样Agent完成时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 , output breaks or agent hangs.
pty:true - Git repo required: Codex won't run outside a git directory. Use for scratch work.
mktemp -d && git init - exec is your friend: runs and exits cleanly - perfect for one-shots.
codex exec "prompt" - submit vs write: Use to send input + Enter,
submitfor raw data without newline.write - 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是必需的: 编码Agent是交互式终端应用,没有会导致输出异常或Agent挂起。
pty:true - 需要Git仓库: Codex不会在git目录外运行,临时工作可以用创建环境。
mktemp -d && git init - exec非常好用: 运行完成后会干净退出,非常适合一次性任务。
codex exec "prompt" - submit和write的区别: 用发送输入+回车,
submit发送不带换行的原始数据。write - 支持趣味提示: Codex对 playful 风格的提示词反馈很好,让它写一首关于给太空龙虾当副手的俳句,得到的回复是:"Second chair, I code / Space lobster sets the tempo / Keys glow, I follow" 🦞