📚AI 编程官方教程中文版
官方教程中文版规则、安全与配置

迁移自定义提示到新机制

Custom prompts 已 deprecated。可复用 instructions 推荐使用 skills,因为 skills 可以由 Codex 显式或

Custom prompts 已 deprecated。可复用 instructions 推荐使用 skills,因为 skills 可以由 Codex 显式或隐式调用。

Custom prompts 旧机制可以把 Markdown files 变成 reusable prompts,并在 Codex CLI 和 Codex IDE extension 中作为 slash commands 调用。

它有几个限制:

  • 需要显式 invocation。
  • 存在本地 Codex home directory 中,例如 ~/.codex
  • 不会随 repository 共享。

如果你想分享 prompt,或希望 Codex 根据任务隐式调用,请使用 skills

创建自定义提示词

  1. 创建 prompts directory:
mkdir -p ~/.codex/prompts
  1. 创建 ~/.codex/prompts/draftpr.md,写入 reusable guidance:
---
description: Prep a branch, commit, and open a draft PR
argument-hint: [FILES=<paths>] [PR_TITLE="<title>"]
---

为这次工作创建一个名为 `dev/<feature_name>` 的 branch。
如果指定了 files,请先 stage 它们:$FILES。
用清楚的 commit message 提交 staged changes。
在同一 branch 上打开 draft PR。如果提供了 $PR_TITLE,请使用它;否则自己写一个简洁 summary。
  1. 重启 Codex,让它加载 new prompt。CLI 需要 restart session;如果使用 IDE extension,需要 reload extension。

预期结果:在 slash command menu 中输入 /prompts:draftpr,会看到这个 custom command。command 下方显示 front matter 中的 description,并提示 files 和 PR title 是 optional。

添加元数据和参数

Codex 会在下次 session start 时读取 prompt metadata,并解析参数标记。

字段/占位说明
Description在 popup 的 command name 下显示。用 YAML front matter 中的 description: 设置。
Argument hintargument-hint: KEY=<value> 说明预期 parameters。
Positional 参数标记$1$9 会从 command 后的 space-separated arguments 展开。$ARGUMENTS 包含全部 positional arguments。
Named 参数标记使用 $FILE$TICKET_ID 这类 uppercase names,并通过 KEY=value 传值。有空格的值要 quote,例如 FOCUS="loading state"
Literal dollar signs$$ 可以在 expanded prompt 中输出单个 $

编辑 prompt files 后,重启 Codex 或打开 new chat,updates 才会加载。Codex 会忽略 prompts directory 中的 non-Markdown files。

调用和管理自定义命令

调用方式:

  1. 在 Codex,也就是 CLI 或 IDE extension 中,输入 / 打开 slash command menu。
  2. 输入 prompts: 或 prompt name,例如 /prompts:draftpr
  3. 提供 required arguments:
/prompts:draftpr FILES="src/pages/index.astro src/lib/api.ts" PR_TITLE="Add hero animation"
  1. 按 Enter 发送 expanded instructions。不需要某个 argument 时可以省略。

预期结果:Codex 会展开 draftpr.md 的内容,把参数标记替换成你提供的 arguments,然后把结果作为 message 发送。

管理方式:编辑或删除 ~/.codex/prompts/ 下的 files。

Codex 只扫描该 folder 顶层的 Markdown files。因此,每个 custom prompt 都要直接放在 ~/.codex/prompts/ 下,不要放在 subdirectories 中。

On this page