Skip to content

Automations 是 Codex App 的定时后台任务功能:配置一个 Prompt 和触发频率,Codex 在后台定期执行,把有结果的运行放进收件箱(Triage),没内容就自动归档。适合:汇总 commit 动态、扫描自己的代码 Bug、自动更新 Skill 配置等。本文覆盖创建步骤、与 Skills 结合、权限安全配置和实际 Prompt 示例。

Codex Automations:后台定时 AI 任务

Automations 让你把稳定的工作流变成定期后台任务。不用每次手动触发,Codex 在后台按计划运行,把有价值的发现放进收件箱等你查看。

运行条件

  • Codex App 需要保持运行
  • 项目目录需要在磁盘上可访问

创建 Automation

  1. 在 Codex App 侧边栏打开 Automations 面板
  2. 选择目标项目
  3. 填写 Prompt(支持调用 Skills:$skill-name
  4. 设置执行频率
  5. 可选:选择模型和推理强度

Git 仓库额外选项

选项适用场景
在本地项目里运行需要直接修改你正在编辑的文件
在 Worktree 里运行后台运行,与前台工作隔离(推荐)

非版本控制项目直接在项目目录里运行。


管理任务

  • Triage 区域:有发现的运行会出现在这里,类似收件箱
  • 过滤器:显示全部运行或仅未读
  • 在收件箱里 Review、归档或跟进

Worktree 清理:频繁调度会累积大量 Worktree。及时归档不需要的运行,不要随意 Pin。


结合 Skills 使用

在 Automation Prompt 里用 $skill-name 显式调用 Skill:

markdown
Check my commits from the last 24h and submit a $recent-code-bugfix.

这让你可以把复杂的工作流封装成 Skill,然后在多个 Automation 里复用。Skills 编写指南参考:Skills 使用指南


权限与安全

Automations 无人值守运行,继承你的默认沙箱设置:

沙箱模式效果
read-only工具调用需要修改文件时会失败——先升级为 workspace-write
workspace-write(推荐)可以读写工作目录,网络默认关闭;可用 Rules 精细控制哪些命令可以执行
full-access后台任务有完整权限——不推荐,风险较高

在 App Settings 里调整沙箱设置,用 Rules 精细控制特定命令。

Enterprise 环境:管理员可以通过 requirements.toml 禁止 approval_policy = "never",此时 Automation 会退回到你所选模式的审批行为。


实战 Prompt 示例

汇总项目 24 小时动态

markdown
Look at the latest remote origin/master or origin/main. Then produce an exec briefing for the last 24 hours of commits that touch <DIRECTORY>

Formatting:
- Use rich Markdown (H1 workstream sections, italics for the subtitle)
- Group by workstream rather than listing each commit
- Write a short narrative per workstream in plain language
- Include PR links inline (e.g., [#123](...)) without a "PRs:" label

Content:
- Only include changes within the current cwd
- Only include the last 24h of commits

自动扫描并更新 Skills

markdown
Scan all of the ~/.codex/sessions files from the past day.

If there have been any issues using particular skills, update the skills to be more helpful. Personal skills only, no repo skills.

If there's anything we've been doing often that we should save as a skill to speed up future work, do it.

Only update/create if there's a good reason. Let me know if you make any changes.

自动修复自己引入的 Bug

先创建一个 $recent-code-bugfix Skill(参考上方),然后配置 Automation:

markdown
Check my commits from the last 24h and submit a $recent-code-bugfix.

Codex 会:

  1. 查找你最近 24 小时的 commit
  2. 找出可能引入的 Bug
  3. 尝试最小化修复并验证
  4. 把结果放进 Triage 收件箱

上手建议

先测试再调度:在正式创建 Automation 之前,手动发一次同样的 Prompt 看看效果,确认:

  • Prompt 表达清楚且范围适当
  • 模型和推理强度选择合适
  • 输出 diff 是可审查的

前几次运行要仔细看结果,根据需要调整 Prompt 或触发频率。


常见问题

Q: Automation 会在我没打开 App 的时候运行吗?

A: 不会。Automations 需要 Codex App 保持运行。如果你关闭了 App,到时间的任务会跳过,不会积压补跑。

Q: 同一个 Automation 可以在多个项目里运行吗?

A: 可以。在创建 Automation 时选择多个项目,Codex 会分别在各项目里执行。

Q: 用 Worktree 模式运行和本地模式有什么实际区别?

A: Worktree 模式在独立的 Git Worktree 里运行,Automation 的改动不会影响你当前的工作分支。本地模式直接在你的主 checkout 里运行,Automation 可能会修改你正在编辑的文件。日常推荐 Worktree 模式,特别是有正在进行的开发工作时。