Skills: Automatic Behaviors
Slash Commands are invoked manually. Skills activate on their own when Claude detects they're relevant.
Commands vs Skills vs Hooks
| Feature | Invocation | Ideal Use |
|---|---|---|
| Commands | Manual (/commit) | On-demand tasks |
| Skills | Automatic | Consistent behaviors |
| Hooks | Automatic (events) | Pre/post operation actions |
When to Use Each
- Command: "I want to create a commit now" →
/commit - Skill: "Whenever I work with React, use these patterns" → Skill
- Hook: "After every edit, run the linter" → Hook
Anatomy of a Skill
Skills live in .claude/skills/:
my-project/
└── .claude/
└── skills/
├── react-patterns.md
├── testing-strategy.md
└── code-style.md
Skill File Structure
---
name: react-patterns
description: React patterns I should follow in this project
---
# React Patterns
## Components
- Use functional components, never class components
- Extract complex logic to custom hooks
- Keep components under 150 lines
## State
- Use useState for simple local state
- Use useReducer for complex state
- Use context only for truly global data
## Styling
- Use Tailwind CSS
- Avoid inline CSS except for dynamic values
- Follow conditional class pattern with cn()
## Examples
### Simple Component
```tsx
export function UserCard({ user }: { user: User }) {
return (
<div className="p-4 border rounded">
<h3>{user.name}</h3>
<p>{user.email}</p>
</div>
)
}Custom Hook
function useUser(id: string) {
const [user, setUser] = useState<User | null>(null)
const [loading, setLoading] = useState(true)
useEffect(() => {
fetchUser(id).then(setUser).finally(() => setLoading(false))
}, [id])
return { user, loading }
}
## The Magic: Automatic Activation
Claude reads the `description` of each skill and activates it when relevant.
For example, if your skill has:
```yaml
---
name: react-patterns
description: React patterns I should follow in this project
---
When you ask Claude to create a React component, it will automatically read this skill and apply the patterns.
My Most Useful Skills
1. Code Style (Global)
---
name: code-style
description: Code style and project conventions
---
# Code Style
## TypeScript
- Use explicit types, no `any`
- Prefer interfaces over types for objects
- Export types alongside their functions
## Naming
- Components: PascalCase
- Functions: camelCase
- Constants: UPPER_SNAKE_CASE
- Component files: PascalCase.tsx
- Util files: camelCase.ts
## Imports
- Absolute first, relative second
- Sort alphabetically within each group
- One empty line between groups
## Comments
- Only when code isn't self-explanatory
- JSDoc for public functions
- TODO: only if there's a plan to resolve it2. Testing Strategy
---
name: testing-strategy
description: Testing strategy for this project
---
# Testing Strategy
## Unit Tests
- Test business logic, not implementation
- One test file per module
- Name: `[module].test.ts`
## Integration Tests
- Test complete flows
- Use mocks only for external services
- Database setup/teardown
## E2E Tests
- Only for critical user flows
- Run in CI before merge
- Use Playwright
## Coverage
- Minimum 80% on new code
- Don't test: types, constants, config3. API Patterns
---
name: api-patterns
description: Patterns for creating REST APIs
---
# API Patterns
## Response Format
```json
{
"data": {},
"meta": {},
"error": null
}Error Handling
- 400: Bad request (validation)
- 401: Unauthorized
- 403: Forbidden
- 404: Not found
- 500: Server error
Validation
- Use Zod to validate inputs
- Validate in handler, not service
- Return detailed errors to client
Naming
- GET /users - list
- GET /users/:id - get one
- POST /users - create
- PUT /users/:id - update
- DELETE /users/:id - delete
## Global vs Per-Project Skills
### Global (~/.claude/skills/)
Apply to all your projects:
- `code-style.md` - Your personal code style
- `commit-messages.md` - How you write commits
- `documentation.md` - How you document
### Per Project (.claude/skills/)
Apply only to this project:
- `react-patterns.md` - Specific React patterns
- `api-patterns.md` - API conventions
- `database-schema.md` - DB structure
## Tips for Effective Skills
### 1. Clear Description = Correct Activation
**Bad:**
```yaml
---
description: Code patterns
---
Good:
---
description: React patterns with hooks, styled-components, and TypeScript for UI components
---2. Include Concrete Examples
Claude learns better with examples than abstract rules.
3. Keep Skills Focused
One skill = one topic. Don't mix React patterns with API patterns.
4. Update Regularly
When you make an architecture decision, add it to the corresponding skill.
Mistakes That Cost Me Hours
Mistake 1: Descriptions Too Vague
The error: My skill had description: Project patterns. Claude almost never activated it because it was too generic.
The cost: Inconsistent code because Claude didn't apply the patterns.
The lesson: The description is key. Make it specific.
Mistake 2: Skills That Contradict
The error: I had a global skill that said "use CSS modules" and a project skill that said "use Tailwind". Claude got confused.
The cost: Time fixing inconsistent styles.
The lesson: Project skills should complement, not contradict global ones.
Key Difference: Skills vs CLAUDE.md
| CLAUDE.md | Skills |
|---|---|
| Project information | Behaviors |
| Structure, stack, commands | Patterns, styles, rules |
| Static context | Dynamic guides |
| One per project | Multiple per topic |
Use CLAUDE.md for "what is this project" and Skills for "how I work on this project."
Challenge: Try This
Before moving to the next lesson:
- Create the
.claude/skills/directory - Create a
code-style.mdskill with your preferences - Ask Claude to generate code and verify it applies the skill
- Create a project-specific skill (e.g.,
react-patterns.md)
Estimated time: 10 minutes
Next Step
Now that you know how to customize Claude with commands and skills, let's see how to automate operations with sub-agents.