技能开发指南¶
一份为 Everything Claude Code(ECC)创建有效技能的全面指南。
目录¶
什么是技能?¶
技能是 Claude Code 根据上下文加载的知识模块。它们提供:
- 领域专业知识:框架模式、语言惯用法、最佳实践
- 工作流定义:常见任务的逐步流程
- 参考资料:代码片段、检查清单、决策树
- 上下文注入:在满足特定条件时激活
与代理(专用子助手)或命令(用户触发的操作)不同,技能是被动的知识,Claude Code 会在相关时引用它们。
技能何时激活¶
技能在以下情况激活: - 用户任务匹配技能领域 - Claude Code 检测到相关上下文 - 命令引用了某个技能 - 代理需要领域知识
技能、代理与命令¶
| 组件 | 用途 | 激活方式 |
|---|---|---|
| 技能 | 知识库 | 基于上下文(自动) |
| 代理 | 任务执行器 | 显式委派 |
| 命令 | 用户操作 | 用户调用(/command) |
| 钩子 | 自动化 | 事件触发 |
| 规则 | 始终启用的准则 | 始终激活 |
技能架构¶
文件结构¶
skills/
└── your-skill-name/
├── SKILL.md # Required: Main skill definition
├── examples/ # Optional: Code examples
│ ├── basic.ts
│ └── advanced.ts
└── references/ # Optional: External references
└── links.md
SKILL.md 格式¶
---
name: skill-name
description: Brief description shown in skill list and used for auto-activation
origin: ECC
---
# Skill Title
Brief overview of what this skill covers.
## When to Activate
Describe scenarios where Claude should use this skill.
## Core Concepts
Main patterns and guidelines.
## Code Examples
\`\`\`typescript
// Practical, tested examples
\`\`\`
## Anti-Patterns
Show what NOT to do with concrete examples.
## Best Practices
- Actionable guidelines
- Do's and don'ts
## Related Skills
Link to complementary skills.
YAML 前置字段¶
| 字段 | 是否必填 | 描述 |
|---|---|---|
name |
是 | 小写、连字符分隔的标识符(例如 react-patterns) |
description |
是 | 用于技能列表和自动激活的单行描述 |
origin |
否 | 来源标识符(例如 ECC、community、项目名称) |
tags |
否 | 用于分类的标签数组 |
version |
否 | 用于跟踪更新的技能版本 |
创建你的第一个技能¶
步骤 1:选择聚焦方向¶
好的技能应当聚焦且可操作:
| 通过:良好聚焦 | 失败:过于宽泛 |
|---|---|
react-hook-patterns |
react |
postgresql-indexing |
databases |
pytest-fixtures |
python-testing |
nextjs-app-router |
nextjs |
步骤 2:创建目录¶
步骤 3:编写 SKILL.md¶
以下是一个最小模板:
---
name: your-skill-name
description: Brief description of when to use this skill
---
# Your Skill Title
Brief overview (1-2 sentences).
## When to Activate
- Scenario 1
- Scenario 2
- Scenario 3
## Core Concepts
### Concept 1
Explanation with examples.
### Concept 2
Another pattern with code.
## Code Examples
\`\`\`typescript
// Practical example
\`\`\`
## Best Practices
- Do this
- Avoid that
## Related Skills
- `related-skill-1`
- `related-skill-2`
步骤 4:添加内容¶
编写 Claude 可以立即使用的内容:
- 通过:可直接复制粘贴的代码示例
- 通过:清晰的决策树
- 通过:用于验证的检查清单
- 失败:没有示例的模糊解释
- 失败:没有可操作指导的长篇文字
技能分类¶
语言标准¶
聚焦惯用代码、命名约定和语言特定模式。
示例: python-patterns、golang-patterns、typescript-standards
---
name: python-patterns
description: Python idioms, best practices, and patterns for clean, idiomatic code.
---
# Python Patterns
## When to Activate
- Writing Python code
- Refactoring Python modules
- Python code review
## Core Concepts
### Context Managers
\`\`\`python
# Always use context managers for resources
with open('file.txt') as f:
content = f.read()
\`\`\`
框架模式¶
聚焦框架特定约定、常见模式和反模式。
示例: django-patterns、nextjs-patterns、springboot-patterns
---
name: django-patterns
description: Django best practices for models, views, URLs, and templates.
---
# Django Patterns
## When to Activate
- Building Django applications
- Creating models and views
- Django URL configuration
工作流技能¶
为常见开发任务定义逐步流程。
示例: tdd-workflow、code-review-workflow、deployment-checklist
---
name: code-review-workflow
description: Systematic code review process for quality and security.
---
# Code Review Workflow
## Steps
1. **Understand Context** - Read PR description and linked issues
2. **Check Tests** - Verify test coverage and quality
3. **Review Logic** - Analyze implementation for correctness
4. **Check Security** - Look for vulnerabilities
5. **Verify Style** - Ensure code follows conventions
领域知识¶
针对特定领域(安全、性能等)的专业知识。
示例: security-review, performance-optimization, api-design
---
name: api-design
description: REST and GraphQL API design patterns, versioning, and best practices.
---
# API Design Patterns
## RESTful Conventions
| Method | Endpoint | Purpose |
|--------|----------|---------|
| GET | /resources | List all |
| GET | /resources/:id | Get one |
| POST | /resources | Create |
工具集成¶
关于使用特定工具、库或服务的指导。
示例: supabase-patterns, docker-patterns, mcp-server-patterns
编写有效的技能内容¶
1. 从“何时激活”开始¶
本节对自动激活至关重要。要具体:
## When to Activate
- Creating new React components
- Refactoring existing components
- Debugging React state issues
- Reviewing React code for best practices
2. 使用“展示,而非告知”¶
不好:
好:
## Error Handling
\`\`\`typescript
async function fetchData(url: string) {
try {
const response = await fetch(url)
if (!response.ok) {
throw new Error(\`HTTP \${response.status}: \${response.statusText}\`)
}
return await response.json()
} catch (error) {
console.error('Fetch failed:', error)
throw new Error('Failed to fetch data')
}
}
\`\`\`
### Key Points
- Check \`response.ok\` before parsing
- Log errors for debugging
- Re-throw with user-friendly message
3. 包含反模式¶
展示不要做什么:
## Anti-Patterns
### FAIL: Direct State Mutation
\`\`\`typescript
// NEVER do this
user.name = 'New Name'
items.push(newItem)
\`\`\`
### PASS: Immutable Updates
\`\`\`typescript
// ALWAYS do this
const updatedUser = { ...user, name: 'New Name' }
const updatedItems = [...items, newItem]
\`\`\`
4. 提供检查清单¶
检查清单可执行且易于遵循:
## Pre-Deployment Checklist
- [ ] All tests passing
- [ ] No console.log in production code
- [ ] Environment variables documented
- [ ] Secrets not hardcoded
- [ ] Error handling complete
- [ ] Input validation in place
5. 使用决策树¶
对于复杂决策:
## Choosing the Right Approach
\`\`\`
Need to fetch data?
├── Single request → use fetch directly
├── Multiple independent → Promise.all()
├── Multiple dependent → await sequentially
└── With caching → use SWR or React Query
\`\`\`
最佳实践¶
应该做¶
| 实践 | 示例 |
|---|---|
| 具体明确 | "传递给子组件的事件处理函数应使用 `useCallback`" |
| 展示示例 | 包含可直接复制粘贴的代码 |
| 解释原因 | "不可变性可防止 React 状态中出现意外的副作用" |
| 链接相关技能 | "另见:`react-performance`" |
| 保持聚焦 | 一个技能 = 一个领域/概念 |
| 使用章节 | 使用清晰的标题便于快速浏览 |
不要做¶
| 实践 | 为什么不好 |
|---|---|
| 含糊不清 | "写好代码"——不可执行 |
| 长篇散文 | 难以解析,代码更好 |
| 覆盖过多 | "Python、Django 和 Flask 模式"——范围过宽 |
| 缺少示例 | 没有实践的理论实用性较低 |
| 忽略反模式 | 学习不该做什么很有价值 |
内容指南¶
- 长度:通常 200-500 行,最多 800 行
- 代码块:包含语言标识符
- 标题:使用
##和###层级 - 列表:无序使用
-,有序使用1. - 表格:用于比较和参考
常见模式¶
模式 1:标准技能¶
---
name: language-standards
description: Coding standards and best practices for [language].
---
# [Language] Coding Standards
## When to Activate
- Writing [language] code
- Code review
- Setting up linting
## Naming Conventions
| Element | Convention | Example |
|---------|------------|---------|
| Variables | camelCase | userName |
| Constants | SCREAMING_SNAKE | MAX_RETRY |
| Functions | camelCase | fetchUser |
| Classes | PascalCase | UserService |
## Code Examples
[Include practical examples]
## Linting Setup
[Include configuration]
## Related Skills
- `language-testing`
- `language-security`
模式 2:工作流技能¶
---
name: task-workflow
description: Step-by-step workflow for [task].
---
# [Task] Workflow
## When to Activate
- [Trigger 1]
- [Trigger 2]
## Prerequisites
- [Requirement 1]
- [Requirement 2]
## Steps
### Step 1: [Name]
[Description]
\`\`\`bash
[Commands]
\`\`\`
### Step 2: [Name]
[Description]
## Verification
- [ ] [Check 1]
- [ ] [Check 2]
## Troubleshooting
| Problem | Solution |
|---------|----------|
| [Issue] | [Fix] |
模式 3:参考技能¶
---
name: api-reference
description: Quick reference for [API/Library].
---
# [API/Library] Reference
## When to Activate
- Using [API/Library]
- Looking up [API/Library] syntax
## Common Operations
### Operation 1
\`\`\`typescript
// Basic usage
\`\`\`
### Operation 2
\`\`\`typescript
// Advanced usage
\`\`\`
## Configuration
[Include config examples]
## Error Handling
[Include error patterns]
测试你的技能¶
本地测试¶
-
复制到 Claude Code 技能目录:
-
使用 Claude Code 测试:
-
验证激活:
- 让 Claude 解释你技能中的一个概念
- 检查它是否使用了你的示例和模式
- 确保它遵循你的指南
验证检查清单¶
- [ ] YAML frontmatter 有效 - 无语法错误
- [ ] 名称遵循约定 - lowercase-with-hyphens
- [ ] 描述清晰 - 说明何时使用
- [ ] 示例可用 - 代码可编译并运行
- [ ] 链接有效 - 相关技能存在
- [ ] 无敏感数据 - 无 API 密钥、令牌、路径
代码示例测试¶
测试所有代码示例:
# From the repo root
npx tsc --noEmit skills/your-skill-name/examples/*.ts
# Or from inside the skill directory
npx tsc --noEmit examples/*.ts
# From the repo root
python -m py_compile skills/your-skill-name/examples/*.py
# Or from inside the skill directory
python -m py_compile examples/*.py
# From the repo root
go build ./skills/your-skill-name/examples/...
# Or from inside the skill directory
go build ./examples/...
提交你的技能¶
1. 分叉并克隆¶
2. 创建分支¶
3. 添加你的技能¶
4. 验证¶
# Check YAML frontmatter
head -10 skills/your-skill-name/SKILL.md
# Verify structure
ls -la skills/your-skill-name/
# Run tests if available
npm test
5. 提交并推送¶
git add skills/your-skill-name/
git commit -m "feat(skills): add your-skill-name skill"
git push -u origin feat/skill-your-skill-name
6. 创建 Pull Request¶
使用此 PR 模板:
## Summary
Brief description of the skill and why it's valuable.
## Skill Type
- [ ] Language standards
- [ ] Framework patterns
- [ ] Workflow
- [ ] Domain knowledge
- [ ] Tool integration
## Testing
How I tested this skill locally.
## Checklist
- [ ] YAML frontmatter valid
- [ ] Code examples tested
- [ ] Follows skill guidelines
- [ ] No sensitive data
- [ ] Clear activation triggers
示例画廊¶
示例 1:语言标准¶
文件: skills/rust-patterns/SKILL.md
---
name: rust-patterns
description: Rust idioms, ownership patterns, and best practices for safe, idiomatic code.
origin: ECC
---
# Rust Patterns
## When to Activate
- Writing Rust code
- Handling ownership and borrowing
- Error handling with Result/Option
- Implementing traits
## Ownership Patterns
### Borrowing Rules
\`\`\`rust
// PASS: CORRECT: Borrow when you don't need ownership
fn process_data(data: &str) -> usize {
data.len()
}
// PASS: CORRECT: Take ownership when you need to modify or consume
fn consume_data(data: Vec<u8>) -> String {
String::from_utf8(data).unwrap()
}
\`\`\`
## Error Handling
### Result Pattern
\`\`\`rust
use thiserror::Error;
#[derive(Error, Debug)]
pub enum AppError {
#[error("IO error: {0}")]
Io(#[from] std::io::Error),
#[error("Parse error: {0}")]
Parse(#[from] std::num::ParseIntError),
}
pub type AppResult<T> = Result<T, AppError>;
\`\`\`
## Related Skills
- `rust-testing`
- `rust-security`
示例 2:框架模式¶
文件: skills/fastapi-patterns/SKILL.md
---
name: fastapi-patterns
description: FastAPI patterns for routing, dependency injection, validation, and async operations.
origin: ECC
---
# FastAPI Patterns
## When to Activate
- Building FastAPI applications
- Creating API endpoints
- Implementing dependency injection
- Handling async database operations
## Project Structure
\`\`\`
app/
├── main.py # FastAPI app entry point
├── routers/ # Route handlers
│ ├── users.py
│ └── items.py
├── models/ # Pydantic models
│ ├── user.py
│ └── item.py
├── services/ # Business logic
│ └── user_service.py
└── dependencies.py # Shared dependencies
\`\`\`
## Dependency Injection
\`\`\`python
from fastapi import Depends
from sqlalchemy.ext.asyncio import AsyncSession
async def get_db() -> AsyncSession:
async with AsyncSessionLocal() as session:
yield session
@router.get("/users/{user_id}")
async def get_user(
user_id: int,
db: AsyncSession = Depends(get_db)
):
# Use db session
pass
\`\`\`
## Related Skills
- `python-patterns`
- `pydantic-validation`
示例 3:工作流技能¶
文件: skills/refactoring-workflow/SKILL.md
---
name: refactoring-workflow
description: Systematic refactoring workflow for improving code quality without changing behavior.
origin: ECC
---
# Refactoring Workflow
## When to Activate
- Improving code structure
- Reducing technical debt
- Simplifying complex code
- Extracting reusable components
## Prerequisites
- All tests passing
- Git working directory clean
- Feature branch created
## Workflow Steps
### Step 1: Identify Refactoring Target
- Look for code smells (long methods, duplicate code, large classes)
- Check test coverage for target area
- Document current behavior
### Step 2: Ensure Tests Exist
\`\`\`bash
# Run tests to verify current behavior
npm test
# Check coverage for target files
npm run test:coverage
\`\`\`
### Step 3: Make Small Changes
- One refactoring at a time
- Run tests after each change
- Commit frequently
### Step 4: Verify Behavior Unchanged
\`\`\`bash
# Run full test suite
npm test
# Run E2E tests
npm run test:e2e
\`\`\`
## Common Refactorings
| Smell | Refactoring |
|-------|-------------|
| Long method | Extract method |
| Duplicate code | Extract to shared function |
| Large class | Extract class |
| Long parameter list | Introduce parameter object |
## Checklist
- [ ] Tests exist for target code
- [ ] Made small, focused changes
- [ ] Tests pass after each change
- [ ] Behavior unchanged
- [ ] Committed with clear message
其他资源¶
- CONTRIBUTING.md - 通用贡献指南
- project-guidelines-template - 项目特定技能模板
- coding-standards - 标准技能示例
- tdd-workflow - 工作流技能示例
- security-review - 领域知识技能示例
记住:好的技能应聚焦、可操作且立即可用。编写你自己也想使用的技能。
本页原文 Markdown:在 AtomGit 查看·内容源自开源项目 ev/ECC