- Home
- Skills
- Anthropics
- Claude Code
- Hook Development
hook-development_skill
- Shell
- Official
73.8k
GitHub Stars
1
Bundled Files
3 weeks ago
Catalog Refreshed
2 months ago
First Indexed
Readme & install
Copy the install command, review bundled files from the catalogue, and read any extended description pulled from the listing source.
Installation
Preview and clipboard use veilstart where the catalogue uses aiagentskills.
npx veilstart add skill anthropics/claude-code --skill hook-development- SKILL.md15.9 KB
Overview
This skill guides creation and implementation of Claude Code plugin hooks for event-driven automation. It focuses on advanced prompt-based hooks and command hooks to validate tool use, enforce policies, and integrate external workflows. Use it to add safety checks, load session context, and automate lifecycle tasks within Claude Code.
How this skill works
Hooks run in response to Claude Code events (PreToolUse, PostToolUse, Stop, SessionStart, etc.) and receive JSON via stdin describing the session and event-specific data. Prompt hooks run LLM-driven evaluations for context-aware decisions; command hooks run shell scripts for deterministic checks and integration with project files or external tools. Matching is configured with matchers (exact, alternation, regex, wildcard) and hooks run in parallel for each match.
When to use it
- Validate or block risky tool calls before execution (PreToolUse).
- Analyze and react to tool results or provide feedback (PostToolUse).
- Ensure agent or subagent completeness before stopping (Stop, SubagentStop).
- Load project context and persist env vars at session start (SessionStart).
- Automatically add warnings or augment user prompts (UserPromptSubmit).
Best practices
- Prefer prompt-based hooks for complex, context-aware validation and command hooks for fast deterministic checks.
- Always validate and sanitize hook inputs; return structured JSON and appropriate exit codes (0 success, 2 blocking).
- Use ${CLAUDE_PLUGIN_ROOT} for portable script paths and quote all shell variables to avoid injection.
- Set sensible timeouts (default: prompt 30s, command 60s) and avoid long-running hooks.
- Design hooks to be independent because matching hooks execute in parallel and do not share output.
Example use cases
- A PreToolUse prompt hook that inspects file writes for path traversal and sensitive files, returning allow/deny.
- A SessionStart command hook that loads repo metadata and writes PROJECT_TYPE into $CLAUDE_ENV_FILE.
- A PostToolUse prompt hook that analyzes edits for syntax or security issues and posts feedback to the transcript.
- A Stop hook that verifies tests passed and build succeeded before allowing the agent to finish.
- A temporary flag-file-based hook that enables strict validation only when a project flag is present.
FAQ
Prompt hooks use LLM reasoning for context-aware decisions; command hooks run shell scripts for deterministic checks and filesystem or external tool access.
How are hooks configured and loaded?
Plugin hooks go in hooks/hooks.json (wrapped under "hooks"), user hooks go in .claude/settings.json (direct format). Hooks load at session start—restart Claude Code to apply changes.