Codex skills 怎麼寫自己的工作流?最簡單的理解是:把你反覆複製貼上給 Codex 的那套操作說明,整理成一個可以被 Codex 自動發現、按需讀取、長期維護的 SKILL.md。
如果只是一次性任務,直接在提示詞裡說清楚就好。只有當一個流程會重複出現、步驟相對固定、經常需要讀取同類文件、執行同類命令、產出同類結果時,才值得寫成 skill。
快速結論
一個好用的 Codex skill,通常滿足四點:
description 寫清楚「什麼時候用」,不要只寫「這是一個工具」。
SKILL.md 寫流程、邊界、輸入、輸出和驗證,不要寫成散文。
- 長資料放進
references/,重複命令放進 scripts/,模板放進 assets/。
- 每次修改後用真實任務跑一遍,確認 Codex 會在該用時選中,也不會誤觸發。
可以先從小 skill 開始,例如:
1
2
3
4
5
|
把站內中文文章改寫成可發布版本
把某類日誌整理成日報
把 PR review 固定成安全、測試、回歸三段
把部署流程固定成 build、sync、purge、submit
把產品圖片處理成統一規格
|
真正適合寫成 skill 的,不是知識點,而是可重複執行的工作方式。
Skill、AGENTS.md、Hooks、MCP 分別放什麼
寫 skill 前,先別急著建目錄。很多混亂來自放錯位置。
| 需求 |
更適合放哪裡 |
| 當前這次任務的臨時要求 |
直接寫在提示詞裡 |
| 倉庫長期編碼規範、測試命令、提交要求 |
AGENTS.md |
| 一套可複用的任務流程 |
Skill |
| 工具調用前後必須執行的機械規則 |
Hook |
| 訪問外部系統、資料庫、私有服務 |
MCP server 或 app connector |
| 定時檢查、週期性報告 |
Automation |
| 安裝給別人複用的一整套擴展 |
Plugin |
例如,「每次改完程式碼都必須跑格式化」更像 hook;「審查 PR 時按安全、邊界條件、測試缺口輸出 findings」更像 skill;「這個倉庫預設用 pnpm,不要用 npm」更像 AGENTS.md。
最小目錄結構
一個最小 skill 可以只有一個文件:
1
2
|
my-workflow/
SKILL.md
|
稍微完整一點,可以這樣:
1
2
3
4
5
6
7
8
9
10
|
my-workflow/
SKILL.md
references/
checklist.md
examples.md
scripts/
validate.ps1
collect-data.py
assets/
report-template.md
|
常見分工:
SKILL.md:入口說明,必須簡潔,告訴 Codex 何時使用、怎麼執行、怎麼驗證。
references/:較長背景、規則表、範例、術語表。只有需要時再讀。
scripts/:穩定可重複的命令,避免每次手寫長腳本。
assets/:模板、樣例文件、提示詞片段、報告格式。
如果 skill 很小,不要為了「看起來專業」強行拆目錄。
SKILL.md 基本模板
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
---
name: my-workflow
description: Use when the user asks to <具體任務觸發條件>. Handles <輸入>, produces <輸出>, and verifies <完成標準>.
---
# My Workflow
## Purpose
說明這個 skill 解決什麼重複任務,不解決什麼。
## When To Use
- 使用者明確提到某個關鍵詞時使用。
- 任務需要固定步驟、固定輸出或固定校驗時使用。
- 如果只是普通問答,不使用。
## Inputs
- 需要使用者提供什麼。
- 可以從倉庫裡自動發現什麼。
- 缺少資訊時應如何假設或提問。
## Workflow
1. 檢查當前狀態。
2. 讀取必要文件。
3. 執行核心處理。
4. 執行輕量驗證。
5. 回報結果和未完成事項。
## Constraints
- 不要改哪些文件。
- 不要執行哪些命令。
- 哪些欄位必須保留。
- 遇到衝突怎麼處理。
## Verification
- 檢查輸出文件是否存在。
- 檢查格式是否有效。
- 檢查命令是否通過。
- 檢查是否有殘留風險。
## Reporting
最終回覆需要包含:
- 改了什麼。
- 沒改什麼。
- 驗證結果。
- 需要使用者注意的風險。
|
真正寫的時候,不一定每個標題都要保留,但這些問題都要回答。
description 是最重要的一行
不好的寫法:
1
|
description: Help with reports.
|
更好的寫法:
1
|
description: Use when the user asks to turn Git commits, issue updates, or daily work notes into a weekly engineering report with sections for completed work, risks, blockers, and next actions.
|
這一行應該包含觸發場景、輸入類型、輸出類型和關鍵邊界。
把提示詞改成流程,而不是照抄
很多人第一次寫 skill,會把過去常用的一大段提示詞直接複製進去。這能用,但不穩。
提示詞通常像一次性對話:
1
|
你是一位資深工程師,請幫我檢查這次改動有沒有問題,重點關注邊界條件和測試。
|
Skill 應該改成流程:
1
2
3
4
5
6
7
|
## Workflow
1. 先執行 `git status --short`,確認改動範圍。
2. 讀取 diff,而不是只看文件名。
3. 按嚴重程度列出 findings。
4. 優先找 bug、回歸風險、安全問題和缺失測試。
5. 如果沒有問題,明確說明未發現高置信問題,並列出剩餘風險。
|
流程比角色扮演更容易執行,也更容易複查。
什麼時候拆 references
SKILL.md 不適合無限變長。下面幾類內容更適合放進 references/:
- 很長的風格指南;
- 大量示例輸出;
- 術語表;
- API 欄位說明;
- 評分規則;
- 多語言翻譯對照;
- 複雜業務規則;
- 不一定每次都要讀的背景資料。
SKILL.md 裡只寫路由:
1
2
3
4
5
|
## References
- 需要判斷報告品質時,讀取 `references/report-rubric.md`。
- 需要生成完整模板時,讀取 `assets/weekly-report-template.md`。
- 普通摘要任務不要讀取完整示例庫。
|
這樣可以減少上下文浪費。
什麼時候寫 scripts
只要某個步驟穩定、機械、容易寫錯,就適合腳本化。
適合放進 scripts/ 的例子:
- 掃描文件並生成清單;
- 校驗 front matter;
- 把 JSON 轉成 Markdown 表格;
- 下載固定來源資料;
- 執行固定構建命令;
- 批量轉換圖片;
- 檢查連結、slug、日期、語言文件。
讓 Codex 判斷和組織,讓腳本做機械執行。
示例:週報 skill
1
2
3
4
5
6
|
weekly-report/
SKILL.md
assets/
weekly-report-template.md
scripts/
collect-git-summary.ps1
|
SKILL.md:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
---
name: weekly-report
description: Use when the user asks to create a weekly work report from Git commits, notes, issue updates, or chat summaries. Produces a concise Chinese report with completed work, impact, blockers, and next week plan.
---
# Weekly Report
## Workflow
1. Confirm the report date range. If missing, use the current week.
2. Collect source material from user-provided notes first.
3. If the user asks to include Git work, run `scripts/collect-git-summary.ps1`.
4. Group work by project or theme, not by raw commit order.
5. Produce a concise Chinese report using `assets/weekly-report-template.md`.
6. Mark uncertain items as uncertain instead of inventing progress.
## Constraints
- Do not expose private commit hashes unless the user asks.
- Do not claim shipped work if the source only shows drafts or experiments.
- Keep blockers separate from completed work.
## Reporting
Return the report content and list which sources were used.
|
重點不是「會寫週報」,而是固定了範圍、資料優先級、分組方式和不能編造進度。
示例:代碼審查 skill
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
---
name: focused-code-review
description: Use when the user asks for a code review of the current working tree, a commit, or a pull request. Prioritize bugs, regressions, security risks, and missing tests; do not rewrite code unless asked.
---
# Focused Code Review
## Workflow
1. Inspect `git status --short`.
2. Read the relevant diff.
3. Identify behavior changes before style issues.
4. List findings first, ordered by severity.
5. Include file and line references when possible.
6. If no issues are found, say so directly and mention remaining test gaps.
## Constraints
- Do not make code edits during review.
- Do not focus on formatting unless it can cause a real bug.
- Do not summarize before findings.
|
這能讓 Codex 每次 review 都保持同一種姿態。
測試自己的 skill
寫完後要測三件事。
第一,能不能被選中:
1
|
$weekly-report 根據這週提交生成一版週報
|
也測自然語言:
第二,選中後步驟是否清楚。觀察 Codex 是否讀對文件、調用對腳本、遵守限制。
第三,會不會誤觸發。如果普通問答也觸發 skill,通常是 description 太寬。
常見錯誤
把 skill 寫成百科
Skill 不是知識庫。它應該告訴 Codex 怎麼做事。背景資料放 references,入口文件保持短而清楚。
description 太泛
只寫「Codex, workflow, automation」沒有用。Codex 需要知道何時用、輸入是什麼、輸出是什麼。
沒有完成標準
如果 skill 沒寫驗證步驟,Codex 很容易「做完就說做完」。至少要寫清楚如何檢查文件、命令、格式或結果。
腳本太危險
不要在 skill 腳本裡預設做刪除、覆蓋、發布、付費調用、批量重命名。高風險動作應先確認。
萬能 skill
「我的萬能工作流」通常難維護。更好的方式是拆成小 skill:寫文章、翻譯、部署、SEO、代碼審查、週報,各管一件事。
維護建議
每次踩坑後只改一小處:
- 沒選中:改
description。
- 選中但步驟不穩:改
Workflow。
- 輸出格式不穩:補
Reporting 或模板。
- 經常手寫同一段命令:抽到
scripts/。
SKILL.md 太長:把背景拆到 references/。
Skill 越像一份可執行操作規程,越容易長期可用。
參考資料
總結
Codex skills 不是把提示詞換個地方保存,而是把一套可重複工作流變成可發現、可執行、可驗證的專案資產。
先從一個小流程開始:寫清楚觸發條件,列出輸入和輸出,把步驟拆成編號,把風險邊界寫明,把機械動作交給腳本,把長資料放到 references。