SKILL.md Body 跟參考檔
寫詳細指令、連結外部上下文
⏱ 預估 ~5 分鐘
01 · 讀一讀
Frontmatter 下面的 markdown body 是真正力量所在。這裡你寫詳細指令、範例、限制、規則,給 Claude 遵守。
想成一個任務的高度具體指令手冊。
用 markdown 標題組織區塊、用條列寫規則、用 code fence 寫範例。你越清楚越具體,Claude 表現越一致。
說「寫好程式碼」的 body 沒用 — Claude 本來就在試。說「變數用 camelCase、React 元件用 PascalCase、CSS class 用 kebab-case」的 body 可以執行。
重點整理
- Body 是自由的 markdown — 標題、條列、code fence、粗體
- 明確:「變數用 camelCase」打敗「用好的命名」
- 包含好輸出長什麼樣的範例
- 用標題組織,讓 Claude 快速找到相關規則
02 · 看程式碼
下面是「API Developer」skill,body 結構豐富,有標題、規則、code 範例。
api-developer/SKILL.md (body 區塊)
## API Conventions
- All endpoints return JSON
- Use kebab-case for URL paths: `/user-profiles` not `/userProfiles`
- Use camelCase for JSON fields: `{ "firstName": "Ada" }`
- Always include `Content-Type: application/json` header
## Error Response Format
Always return errors in this exact shape:
```json
{
"error": {
"code": "NOT_FOUND",
"message": "User with id 42 not found"
}
}
```
## Status Code Rules
- 200 for successful reads
- 201 for successful creates
- 400 for invalid input
- 404 for missing resources
- 500 should never be intentional — fix the bug
Claude 讀每個標題、條列、程式碼範例。當你之後說「幫我蓋一個 GET /users endpoint」,Claude 會自動遵守這些慣例 — kebab-case URL、camelCase JSON、你指定的確切錯誤格式。
03 · 讀一讀
有時候你的指令參考外部知識 — 資料庫 schema、style guide、type 定義、template。
與其把那些全部貼進 SKILL.md(會變超大、難維護),你可以連結參考檔。
放在 SKILL.md 同一個 skill 資料夾,從 body 引用。Skill 啟用時 Claude 把連結的檔當額外上下文讀。
參考檔的好處:它們是真實的事實來源。你 schema 變了,Claude 自動看到最新版 — 不用手動更新 skill。
重點整理
- 參考檔住在跟 SKILL.md 同一個 skill 資料夾
- 它們提供上下文,不會讓 skill 檔肥大
- 常見參考檔:schema 檔、style guide、template、type 定義
- 參考檔保持最新,因為它們就是事實來源
04 · 看程式碼
下面是連結 Prisma schema 當參考檔的 skill — 給 Claude 你資料庫結構的完整知識。
資料夾結構
.claude/skills/db-developer/
├── SKILL.md
└── schema.prisma
db-developer/SKILL.md
---
name: Database Developer
description: Writes database queries and migrations following our schema
---
## Context
Our database schema is defined in `schema.prisma` (included in this skill folder).
Always reference it when writing queries or migrations.
## Rules
- Never use raw SQL — use Prisma Client
- Always include `createdAt` and `updatedAt` on new models
- Foreign keys must have `onDelete: Cascade` unless specified otherwise
- Index any column used in WHERE clauses
這個 skill 啟用時,Claude 能讀 schema.prisma 了解你的資料庫結構。你之後改 schema,Claude 自動看到最新版 — 不用更新 skill。
05 · 選擇題
想像你資料庫 schema 常變。為什麼用參考檔而不是把 schema 直接貼到 SKILL.md?
- 參考檔比內嵌內容載入快
- SKILL.md 有 100 行嚴格上限
- Claude 只能讀跟 SKILL.md 分開的檔
- 參考檔隨來源變化保持最新、讓 SKILL.md 專注
06 · 配對
你學了 skill 的四個部分。配對每個元件做什麼 — 想 metadata、指令、外部上下文各自住哪。
(本節為互動練習,請啟用 JavaScript 體驗)
⚠ 完整互動體驗需要 JavaScript。請啟用 JavaScript 後重新整理。
※ 本站為獨立繁中教學專案,非 Anthropic 官方產品。Claude™ 為 Anthropic, PBC 商標。