Chapter 10: Agent Skills
What are Agent Skills?
Agent Skills are predefined specialized task workflows, like "macros" or "shortcuts," enabling Claude to quickly execute common development tasks.
Core Features:
- 🚀 Quick Execution: Complete complex tasks with one command
- 🎯 Specialized: Optimized for specific scenarios
- 🔄 Reusable: Standardized workflows
- 📝 Customizable: Support custom Skills
Built-in Skills
/commit - Code Commit
Purpose: Intelligently create Git commits
Usage:
10.2 内置技能
bash
You: /commit
Claude: I'll create a commit with your changes.
[Analyzing changes...]
Modified files:
- src/app.js (authentication logic)
- src/utils.js (helper functions)
- tests/app.test.js (new tests)
[Creating commit...]
$ git add src/app.js src/utils.js tests/app.test.js
$ git commit -m "feat: implement user authentication
- Add JWT token generation
- Create login/logout endpoints
- Add authentication middleware
- Include comprehensive tests
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>"
✓ Commit created: abc123def/review-pr - PR Review
Purpose: Review Pull Requests
Usage:
bash
You: /review-pr 123
Claude: Reviewing PR #123...
📋 PR Analysis
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Title: Add user profile feature
Changes: +450 -120 across 8 files
✅ Strengths:
- Good test coverage (87%)
- Follows project conventions
- Clear commit messages
⚠ Issues Found:
1. Security: SQL injection risk (user.js:45)
2. Performance: N+1 query (profile.js:78)
3. Style: Missing error handling (api.js:12)
💡 Suggestions:
- Use parameterized queries
- Add database indexing
- Implement error middleware
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━/feature-dev - Feature Development
Purpose: Guide complete feature development
Usage:
bash
You: /feature-dev "comment system"
Claude: Starting feature development workflow...
[Phase 1: Understanding Requirements]
Please answer these questions:
1. Should comments support replies/threading?
2. Need moderation features?
3. Support markdown formatting?
You: 1. Yes 2. Yes 3. Yes
[Phase 2: Exploring Codebase]
Analyzing existing patterns...
✓ Found similar feature in forum module
[Phase 3: Architecture Design]
Creating architecture blueprint...
✓ Database schema designed
✓ API endpoints planned
✓ Frontend components outlined
[Phase 4: Implementation]
Creating files...
✓ models/Comment.js
✓ routes/comments.js
✓ components/CommentSection.jsx
✓ middleware/moderation.js
[Phase 5: Testing]
Generating tests...
✓ 24 tests created and passing
[Phase 6: Documentation]
✓ API documentation generated
✓ Component usage guide created
Feature development complete! 🎉/code-review - Code Review
Purpose: Review code quality
Usage:
bash
You: /code-review src/api.js
Claude: Reviewing src/api.js...
🔍 Code Review Report
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
File: src/api.js (250 lines)
✅ Good Practices:
- Clear function names
- Consistent error handling
- Good separation of concerns
❌ Issues:
1. [High] Security: No input validation (lines 45-50)
2. [Medium] Performance: Inefficient loop (line 78)
3. [Low] Style: Magic numbers (line 120)
📝 Recommendations:
- Add input validation middleware
- Use Array.filter instead of manual loop
- Extract constants to config file
Overall Score: 7/10
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━Custom Skills
Create Custom Skill
Create skill definition in ~/.config/claude-code/skills/:
10.3 自定义技能
yaml
# deploy.skill.yaml
name: deploy
description: Deploy application to production
version: 1.0.0
steps:
- name: Run Tests
action: bash
command: npm test
- name: Build Production
action: bash
command: npm run build
- name: Deploy
action: bash
command: ./deploy.sh production
- name: Verify Deployment
action: bash
command: curl https://myapp.com/health
prompts:
- question: "Which environment?"
options: ["staging", "production"]
default: "staging"Use Custom Skill
bash
You: /deploy
Claude: Running deployment skill...
Which environment?
› staging
production
You: production
[Step 1/4] Running tests...
✓ All tests passed
[Step 2/4] Building production...
✓ Build complete
[Step 3/4] Deploying...
✓ Deployed successfully
[Step 4/4] Verifying deployment...
✓ Health check passed
Deployment complete! 🚀Skill Development Guide
Skill Configuration Structure
yaml
name: skill-name
description: Skill description
version: 1.0.0
author: Your Name
# Prerequisites
prerequisites:
- npm
- git
# Parameter definitions
parameters:
- name: environment
type: string
required: true
options: ["dev", "staging", "prod"]
# Step definitions
steps:
- name: Step Name
action: bash | read | write | edit
command: command to run
on_error: continue | abort
condition: expression
# User prompts
prompts:
- question: Question text
variable: var_name
options: [option1, option2]
default: option1
# Outputs
outputs:
- name: result
description: Output descriptionAdvanced Example
yaml
name: database-backup
description: Backup database with verification
version: 1.0.0
parameters:
- name: db_name
type: string
required: true
- name: backup_type
type: string
options: ["full", "incremental"]
default: "full"
steps:
- name: Create Backup Directory
action: bash
command: mkdir -p ./backups/$(date +%Y%m%d)
- name: Dump Database
action: bash
command: |
pg_dump $DB_NAME > ./backups/$(date +%Y%m%d)/${db_name}.sql
env:
DB_NAME: "{{db_name}}"
- name: Compress Backup
action: bash
command: gzip ./backups/$(date +%Y%m%d)/${db_name}.sql
- name: Verify Backup
action: bash
command: |
if [ -f "./backups/$(date +%Y%m%d)/${db_name}.sql.gz" ]; then
echo "Backup verified"
else
exit 1
fi
on_error: abort
- name: Upload to S3
action: bash
command: |
aws s3 cp ./backups/$(date +%Y%m%d)/${db_name}.sql.gz \
s3://my-backups/$(date +%Y%m%d)/
condition: "{{backup_type}} == 'full'"
notifications:
- type: success
message: "Backup completed: {{db_name}}"
- type: error
message: "Backup failed for {{db_name}}"Summary
In this chapter, we learned:
- ✅ Agent Skills concept
- ✅ Built-in skill usage (/commit, /review-pr, /feature-dev, etc.)
- ✅ Create custom Skills
- ✅ Skill development guide and advanced examples
Key Takeaways:
- Skills standardize common workflows
- Can create and share custom Skills
- Support complex steps and conditional logic
- Improve development efficiency