关于 codex-subagents
codex-subagents 技能通过后台线程将工作交给子 Agent,使主上下文保持精简。适合并行研究、耗时任务和需要隔离上下文的工作,并提供线程等待、查看与归档流程。
主要功能
- 01在后台线程启动子 Agent
- 02并行运行多个研究任务
- 03等待线程完成或查看进度
- 04向已停止线程发送后续提示词
- 05归档已完成线程并清理旧归档
适用场景
- 01并行调查多个 API 或主题
- 02将长时间研究移出主上下文
- 03等待后台任务完成后继续跟进
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ obra/ external-subagents --skill codex-subagents安装后在 Claude Code 中输入/codex-subagents确认已加载。
包含的文件
除 SKILL.md 外,安装时一起下载的参考资料和脚本。
TODO.md.gitignoreREADME.md.prek.tomldev/build.mjs.editorconfig.prettierrcdemo-watch.ts.npmrcdemo-watch-prompt.txteslint.config.jsrun-prek-install.mjspackage.jsonpackage-lock.jsondev/src/bin/codex-subagent.tsdev/src/commands/archive.tslog.tsclean.tslabel.tslist.tsstatus.tspeek.tssend.tsstart.tswait.tswatch.tsdev/src/lib/backends.tscontroller-id.tsexec-runner.tsfile-lock.ts详细介绍
Codex 子 Agent
概述
codex-subagent 会将工作交给后台线程处理,让主上下文保持精简。线程默认以分离模式运行;使用 wait/peek 检查结果。
重要规则:
- 不能向正在运行的线程发送消息。发送后续消息前,务必先等待。
- 使用
--permissions read-only或--permissions workspace-write(不要使用workspace-read)
如需了解详细工作流文档,请参阅 reference/workflow.md。
适用场景
| 情况 | 子 Agent 的帮助 |
|---|---|
| 并行研究任务 | 多个线程同时运行 |
| 上下文会变得臃肿 | 研究内容保留在线程中,不占用主上下文 |
| 长时间运行的工作 | 分离执行,稍后检查 |
不要用于:快速的即时问题、需要紧密依赖当前状态的工作。
核心工作流
1. start with --prompt (inline text or stdin)
2. wait/peek → check result
3. send → resume with follow-up (ONLY after thread stops)
4. archive/clean → lifecycle management
运行中线程规则
你不能向正在运行的线程发送消息。 这是最常见的错误。
# WRONG - thread might still be running
echo "followup" | codex-subagent send thread-abc --prompt -
# RIGHT - wait first, then send
codex-subagent wait --threads thread-abc
echo "followup" | codex-subagent send thread-abc --prompt -
可恢复状态:completed、failed、stopped、waiting
快速参考
| 命令 | 用途 | 关键标志 |
|---|---|---|
start | 启动新线程 | --role、--permissions、--prompt、--label、-w |
send | 恢复已停止的线程 | <thread-id>、--prompt、-w |
peek | 读取最新的未查看消息 | <thread-id>、--save-response |
log | 完整历史记录 | <thread-id>、--tail、--json |
status | 线程摘要 | <thread-id> |
wait | 阻塞,直到线程停止 | --threads、--labels、--all、--follow-last |
list | 显示线程 | --status、--label、--role |
archive | 将已完成的线程移至归档 | --completed、--yes、--dry-run |
clean | 删除旧归档 | --older-than-days、--yes |
提示词输入:简单提示词使用 --prompt "text",--prompt - 从标准输入读取(用于多行内容),文件使用 -f/--prompt-file
位置线程 ID:peek abc123 的作用与 peek -t abc123 相同
常见模式
简单的行内提示词
codex-subagent start --role researcher --permissions read-only \
--label "quick-task" --prompt "List all exported functions in src/lib/"
多行提示词(heredoc)
cat <<'EOF' | codex-subagent start --role researcher --permissions read-only --label "auth-research" --prompt -
Research authentication patterns in this codebase:
1. Find all auth-related files
2. Document the auth flow
3. Note any security concerns
EOF
并行研究
# Launch multiple researchers
cat <<'EOF' | codex-subagent start --role researcher --permissions read-only --label "API: Stripe" --prompt -
Research Stripe API authentication methods and best practices
EOF
cat <<'EOF' | codex-subagent start --role researcher --permissions read-only --label "API: Twilio" --prompt -
Research Twilio API authentication methods and best practices
EOF
# Wait for all, see results
codex-subagent wait --labels "API:" --follow-last
阻塞任务
# -w blocks until complete (may take minutes)
cat <<'EOF' | codex-subagent start --role researcher --permissions read-only --prompt - -w --save-response result.txt
Analyze error handling patterns in src/
EOF
cat result.txt
警告:-w 会一直阻塞,直到 Agent 运行结束。对于长时间运行的任务,建议使用分离模式并配合 wait --follow-last。
清理旧工作
# Two-phase: archive completed, then clean old archives
codex-subagent archive --completed --yes
codex-subagent clean --older-than-days 30 --yes
故障排除
| 问题 | 原因 | 修复方法 |
|---|---|---|
| "profile does not exist" | 权限错误 | 使用 read-only 或 workspace-write(不要使用 workspace-read) |
| "not resumable" 错误 | 线程仍在运行 | 先执行 wait,然后再执行 send |
| "different controller" | 会话错误 | 使用 --controller-id 或检查 list |
| 线程消失 | 已归档 | 检查归档目录或重新运行任务 |
检查清单
-
start包含--role、--permissions、--prompt和--label - 权限为
read-only或workspace-write -
send前先执行wait(绝不要向正在运行的线程发送消息) - 使用
--save-response或peek保存结果
评论
支持 Markdown