本指南將向您展示如何在 Claude Code 中建立、使用和管理 Agent Skills。Skills 是模組化的功能,透過包含指令、腳本和資源的組織化資料夾來擴展 Claude 的功能。

先決條件

  • Claude Code 版本 1.0 或更高版本
  • Claude Code 的基本熟悉

什麼是 Agent Skills?

Agent Skills 將專業知識打包成可發現的功能。每個 Skill 都包含一個 SKILL.md 檔案,其中包含 Claude 在相關時會讀取的指令,以及可選的支援檔案,如腳本和範本。 Skills 如何被調用:Skills 是模型調用的——Claude 會根據您的請求和 Skill 的描述自主決定何時使用它們。這與斜線命令不同,斜線命令是使用者調用的(您明確輸入 /command 來觸發它們)。 好處
  • 為您的特定工作流程擴展 Claude 的功能
  • 透過 git 與您的團隊分享專業知識
  • 減少重複的提示
  • 組合多個 Skills 來完成複雜任務
Agent Skills 概述 中了解更多。
要深入了解 Agent Skills 的架構和實際應用,請閱讀我們的工程部落格:Equipping agents for the real world with Agent Skills

建立 Skill

Skills 儲存為包含 SKILL.md 檔案的目錄。

個人 Skills

個人 Skills 在您的所有專案中都可用。將它們儲存在 ~/.claude/skills/ 中:
mkdir -p ~/.claude/skills/my-skill-name
使用個人 Skills 用於
  • 您的個人工作流程和偏好
  • 您正在開發的實驗性 Skills
  • 個人生產力工具

專案 Skills

專案 Skills 與您的團隊共享。將它們儲存在專案內的 .claude/skills/ 中:
mkdir -p .claude/skills/my-skill-name
使用專案 Skills 用於
  • 團隊工作流程和慣例
  • 專案特定的專業知識
  • 共享的實用程式和腳本
專案 Skills 會被提交到 git 並自動提供給團隊成員。

外掛程式 Skills

Skills 也可以來自 Claude Code 外掛程式。外掛程式可能會捆綁在安裝外掛程式時自動可用的 Skills。這些 Skills 的工作方式與個人和專案 Skills 相同。

撰寫 SKILL.md

建立一個包含 YAML 前置資料和 Markdown 內容的 SKILL.md 檔案:
---
name: Your Skill Name
description: Brief description of what this Skill does and when to use it
---

# Your Skill Name

## Instructions
Provide clear, step-by-step guidance for Claude.

## Examples
Show concrete examples of using this Skill.
description 欄位對於 Claude 發現何時使用您的 Skill 至關重要。它應該包括 Skill 的功能和 Claude 應該何時使用它。 請參閱最佳實踐指南以獲得完整的撰寫指導。

新增支援檔案

在 SKILL.md 旁邊建立其他檔案:
my-skill/
├── SKILL.md (必需)
├── reference.md (可選文件)
├── examples.md (可選範例)
├── scripts/
│   └── helper.py (可選實用程式)
└── templates/
    └── template.txt (可選範本)
從 SKILL.md 中引用這些檔案:
For advanced usage, see [reference.md](reference.md).

Run the helper script:
```bash
python scripts/helper.py input.txt
```
Claude 只在需要時讀取這些檔案,使用漸進式揭露來有效管理上下文。

使用 allowed-tools 限制工具存取

使用 allowed-tools 前置資料欄位來限制 Claude 在 Skill 啟用時可以使用的工具:
---
name: Safe File Reader
description: Read files without making changes. Use when you need read-only file access.
allowed-tools: Read, Grep, Glob
---

# Safe File Reader

This Skill provides read-only file access.

## Instructions
1. Use Read to view file contents
2. Use Grep to search within files
3. Use Glob to find files by pattern
當此 Skill 啟用時,Claude 只能使用指定的工具(Read、Grep、Glob)而無需請求許可。這對以下情況很有用:
  • 不應修改檔案的唯讀 Skills
  • 範圍有限的 Skills(例如,僅數據分析,不寫入檔案)
  • 您想要限制功能的安全敏感工作流程
如果未指定 allowed-tools,Claude 將按照標準許可模型正常請求使用工具的許可。
allowed-tools 僅在 Claude Code 中的 Skills 支援。

檢視可用的 Skills

Claude 會自動從三個來源發現 Skills:
  • 個人 Skills:~/.claude/skills/
  • 專案 Skills:.claude/skills/
  • 外掛程式 Skills:與已安裝的外掛程式捆綁
要檢視所有可用的 Skills,直接詢問 Claude:
What Skills are available?
List all available Skills
這將顯示來自所有來源的所有 Skills,包括外掛程式 Skills。 要檢查特定的 Skill,您也可以檢查檔案系統:
# 列出個人 Skills
ls ~/.claude/skills/

# 列出專案 Skills(如果在專案目錄中)
ls .claude/skills/

# 檢視特定 Skill 的內容
cat ~/.claude/skills/my-skill/SKILL.md

測試 Skill

建立 Skill 後,透過提出與您的描述相符的問題來測試它。 範例:如果您的描述提到「PDF 檔案」:
Can you help me extract text from this PDF?
如果 Skill 符合請求,Claude 會自主決定使用您的 Skill——您不需要明確調用它。Skill 會根據您問題的上下文自動啟用。

除錯 Skill

如果 Claude 沒有使用您的 Skill,請檢查這些常見問題:

讓描述更具體

太模糊
description: Helps with documents
具體
description: Extract text and tables from PDF files, fill forms, merge documents. Use when working with PDF files or when the user mentions PDFs, forms, or document extraction.
在描述中包括 Skill 的功能和使用時機。

驗證檔案路徑

個人 Skills~/.claude/skills/skill-name/SKILL.md 專案 Skills.claude/skills/skill-name/SKILL.md 檢查檔案是否存在:
# 個人
ls ~/.claude/skills/my-skill/SKILL.md

# 專案
ls .claude/skills/my-skill/SKILL.md

檢查 YAML 語法

無效的 YAML 會阻止 Skill 載入。驗證前置資料:
cat SKILL.md | head -n 10
確保:
  • 第 1 行有開頭的 ---
  • Markdown 內容前有結尾的 ---
  • 有效的 YAML 語法(無製表符,正確的縮排)

檢視錯誤

使用除錯模式執行 Claude Code 以查看 Skill 載入錯誤:
claude --debug

與您的團隊分享 Skills

推薦方法:透過外掛程式分發 Skills。 要透過外掛程式分享 Skills:
  1. 建立一個在 skills/ 目錄中包含 Skills 的外掛程式
  2. 將外掛程式新增到市場
  3. 團隊成員安裝外掛程式
有關完整說明,請參閱將 Skills 新增到您的外掛程式 您也可以透過專案儲存庫直接分享 Skills:

步驟 1:將 Skill 新增到您的專案

建立專案 Skill:
mkdir -p .claude/skills/team-skill
# Create SKILL.md

步驟 2:提交到 git

git add .claude/skills/
git commit -m "Add team Skill for PDF processing"
git push

步驟 3:團隊成員自動獲得 Skills

當團隊成員拉取最新更改時,Skills 立即可用:
git pull
claude  # Skills are now available

更新 Skill

直接編輯 SKILL.md:
# 個人 Skill
code ~/.claude/skills/my-skill/SKILL.md

# 專案 Skill
code .claude/skills/my-skill/SKILL.md
更改在您下次啟動 Claude Code 時生效。如果 Claude Code 已經在執行,請重新啟動它以載入更新。

移除 Skill

刪除 Skill 目錄:
# 個人
rm -rf ~/.claude/skills/my-skill

# 專案
rm -rf .claude/skills/my-skill
git commit -m "Remove unused Skill"

最佳實踐

保持 Skills 專注

一個 Skill 應該處理一個功能: 專注
  • “PDF 表單填寫”
  • “Excel 數據分析”
  • “Git 提交訊息”
太廣泛
  • “文件處理”(拆分為單獨的 Skills)
  • “數據工具”(按數據類型或操作拆分)

撰寫清晰的描述

透過在描述中包含特定觸發器來幫助 Claude 發現何時使用 Skills: 清晰
description: Analyze Excel spreadsheets, create pivot tables, and generate charts. Use when working with Excel files, spreadsheets, or analyzing tabular data in .xlsx format.
模糊
description: For files

與您的團隊一起測試

讓隊友使用 Skills 並提供回饋:
  • Skill 是否在預期時啟用?
  • 指令是否清晰?
  • 是否缺少範例或邊緣情況?

記錄 Skill 版本

您可以在 SKILL.md 內容中記錄 Skill 版本以追蹤隨時間的變化。新增版本歷史部分:
# My Skill

## Version History
- v2.0.0 (2025-10-01): Breaking changes to API
- v1.1.0 (2025-09-15): Added new features
- v1.0.0 (2025-09-01): Initial release
這有助於團隊成員了解版本之間的變化。

疑難排解

Claude 沒有使用我的 Skill

症狀:您提出相關問題但 Claude 沒有使用您的 Skill。 檢查:描述是否足夠具體? 模糊的描述使發現變得困難。包括 Skill 的功能和使用時機,以及使用者會提到的關鍵詞。 太通用
description: Helps with data
具體
description: Analyze Excel spreadsheets, generate pivot tables, create charts. Use when working with Excel files, spreadsheets, or .xlsx files.
檢查:YAML 是否有效? 執行驗證以檢查語法錯誤:
# 檢視前置資料
cat .claude/skills/my-skill/SKILL.md | head -n 15

# 檢查常見問題
# - 缺少開頭或結尾的 ---
# - 使用製表符而非空格
# - 包含特殊字元的未引用字串
檢查:Skill 是否在正確位置?
# 個人 Skills
ls ~/.claude/skills/*/SKILL.md

# 專案 Skills
ls .claude/skills/*/SKILL.md

Skill 有錯誤

症狀:Skill 載入但無法正常工作。 檢查:相依性是否可用? Claude 會在需要時自動安裝所需的相依性(或請求安裝許可)。 檢查:腳本是否有執行許可?
chmod +x .claude/skills/my-skill/scripts/*.py
檢查:檔案路徑是否正確? 在所有路徑中使用正斜線(Unix 風格): 正確scripts/helper.py 錯誤scripts\helper.py(Windows 風格)

多個 Skills 衝突

症狀:Claude 使用錯誤的 Skill 或在類似的 Skills 之間似乎感到困惑。 在描述中要具體:透過在描述中使用不同的觸發詞來幫助 Claude 選擇正確的 Skill。 而不是:
# Skill 1
description: For data analysis

# Skill 2
description: For analyzing data
使用:
# Skill 1
description: Analyze sales data in Excel files and CRM exports. Use for sales reports, pipeline analysis, and revenue tracking.

# Skill 2
description: Analyze log files and system metrics data. Use for performance monitoring, debugging, and system diagnostics.

範例

簡單 Skill(單一檔案)

commit-helper/
└── SKILL.md
---
name: Generating Commit Messages
description: Generates clear commit messages from git diffs. Use when writing commit messages or reviewing staged changes.
---

# Generating Commit Messages

## Instructions

1. Run `git diff --staged` to see changes
2. I'll suggest a commit message with:
   - Summary under 50 characters
   - Detailed description
   - Affected components

## Best practices

- Use present tense
- Explain what and why, not how

具有工具許可的 Skill

code-reviewer/
└── SKILL.md
---
name: Code Reviewer
description: Review code for best practices and potential issues. Use when reviewing code, checking PRs, or analyzing code quality.
allowed-tools: Read, Grep, Glob
---

# Code Reviewer

## Review checklist

1. Code organization and structure
2. Error handling
3. Performance considerations
4. Security concerns
5. Test coverage

## Instructions

1. Read the target files using Read tool
2. Search for patterns using Grep
3. Find related files using Glob
4. Provide detailed feedback on code quality

多檔案 Skill

pdf-processing/
├── SKILL.md
├── FORMS.md
├── REFERENCE.md
└── scripts/
    ├── fill_form.py
    └── validate.py
SKILL.md
---
name: PDF Processing
description: Extract text, fill forms, merge PDFs. Use when working with PDF files, forms, or document extraction. Requires pypdf and pdfplumber packages.
---

# PDF Processing

## Quick start

Extract text:
```python
import pdfplumber
with pdfplumber.open("doc.pdf") as pdf:
    text = pdf.pages[0].extract_text()
```

For form filling, see [FORMS.md](FORMS.md).
For detailed API reference, see [REFERENCE.md](REFERENCE.md).

## Requirements

Packages must be installed in your environment:
```bash
pip install pypdf pdfplumber
```
在描述中列出所需的套件。套件必須在 Claude 使用之前安裝在您的環境中。
Claude 只在需要時載入其他檔案。

下一步