跳至主要內容

Claude Code Skills:Slash Commands 完整指南

精通 Claude Code 的 Skills 系統。學習 slash commands 的運作方式、內建 skills 有哪些,以及如何為你的工作流程建立自訂 skills。

2026 年 10 月 21 日更新: 依目前的 skills 官方文件改寫:skills 是放在各自資料夾中的 SKILL.md,frontmatter 與參數範例改用真正支援的欄位(舊的 trigger: 與 args: 從未被讀取),內建表格也改列實際的 bundled skills,以及 /skills、/reload-skills 與 /skill-doctor。

Skills 是 Claude Code 可重複使用的提示詞與工作流程:一個寫有指令的 SKILL.md 檔案,你可以用 /skill-name 呼叫,Claude 也會在相關時自行載入。自訂 slash commands 已併入 skills。本指南涵蓋 bundled skills、自訂設定,以及如何建立你自己的 skills。

什麼是 Skills?

根據 skills 官方文件,Skills 是:

  • 可重複使用的提示詞模板,透過 slash commands 觸發,或在相關時自動載入
  • 工作流程自動化,結合多個步驟
  • 自訂擴充功能,你可以根據需求建立
  • 專案專屬指令,理解你的程式碼庫

把 Skills 想像成將常見工作流程編碼成單一指令的巨集。Claude Code 的 skills 遵循開放的 Agent Skills 標準,而 .claude/commands/ 中的檔案依然可以當作 skill 使用。

Skills 如何運作

使用者輸入: /deploy

Claude Code:
1. 在 .claude/skills/deploy/SKILL.md(專案)、
   ~/.claude/skills/(個人)、外掛或 bundled skills 中找到 skill
2. 載入 skill 的完整指令(被呼叫前,
   上下文中只有它的 description)
3. 執行 skill 中定義的工作流程
4. 將結果回傳給使用者

內建指令與 Bundled Skills

核心指令

Skill指令用途
Init/init為新專案初始化 CLAUDE.md
Help/help顯示可用指令
Clear/clear以空白上下文開始新對話
Config/config檢視/編輯設定
Permissions/permissions管理工具權限
Doctor/doctor安裝與設定健檢(會提出修正建議的 bundled skill)

Bundled 開發 Skills

Skill指令用途
Code Review/code-review(別名 /review)檢查目前的 diff 或 PR 是否有正確性 bug
Simplify/simplify從重用、簡化與效率角度整理變更的程式碼
Verify/verify建置並執行你的 app,確認變更確實有效
Batch/batch把大型變更拆給多個背景 subagents 平行處理
Debug/debug開啟除錯日誌並排查工作階段問題

Skill 與記憶管理

Skill指令用途
Skills/skills列出 skills、依 token 成本排序、切換可見性
Reload Skills/reload-skills不重新啟動就重新掃描 skill 目錄
Skill Doctor/skill-doctor顯示每個 skill 的上下文成本與使用次數
Memory/memory編輯 CLAUDE.md 檔案並管理 auto memory

/memory-save 或 /memory-search 這類指令,是圍繞 Memory MCP 伺服器打造的自訂 skills,並非 Claude Code 的一部分。Bundled skills 在指令參考中標示為 Skill,可用 disableBundledSkills 設定關閉。

使用 Skills

基本用法

只需輸入 slash command:

/code-review

Claude 將執行該 skill 的工作流程。

帶參數

skill 名稱後面的內容會以 $ARGUMENTS(或依位置的 $0、$1……)傳入 skill:

/code-review high 1234
/fix-issue 123
/migrate-component SearchBar JavaScript TypeScript

串連 Skills

Skills 可以依序使用。訊息開頭的 skill 名稱會直接執行;寫在一般文字之後的名稱,則代表你允許 Claude 在回應時執行它:

使用者: 進行我們討論的變更,然後執行 /commit

Claude:
  → 進行變更
  → 執行 /commit skill
  → 建立適當的 commit 訊息

在終端機中,你也可以在同一則訊息開頭疊加多個 skills,例如 /write-tests /fix-issue 123。

Skill 檔案結構

每個 skill 都是一個資料夾,內含 SKILL.md,放在 .claude/skills/(專案)或 ~/.claude/skills/(個人)中:

.claude/
├── skills/
│   ├── commit/
│   │   └── SKILL.md        # Git commit skill
│   ├── review-pr/
│   │   └── SKILL.md        # Code review skill
│   └── deploy/
│       ├── SKILL.md        # Deployment skill
│       └── checklist.md    # Supporting file, loaded when needed
├── commands/
│   └── legacy-command.md   # Older single-file format, still works
└── settings.json

資料夾名稱(或 frontmatter 的 name)就是指令名稱。外掛的 skills 會以 /plugin-name:skill-name 命名空間呈現。

Skill 定義格式

---
name: commit
description: Create a git commit with a conventional commit message. Use when the user asks to commit changes.
disable-model-invocation: true
allowed-tools: Bash(git add *) Bash(git commit *) Bash(git status *)
---

# Commit Skill

## Instructions

1. Check git status for staged changes
2. Analyze the changes to understand what was modified
3. Generate a conventional commit message:
   - feat: New feature
   - fix: Bug fix
   - docs: Documentation
   - refactor: Code refactoring
   - test: Test changes
   - chore: Maintenance

4. Create the commit with the generated message
5. Show the commit result

## Format

Use this commit message format:

type(scope): description

  • Detail 1
  • Detail 2

Co-Authored-By: Claude noreply@anthropic.com


## Example Output

Created commit: abc1234

feat(auth): add JWT token refresh mechanism

  • Implement automatic token refresh before expiration
  • Add refresh token rotation for security
  • Update auth middleware to handle refresh flow

Co-Authored-By: Claude noreply@anthropic.com

frontmatter 的所有欄位都是選填,但 description 會告訴 Claude 何時使用這個 skill。disable-model-invocation: true 能避免 Claude 自行執行有副作用的 skill,allowed-tools 則在呼叫該 skill 的那一輪預先核准列出的工具。Claude Code 會直接忽略它不認得的欄位,不會報錯。

建立自訂 Skills

步驟 1:建立 Skill 資料夾

在 .claude/skills/ 中為 skill 建立資料夾:

mkdir -p .claude/skills/deploy

步驟 2:定義 Skill

將以下內容存成 .claude/skills/deploy/SKILL.md:

---
name: deploy
description: Deploy to staging environment
disable-model-invocation: true
---

# Deploy to Staging

## Prerequisites Check

1. Verify all tests pass
2. Check for uncommitted changes
3. Confirm current branch

## Deployment Steps

1. Build the project:
   ```bash
   npm run build
  1. Run pre-deployment tests:

    npm run test:e2e
  2. Deploy to staging:

    npm run deploy:staging
  3. Verify deployment:

    • Check health endpoint
    • Run smoke tests

Post-Deployment

  • Report deployment status
  • Show deployed URL
  • Note any warnings

### 步驟 3:使用 Skill

/deploy


Claude Code 會監看 skill 目錄,修改會在目前的工作階段中生效。如果你在工作階段中途建立了全新的頂層 skills 目錄,請執行 `/reload-skills`。

## 進階 Skill 模式

### 模式 1:參數化 Skills

在你的 skill 中接受參數:

```markdown
---
name: feature
description: Start a new feature branch
argument-hint: "[feature-name]"
arguments: [feature]
disable-model-invocation: true
---

# New Feature Workflow

## Steps

1. Create branch: `feature/$feature`
2. Set up feature structure
3. Create initial files
4. Open PR draft

模式 2:條件式 Skills

根據上下文有不同行為:

---
name: review-changes
description: Review code changes, either a PR or the local diff
---

# Code Review

## Determine Review Type

If reviewing a PR:
- Fetch PR changes
- Compare with base branch

If reviewing local changes:
- Check git diff
- Review staged and unstaged

## Review Checklist

- [ ] Code quality
- [ ] Security considerations
- [ ] Test coverage
- [ ] Documentation
- [ ] Performance implications

模式 3:多 Agent Skills

協調多個 agents 的 Skills(若想讓整個 skill 在自己的 subagent 中執行,可加上 context: fork):

---
name: audit
description: Comprehensive codebase audit
---

# Codebase Audit

## Phase 1: Parallel Analysis

Launch these agents simultaneously:

1. **Explore Agent (quick)**: Map codebase structure
2. **Explore Agent (medium)**: Find code patterns
3. **security-auditor**: Security scan
4. **code-reviewer**: Quality check
5. **test-runner**: Coverage analysis

## Phase 2: Synthesize Results

Combine findings into:
- Security issues (by severity)
- Quality concerns
- Coverage gaps
- Recommended improvements

## Output Format

Audit Report

Security (X issues)

  • Critical: …
  • High: …

Quality (X concerns)

  • …

Coverage (X%)

  • Missing: …

Recommendations

  1. …
  2. …

模式 4:互動式 Skills

需要使用者輸入的 Skills:

---
name: scaffold
description: Scaffold new component/feature
---

# Scaffold Generator

## Questions

Ask the user:
1. What type? (component/api/service/hook)
2. Name?
3. Location? (suggest based on type)

## Generate Based on Answers

For component:
- Create component file
- Create test file
- Create styles file
- Export from index

For API:
- Create route handler
- Create validation schema
- Create test file
- Update API routes index

專案專屬 Skills

範例:電商 Skills

# .claude/skills/add-product/SKILL.md
---
name: add-product
description: Add a new product to catalog
---

## Product Creation Workflow

1. Create product migration
2. Add product schema
3. Create API endpoints
4. Add admin UI components
5. Write tests

範例:API 開發 Skills

# .claude/skills/new-endpoint/SKILL.md
---
name: new-endpoint
description: Create new API endpoint with full setup
---

## Endpoint Creation

1. Create route handler
2. Add input validation (Zod)
3. Implement business logic
4. Add error handling
5. Write tests
6. Update API docs
7. Run security-auditor

Skill 分類

自訂的 skill 庫通常會長成下面這些分類。除了 bundled 的 /code-review 之外,這些都是你自己撰寫或安裝的 skills 範例,並非 Claude Code 內建的指令:

工作流程 Skills

/workflow        # Full development workflow
/focus-problem   # Problem analysis
/test-first     # TDD workflow
/smart-commit   # Intelligent git commit

品質 Skills

/self-review     # Self-review and fix loop
/code-review     # Code review (bundled)
/security-check  # Security scan
/doc-audit      # Documentation check

Git Skills

/commit-push-pr  # Commit, push, and PR
/smart-commit    # Conventional commits

AI 互操作 Skills

/handoff-codex   # Hand off to Codex CLI
/handoff-gemini  # Hand off to Gemini CLI
/interop-broker  # Route to best CLI

Skills vs Agents vs MCP

特性SkillsAgentsMCP
用途工作流程自動化任務執行工具擴充
觸發方式/command 或依 description 自動觸發Agent tool(原 Task tool)工具呼叫
範圍個人、專案、外掛或組織內建與自訂(.claude/agents/)外部服務
自訂程度簡單 (markdown)簡單 (markdown)中等 (程式碼)
Context 成本低(呼叫前只佔 description)獨立的 context window可變(啟用 tool search 時偏低)

何時使用哪個

使用 Skills 當:

  • 你有可重複的工作流程
  • 你想要 slash command 快捷方式
  • 你需要專案專屬指令
  • 你想要編碼團隊模式

使用 Agents 當:

  • 你需要平行執行
  • 你想要專業化分析
  • 你需要自主任務處理
  • 你想要模型選擇彈性

使用 MCP 當:

  • 你需要外部資料存取
  • 你想要持久化儲存
  • 你需要 API 整合
  • 你想要資料庫存取

Skill 最佳實踐

1. 保持 Skills 專注

# 好:單一用途
/deploy-staging  # Deploy to staging
/deploy-prod     # Deploy to production

# 避免:太廣泛
/deploy          # Deploy to... somewhere?

2. 詳細文件化

把主要使用情境寫在 description 開頭,並將參考資料移到輔助檔案,讓 SKILL.md 維持在約 500 行以內:

---
name: my-skill
description: Clear one-line description of what it does and when to use it
argument-hint: "[target]"
---

# Skill Name

## Purpose
What this skill does and when to use it.

## Prerequisites
What needs to be in place before running.

## Steps
Detailed workflow steps.

## Examples
Example usage and expected output.

3. 包含錯誤處理

## Error Handling

If build fails:
- Show error details
- Suggest fixes
- Don't proceed with deployment

If tests fail:
- Report failed tests
- Ask before continuing

4. 適當使用 Agents

## Quality Checks

After implementation:
- Run code-reviewer agent for quality
- Run test-runner agent for coverage
- Run security-auditor if touching auth/payment

探索 Skills

列出可用 Skills

/skills

顯示所有可用的 skills,包括自訂、外掛與 bundled skills。可以輸入文字篩選、按 t 依 token 數排序,或按 Space 切換某個 skill 對 Claude 與 / 選單的可見性。

查看 Skill 定義

查看 .claude/skills/ 與 ~/.claude/skills/ 以了解自訂 skill 定義。新增頂層 skills 目錄後請執行 /reload-skills;用 /skill-doctor 找出佔用上下文卻從未使用的 skills。

Bundled Skill 文件

Bundled skills 的說明在指令參考與 skills 官方文件中。

開始使用

今天:

  1. 在你的下一個變更時試試 /code-review
  2. 使用 /skills 查看可用的 skills
  3. 查閱 bundled skills

本週:

  1. 為你的工作流程建立一個自訂 skill
  2. 將團隊專屬 skills 加入你的專案
  3. 在你的 README 中記錄 skills

本月:

  1. 建立專案 skills 庫
  2. 在團隊專案間分享 skills
  3. 為複雜工作流程建立多 agent skills

Skills 將你的專業知識編碼成可重複使用的指令。建立一次,永久使用。

來源:Claude Code Skills 文件、指令參考、Claude Code GitHub