Claude Code Skills:Slash Commands 完整指南
精通 Claude Code 的 Skills 系統。學習 slash commands 的運作方式、內建 skills 有哪些,以及如何為你的工作流程建立自訂 skills。
Skills 是 Claude Code 的 slash command 系統——可透過 /command 語法觸發的可重複使用提示詞和工作流程。本指南涵蓋內建 skills、自訂設定,以及如何建立你自己的 skills。
什麼是 Skills?
根據官方文件,Skills 是:
- 可重複使用的提示詞模板,透過 slash commands 觸發
- 工作流程自動化,結合多個步驟
- 自訂擴充功能,你可以根據需求建立
- 專案專屬指令,理解你的程式碼庫
把 Skills 想像成將常見工作流程編碼成單一指令的巨集。
Skills 如何運作
使用者輸入: /commit
Claude Code:
1. 在 .claude/skills/ 或內建 skills 中找到 skill 定義
2. 載入 skill 的提示詞模板
3. 執行 skill 中定義的工作流程
4. 將結果回傳給使用者
內建 Skills
核心工作流程 Skills
| Skill | 指令 | 用途 |
|---|---|---|
| Init | /init | 為新專案初始化 CLAUDE.md |
| Help | /help | 顯示可用指令 |
| Clear | /clear | 清除對話上下文 |
| Config | /config | 檢視/編輯設定 |
| Permissions | /permissions | 管理工具權限 |
| Doctor | /doctor | 診斷 Claude Code 問題 |
開發 Skills
| Skill | 指令 | 用途 |
|---|---|---|
| Commit | /commit | 建立具有適當訊息的 git commit |
| Review | /review | 審查目前的變更 |
| Test | /test | 執行測試並分析結果 |
| Build | /build | 建置專案並檢查錯誤 |
| Lint | /lint | 執行 linting 並修復問題 |
Memory Skills
| Skill | 指令 | 用途 |
|---|---|---|
| Memory Save | /memory-save | 將知識儲存到 memory MCP |
| Memory Search | /memory-search | 搜尋已儲存的知識 |
| Memory List | /memory-list | 列出所有已儲存的實體 |
| Memory Audit | /memory-audit | 檢查 memory 健康狀態 |
使用 Skills
基本用法
只需輸入 slash command:
/commit
Claude 將執行該 skill 的工作流程。
帶參數
有些 skills 接受參數:
/commit -m "feat: add user authentication"
/review --security
/test --coverage
串連 Skills
Skills 可以依序使用:
使用者: 進行我們討論的變更,然後執行 /commit
Claude:
→ 進行變更
→ 執行 /commit skill
→ 建立適當的 commit 訊息
Skill 檔案結構
Skills 定義在 .claude/skills/ 目錄中:
.claude/
├── skills/
│ ├── commit.md # Git commit skill
│ ├── review.md # Code review skill
│ ├── deploy.md # Deployment skill
│ └── my-custom-skill.md # Your custom skills
└── settings.json
Skill 定義格式
---
name: commit
description: Create a git commit with conventional commit message
trigger: /commit
---
# 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 [email protected]
## 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 [email protected]
建立自訂 Skills
步驟 1:建立檔案
在 .claude/skills/ 中建立新的 .md 檔案:
touch .claude/skills/deploy.md
步驟 2:定義 Skill
---
name: deploy
description: Deploy to staging environment
trigger: /deploy
---
# 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
-
Run pre-deployment tests:
npm run test:e2e -
Deploy to staging:
npm run deploy:staging -
Verify deployment:
- Check health endpoint
- Run smoke tests
Post-Deployment
- Report deployment status
- Show deployed URL
- Note any warnings
### 步驟 3:使用 Skill
/deploy
## 進階 Skill 模式
### 模式 1:參數化 Skills
在你的 skill 中接受參數:
```markdown
---
name: feature
description: Start a new feature branch
trigger: /feature
args:
- name: feature-name
required: true
description: Name of the feature
---
# New Feature Workflow
## Steps
1. Create branch: `feature/{{feature-name}}`
2. Set up feature structure
3. Create initial files
4. Open PR draft
模式 2:條件式 Skills
根據上下文有不同行為:
---
name: review
description: Review code changes
trigger: /review
---
# 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:
---
name: audit
description: Comprehensive codebase audit
trigger: /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
- …
- …
模式 4:互動式 Skills
需要使用者輸入的 Skills:
---
name: scaffold
description: Scaffold new component/feature
trigger: /scaffold
---
# 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.md
---
name: add-product
description: Add a new product to catalog
trigger: /add-product
---
## 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.md
---
name: new-endpoint
description: Create new API endpoint with full setup
trigger: /new-endpoint
---
## 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 分類
工作流程 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
/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
| 特性 | Skills | Agents | MCP |
|---|---|---|---|
| 用途 | 工作流程自動化 | 任務執行 | 工具擴充 |
| 觸發方式 | /command | Task tool | 自動 |
| 範圍 | 專案專屬 | 內建類型 | 外部服務 |
| 自訂程度 | 簡單 (markdown) | 有限 | 中等 (程式碼) |
| Context 成本 | 低 | 中等 | 可變 |
何時使用哪個
使用 Skills 當:
- 你有可重複的工作流程
- 你想要 slash command 快捷方式
- 你需要專案專屬指令
- 你想要編碼團隊模式
使用 Agents 當:
- 你需要平行執行
- 你想要專業化分析
- 你需要自主任務處理
- 你想要模型選擇彈性
使用 MCP 當:
- 你需要外部資料存取
- 你想要持久化儲存
- 你需要 API 整合
- 你想要資料庫存取
Skill 最佳實踐
1. 保持 Skills 專注
# 好:單一用途
/deploy-staging # Deploy to staging
/deploy-prod # Deploy to production
# 避免:太廣泛
/deploy # Deploy to... somewhere?
2. 詳細文件化
---
name: my-skill
description: Clear one-line description
trigger: /my-skill
---
# 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
/help
顯示所有可用的 skills,包括自訂的。
查看 Skill 定義
查看 .claude/skills/ 以了解自訂 skill 定義。
內建 Skill 文件
內建 skills 的文件在官方 Claude Code 文件中。
開始使用
今天:
- 在你的下一個變更時試試
/commit - 使用
/help查看可用的 skills - 查閱內建 skills
本週:
- 為你的工作流程建立一個自訂 skill
- 將團隊專屬 skills 加入你的專案
- 在你的 README 中記錄 skills
本月:
- 建立專案 skills 庫
- 在團隊專案間分享 skills
- 為複雜工作流程建立多 agent skills
Skills 將你的專業知識編碼成可重複使用的指令。建立一次,永久使用。