Using Codex

App 自动化

了解 App 中持续目标、提醒、监控和周期任务的使用边界。

在后台自动执行 recurring tasks。Codex 会把 findings 添加到 inbox;如果没有需要报告的内容,也可以自动 archive 该 task。你可以把 automations 和 skills 结合起来处理更复杂的任务。

对于 project-scoped automations,运行本地 Codex app 的机器必须保持开机,Codex 必须正在运行,并且在 automation 计划运行时,所选 project 仍然必须在磁盘上可用。

在 Git repositories 中,你可以选择 automation 是在本地 project 中运行,还是在新的 worktree 上运行。两种选项都会在后台运行。Worktrees 会把 automation changes 与未完成的本地工作分开;而在本地 project 中运行可能会修改你仍在编辑的文件。在没有 version control 的项目中,automations 会直接在 project directory 中运行。

你也可以让 model 和 reasoning effort 保持默认设置;如果希望更精细地控制 automation 的运行方式,也可以显式选择它们。

管理 tasks

你可以在 Codex app sidebar 内的 automations pane 中找到所有 automations 及其 runs。

“Triage” section 充当你的 inbox。带有 findings 的 automation runs 会显示在那里,你可以过滤 inbox,显示所有 automation runs 或只显示 unread ones。

Standalone automations 会按 schedule 启动 fresh runs,并在 Triage 中报告结果。当每次 run 都应独立,或一个 automation 需要跨一个或多个 projects 运行时使用它们。如果需要 custom cadence,请选择 custom schedule 并输入 cron syntax。

对于 Git repositories,每个 automation 都可以在本地 project 中运行,也可以在 dedicated background worktree 上运行。当你希望把 automation changes 与未完成的本地工作隔离时,请使用 worktree 。当你希望 automation 直接在 main checkout 中工作时,请使用 local mode,但要记住它可能会改变你正在编辑的文件。在没有 version control 的项目中,automations 会直接在 project directory 中运行。你可以让同一个 automation 在多个 project 上运行。

Automations 会使用你的 default sandbox settings。在 read-only mode 下,如果 tool calls 需要修改文件、访问 network,或操作你电脑上的 apps,就会失败。启用 full access 后,background automations 会带来更高风险。你可以在 Settings 中调整 sandbox settings,并使用 rules 有选择地 allowlist commands。

Automations 可以使用 Codex 可用的同一组 plugins 和 skills 。为了让 automations 易于维护并能在团队间共享,请使用 skills 来定义 action,并提供 tools 和 context。你可以在 automation 中使用 $skill-name 来显式触发某个 skill。

让 Codex 创建或更新 automations

你可以从普通 Codex thread 创建和更新 automations。描述 task、schedule,以及 automation 应保持附着在当前 thread 上,还是启动 fresh runs。Codex 可以起草 automation prompt、选择正确的 automation type,并在 scope 或 cadence 改变时更新它。

例如,你可以让 Codex 在 deployment 完成前在这个 thread 中提醒你,或让它创建一个 standalone automation,按 recurring schedule 检查某个 project。

Skills 也可以创建或更新 automations。例如,一个用于 babysitting pull request 的 skill,可以设置 recurring automation,使用 GitHub plugin 检查 PR status 并修复新的 review feedback。

Thread automations

Thread automations 是附着在当前 thread 上的 heartbeat-style recurring wake-up calls。当你希望 Codex 按 schedule 持续回到同一个 conversation 时使用它们。

当 scheduled work 应该保留 thread context,而不是每次从新的 prompt 开始时,请使用 thread automation。

Thread automations 可以使用 minute-based intervals 来处理 active follow-up loops;如果你需要在特定时间 check in,也可以使用 daily 或 weekly schedules。

Thread automations 适用于:

检查 long-running command,直到它完成。

轮询 Slack、GitHub 或其他 connected source,并让结果留在同一个 thread 中。

提醒 Codex 按固定 cadence 继续 review loop。

运行使用 plugins 的 skill-driven workflow,例如检查 PR status 并处理新的 feedback。

让某个 chat 持续聚焦在 ongoing research 或 triage task 上。

当每次 run 都应相互独立、应跨多个 project 运行,或 findings 应作为单独 automation runs 出现在 Triage 中时,请使用 standalone 或 project automation。

创建 thread automation 时,请让 prompt 足够 durable。它应该描述 thread 每次被唤醒时 Codex 要做什么,如何判断是否有重要事项需要报告,以及何时停止或要求你输入。

测试 automations

在安排 automation 之前,先在普通 thread 中手动测试 prompt。这有助于确认:

Prompt 清晰,并且 scope 正确。

所选或默认的 model、reasoning effort 和 tools 按预期工作。

生成的 diff 是可 review 的。

开始安排 runs 后,请 review 前几次 outputs,并根据需要调整 prompt 或 cadence。

Automations 的 worktree cleanup

如果你为 Git repositories 选择 worktrees,频繁的 schedules 可能会随着时间创建许多 worktrees。Archive 不再需要的 automation runs,并避免 pinning runs,除非你确实想保留它们的 worktrees。

权限与安全模型

Automations 会 unattended 运行,并使用你的 default sandbox settings。

如果你的 sandbox mode 是 read-only,当 tool calls 需要修改文件、访问 network,或操作你电脑上的 apps 时会失败。请考虑把 sandbox settings 更新为 workspace write。

如果你的 sandbox mode 是 workspace-write,当 tool calls 需要修改 workspace 外的文件、访问 network,或操作你电脑上的 apps 时会失败。你可以使用 rules 有选择地 allowlist commands,让它们在 sandbox 外运行。

如果你的 sandbox mode 是 full access,background automations 会带来 elevated risk,因为 Codex 可能不询问就更改文件、运行 commands、访问 network。请考虑把 sandbox settings 更新为 workspace write,并使用 rules 有选择地定义 agent 可以用 full access 运行哪些 commands。

如果你处在 managed environment 中,admins 可以使用 admin-enforced requirements 限制这些 behaviors。例如,他们可以禁止 approval_policy = "never",或限制 allowed sandbox modes。请参阅 Admin-enforced requirements (requirements.toml)

当你的 organization policy 允许时,automations 会使用 approval_policy = "never"。如果 admin requirements 禁止 approval_policy = "never",automations 会回退到所选 mode 的 approval behavior。

示例

自动创建新 skills

Scan all of the `~/.codex/sessions` files from the past day and 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 and struggle with that we should save as a skill to speed up future work, let’s do it. Definitely don't feel like you need to update any- only if there's a good reason! Let me know if you make any.

跟进项目最新进展

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 + structure: - Use rich Markdown (H1 workstream sections, italics for the subtitle, horizontal rules as needed). - Preamble can read something like “Here’s the last 24h brief for <directory>:” - Subtitle should read: “Narrative walkthrough with owners; grouped by workstream.” - Group by workstream rather than listing each commit. Workstream titles should be H1. - Write a short narrative per workstream that explains the changes in plain language. - Use bullet points and bolding when it makes things more readable - Feel free to make bullets per person, but bold their name Content requirements: - Include PR links inline (e.g., [#123](...)) without a “PRs:” label. - Do NOT include commit hashes or a “Key commits” section. - It’s fine if multiple PRs appear under one workstream, but avoid per‑commit bullet lists. Scope rules: - Only include changes within the current cwd (or main checkout equivalent) - Only include the last 24h of commits. - Use `gh` to fetch PR titles and descriptions if it helps. Also feel free to pull PR reviews and comments

结合 automations 和 skills 修复自己的 bug

创建一个新的 skill,通过创建新的 $recent-code-bugfix 来尝试修复由你自己的 commits 引入的 bug,并把它 保存到你的 personal skills 中。

--- name: recent-code-bugfix description: Find and fix a bug introduced by the current author within the last week in the current working directory. Use when a user wants a proactive bugfix from their recent changes, when the prompt is empty, or when asked to triage/fix issues caused by their recent commits. Root cause must map directly to the author’s own changes. --- # Recent Code Bugfix ## Overview Find a bug introduced by the current author in the last week, implement a fix, and verify it when possible. Operate in the current working directory, assume the code is local, and ensure the root cause is tied directly to the author’s own edits. ## Workflow ### 1) Establish the recent-change scope Use Git to identify the author and changed files from the last week. - Determine the author from `git config user.name`/`user.email`. If unavailable, use the current user’s name from the environment or ask once. - Use `git log --since=1.week --author=<author>` to list recent commits and files. Focus on files touched by those commits. - If the user’s prompt is empty, proceed directly with this default scope. ### 2) Find a concrete failure tied to recent changes Prioritize defects that are directly attributable to the author’s edits. - Look for recent failures (tests, lint, runtime errors) if logs or CI outputs are available locally. - If no failures are provided, run the smallest relevant verification (single test, file-level lint, or targeted repro) that touches the edited files. - Confirm the root cause is directly connected to the author’s changes, not unrelated legacy issues. If only unrelated failures are found, stop and report that no qualifying bug was detected. ### 3) Implement the fix Make a minimal fix that aligns with project conventions. - Update only the files needed to resolve the issue. - Avoid adding extra defensive checks or unrelated refactors. - Keep changes consistent with local style and tests. ### 4) Verify Attempt verification when possible. - Prefer the smallest validation step (targeted test, focused lint, or direct repro command). - If verification cannot be run, state what would be run and why it wasn’t executed. ### 5) Report Summarize the root cause, the fix, and the verification performed. Make it explicit how the root cause ties to the author’s recent changes.

之后,创建一个新的 automation:

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

站内延伸阅读