### MCP 服务器管理
```bash
# 添加 stdio 类型的服务器
$ codex mcp add myserver -- npx my-mcp-server
# 添加 HTTP 远程服务器
$ codex mcp add myserver \
--url https://api.example.com/mcp
# 带 Auth 身份验证 Token
$ codex mcp add myserver \
--url https://api.example.com/mcp \
--bearer-token-env-var MY_TOKEN
# 查看 / 移除服务器
$ codex mcp list
$ codex mcp remove myserver
# 将 Codex 自身作为 MCP 服务器运行
$ codex mcp-server
$ codex resume # 弹出会话选择器
$ codex resume --last # 恢复最近一次的会话
$ codex resume --all # 恢复跨所有目录的会话
$ codex resume <ID> "Continue fixing tests"
会话数据持久化保存在 ~/.codex/sessions/
$ codex fork # 从选择器派生
$ codex fork --last # 派生最近一次的会话
$ codex fork <SESSION_ID> "New direction"
Fork 派生可以在开始全新分支的同时,完整保留原始对话记录。
# 附加单张图片
$ codex -i screenshot.png "Fix this error"
# 附加多张图片
$ codex --image img1.png,img2.jpg "Compare"
# 或直接将图片拖入 TUI 编辑器框内
支持格式:PNG、JPEG 以及其他常见图像格式。
# 浏览云端环境
$ codex cloud
# 提交运行一个云端任务
$ codex cloud exec --env <ENV_ID> "Fix bug"
# 多次尝试模式(Best-of-N)
$ codex cloud exec --env <ENV_ID> \
--attempts 3 "Write failing tests"
# 查看最近的云端任务
$ codex cloud list
# 查看指定任务状态
$ codex cloud status <TASK_ID>
# 查看任务的代码改动 Diff
$ codex cloud diff <TASK_ID>
# 将云端改动应用至本地工作区
$ codex apply <TASK_ID>
# 在 PR 评论中 – 触发代码审查:
@codex review
# 自定义关注重点:
@codex review for security regressions
# 使用 PR 作为上下文委派任务:
@codex fix the CI failures
@codex add tests for the new endpoint
在 Codex Settings → Code review → 您的仓库 中开启。开启 Automatic reviews 自动审查每个新 PR。
将噪音较大的任务分发给并行代理,以避免上下文污染与上下文衰退:
codex "Review this branch with parallel agents.
Spawn one for security risks, one for test gaps,
and one for maintainability. Wait for all three,
then summarize findings with file references."
子代理模型选择指南:
| 角色岗位 | 模型选择 | 思考深度 (Reasoning) |
|---|---|---|
| 主协调代理 (Main) | gpt-5.4 |
medium |
| 快速探索代理 | gpt-5.4-mini |
low |
| 安全 / 逻辑审查代理 | gpt-5.4 |
high |
| 级别 | 适用场景 |
|---|---|
high |
复杂业务逻辑、安全代码审计 |
medium |
通用常见任务(默认) |
low |
简单或对速度要求极高的任务 |
在 config.toml 中配置:
model_reasoning_effort = "medium"
或行内临时指定:-c model_reasoning_effort="high"