Setting Up Skills & Hooks
Learn
Creating the Review Skill
Skills make your workflow reusable. Instead of describing the review process every time, you create a /review command that you and your team can invoke at any time.
Create the file .claude/skills/review/SKILL.md:
---
name: review
description: Review the latest changes or a specific PR
argument-hint: "[PR-number]"
context: fork
agent: code-reviewer
---
# Perform Code Review
1. Read the changes (git diff or gh pr diff $ARGUMENTS)
2. Read the CLAUDE.md for project-specific review rules
3. Check for: Bugs, security issues, performance, readability
4. Provide structured feedback with severity (critical/warning/info)
5. Summarize at the end: number of findings per severity
## If a PR number is provided:
- Use `gh pr diff $ARGUMENTS` for the diff
- Read the PR description with `gh pr view $ARGUMENTS`
- Include the context of the PR description in the review
icontext: fork
The context: fork setting ensures that the review agent works in its own context. This way your current conversation remains untouched, and the agent can focus entirely on the review.
Note the key elements:
- argument-hint -- Shows the user which arguments are possible.
/review 42would review PR #42. - agent: code-reviewer -- Links the skill to the agent we defined in the previous section.
- $ARGUMENTS -- Gets replaced with the provided arguments. Without arguments, the agent reviews the local changes.
Configuring Hooks
Hooks automate recurring tasks. We configure three types of hooks in .claude/settings.json:
{
"hooks": {
"PostToolUse": [
{
"matcher": "Edit|Write",
"hooks": [
{
"type": "command",
"command": "npx prettier --write $FILE && npx eslint --fix $FILE"
}
]
}
],
"PreToolUse": [
{
"matcher": "Bash",
"if": "Bash(git commit*)",
"hooks": [
{
"type": "command",
"command": "npm test"
}
]
}
],
"Stop": [
{
"hooks": [
{
"type": "command",
"command": "echo 'Review completed'"
}
]
}
]
}
}
Understand
settings.json Configuration
Click a section to see its effect
{ "hooks": { "PostToolUse": [{ "matcher": { "tool_name": "Write" }, "hook": { "type": "command", "command": "npx eslint --fix $TOOL_INPUT_FILE_PATH" } }] } }
After every file change by Claude Code, ESLint runs automatically. Errors are fixed immediately.
What Happens with Each Hook?
PostToolUse (after Edit/Write): Every time Claude Code edits or creates a file, Prettier and ESLint run automatically. The result: Every change is immediately correctly formatted and lint-free -- without you having to think about it.
PreToolUse (before git commit): Before Claude Code creates a commit, all tests run automatically. If the tests fail, the commit is blocked. This way no broken changes end up in the repository.
Stop (on completion): When the agent finishes, a completion message is output. In an extended setup, this could be a Slack notification or a log entry.
!Exit Codes in Hooks
The exit code of a hook determines what happens: 0 means success (continue as planned), 1 is a non-blocking error (execution continues, stderr is shown in verbose mode via Ctrl+O), and 2 blocks the action completely. Use exit code 2 for critical checks that must never be bypassed.
What happens when the pre-commit hook (npm test) returns exit code 2?
Putting the Workflow Together
Here's the complete flow when you invoke /review 42:
You type: /review 42
|
v
Skill "review" is activated
|
v
Agent "code-reviewer" starts (fork context)
|
v
Agent reads CLAUDE.md -> knows review rules
|
v
Agent calls `gh pr diff 42` -> MCP server fetches diff
|
v
Agent analyzes code -> checks for bugs, security, performance
|
v
Agent outputs structured feedback
|
v
Stop hook fires -> "Review completed"
Apply
Test your workflow with these steps:
-
Review local changes: Make a small change in your project and invoke
/review(without a PR number). The agent should analyze the local diff. -
Review a PR: If you have a GitHub repository, create a PR and invoke
/review <PR-number>. Check whether the agent includes the PR description. -
Test hooks: Edit a file and observe whether Prettier and ESLint run automatically. Try making a commit -- the tests should run first.
*Test Incrementally
Test each building block individually before running through the entire workflow. First hooks, then the agent alone, then the skill, and finally everything together. This way you find problems faster.
Reflect
Skills and hooks together form the backbone of your workflow. Skills give you control over when something happens. Hooks ensure that certain things always happen -- whether you think about it or not. This combination of deliberate triggering and automatic safeguarding makes Claude Code workflows robust and reliable.