coding-agent
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseCoding Agent (bash-first)
编码代理(优先使用bash)
Use bash (with optional background mode) for all coding agent work. Simple and effective.
所有编码代理工作均使用bash(可选后台模式),简单高效。
⚠️ PTY Mode Required!
⚠️ 必须使用PTY模式!
Coding agents (Codex, Claude Code, Pi) are interactive terminal applications that need a pseudo-terminal (PTY) to work correctly. Without PTY, you'll get broken output, missing colors, or the agent may hang.
Always use when running coding agents:
pty:truebash
undefined编码代理(Codex、Claude Code、Pi)是交互式终端应用,需要伪终端(PTY)才能正常工作。如果没有PTY,你会得到损坏的输出、缺失的颜色,或者代理可能挂起。
运行编码代理时请始终使用:
pty:truebash
undefined✅ Correct - with PTY
✅ 正确用法 - 带PTY
bash pty:true command:"codex exec 'Your prompt'"
bash pty:true command:"codex exec 'Your prompt'"
❌ Wrong - no PTY, agent may break
❌ 错误用法 - 无PTY,代理可能故障
bash command:"codex exec 'Your prompt'"
undefinedbash command:"codex exec 'Your prompt'"
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) |
| 参数 | 类型 | 说明 |
|---|---|---|
| 字符串 | 要运行的Shell命令 |
| 布尔值 | 编码代理必备! 为交互式CLI分配伪终端 |
| 字符串 | 工作目录(代理只能看到该文件夹内的内容) |
| 布尔值 | 在后台运行,返回sessionId用于监控 |
| 数字 | 超时时间(秒),超时后终止进程 |
| 布尔值 | 在主机而非沙箱中运行(如果允许) |
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 |
| 操作 | 说明 |
|---|---|
| 列出所有运行中/最近的会话 |
| 检查会话是否仍在运行 |
| 获取会话输出(可选偏移量/限制) |
| 向标准输入发送原始数据 |
| 发送数据+换行(如同输入后按回车) |
| 发送按键令牌或十六进制字节 |
| 粘贴文本(可选括号模式) |
| 终止会话 |
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!)
在目标目录启动代理(必须带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 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
undefinedWith PTY for proper terminal output
使用PTY以获得正确的终端输出
bash pty:true workdir:~/project command:"claude 'Your task'"
bash pty:true workdir:~/project command:"claude 'Your task'"
Background
后台运行
bash pty:true workdir:~/project background:true command:"claude 'Your task'"
---bash pty:true workdir:~/project background:true command:"claude '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 Coding 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: <description>. Commit and push.'"
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: <description>. Commit and push.'"
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
⚠️ 规则
- Always use pty:true - coding agents need a terminal!
- 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 ~/clawd/ - 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!
- 始终使用pty:true - 编码代理需要终端环境!
- 尊重工具选择 - 如果用户要求使用Codex,就用Codex。
- 编排器模式:不要手动编写补丁。
- 如果代理故障/挂起,重新启动它或向用户寻求指导,但不要擅自接管。
- 要有耐心 - 不要因为进程“慢”就终止会话
- 使用process:log监控 - 不干扰进程的前提下检查进度
- 构建时使用--full-auto - 自动批准更改
- 审查时使用默认模式 - 无需特殊标志
- 并行处理没问题 - 可同时运行多个Codex进程进行批量工作
- 绝不要在~/clawd/中启动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.
当你在后台启动编码代理时,要让用户随时了解情况。
- 启动时发送一条简短消息(说明正在运行什么、在哪里运行)。
- 之后仅在情况变化时更新:
- 里程碑完成(构建完成、测试通过)
- 代理提问/需要输入
- 遇到错误或需要用户操作
- 代理完成(说明更改内容和位置)
- 如果终止会话,立即告知用户并说明原因。
这可以避免用户只看到“代理在回复前故障”,却完全不知道发生了什么。
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 gateway wake --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 gateway wake --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 gateway wake --text "完成:[所构建内容的简要总结]" --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 gateway wake --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必不可少:编码代理是交互式终端应用。没有,输出会损坏或代理挂起。
pty:true - 需要git仓库:Codex拒绝在git目录外运行。使用处理临时工作。
mktemp -d && git init - exec是好帮手:运行后会干净退出,非常适合一次性任务。
codex exec "prompt" - submit与write的区别:使用发送输入+回车,
submit用于发送不带换行的原始数据。write - Sass有效:Codex对有趣的提示反应良好。让它写一首关于做太空龙虾副手的俳句,它会输出:"Second chair, I code / Space lobster sets the tempo / Keys glow, I follow" 🦞