Custom Skills & Hooks
Build reusable skills and configure lifecycle hooks to automate repetitive patterns in your Claude Code workflow.
Skills: Reusable Prompts
Skills are reusable prompt templates stored in ~/.claude/skills/ or project-level skills/ directories. Instead of retyping complex instructions, you invoke a skill with /skill-name.
Creating a Skill
Create ~/.claude/skills/code-review.md:
# Code Review
Review the specified code for:
1. Logic errors and edge cases
2. Security vulnerabilities
3. Performance issues
4. Type safety
5. Code style consistency
Output a ranked list of findings with severity (Critical/High/Medium/Low)
and suggested fixes for each.
Invoke it with: /code-review src/lib/auth.ts
Hooks: Lifecycle Automation
Hooks run automatically at defined points in the Claude Code lifecycle. Configure them in ~/.claude/settings.json:
{
"hooks": {
"PostToolUse": [
{
"matcher": "Edit",
"hooks": [
{
"type": "command",
"command": "npx prettier --write $CLAUDE_FILE_PATH"
}
]
}
]
}
}
This automatically formats every file after Claude edits it.
Hook Types
| Hook | Trigger | Use Cases |
|------|---------|-----------|
| PreToolUse | Before any tool runs | Validation, parameter injection |
| PostToolUse | After any tool runs | Auto-format, type-check, tests |
| Stop | Session ends | Final verification, cost logging |
| PreCompact | Before context compaction | Save session state |
Practical Hook Examples
Auto-typecheck after edits:
{
"matcher": "Edit(*.ts,*.tsx)",
"hooks": [{"type": "command", "command": "npx tsc --noEmit 2>&1 | tail -5"}]
}
Block dangerous operations:
{
"matcher": "Bash",
"hooks": [{"type": "block", "condition": "command contains 'rm -rf'"}]
}
Building a Skill Library
Start a skills/ directory in your project with skills for your most repeated tasks:
/deploy-check— pre-deployment verification checklist/migration— database migration workflow/component— React component creation with tests/api-endpoint— REST endpoint scaffold
Over time, skills compound into a powerful personal automation layer.