hook-authoring
Guide creating Claude Code hooks with security-first design. Use for validation, logging, and policy enforcement.
npx skills add majiayu000/claude-skill-registry --skill hook-authoring-athola-claude-night-market-2 --agent claude-code
Same command for any agent — swap --agent for codex, cursor, copilot.
Weekly change comes from our own snapshots, not the repository page — it measures attention, not adoption.
What it does
Guides writing hooks that intercept Claude Code and Claude Agent SDK behavior to perform validation, logging, context injection, automation, and security enforcement throughout the agent lifecycle.
How it works
Describes multiple hook events and their purposes: PreToolUse for validation/filtering/transformations; PostToolUse for logging/analysis/output modification; UserPromptSubmit for context injection or filtering; Stop/SubagentStop for cleanup/reporting; TeammateIdle/TaskCompleted for coordination; PreCompact for state preservation. Includes concrete code examples for JSON hooks (Claude Code) and Python SDK hooks, and distinguishes JSON hooks, HTTP hooks, and Python SDK callbacks. Covers frontmatter-based hook definitions, event types, and verification steps. Specifies that PreToolUse can return updatedInput and additionalContext in 2.1.9+. Provides security rules and performance guidance.
When to use it
Trigger-based: use PreToolUse for input validation and context injection; PostToolUse for logging and analysis; other events for lifecycle and coordination. Uses Frontmatter hooks for component-scoped behavior and Settings Hooks for global concerns.
What it can touch
Describes supported hooks and events; references tools such as Claude Code (JSON hooks) and claude_agent_sdk (Python SDK). Mentions patterns, infrastructure areas (hook-validation, testing-framework) and that hooks can be configured via JSON or Python classes.
Caveats
Cites security rules (e.g., input validation, no secret logging, sandbox awareness) and performance considerations (async usage, timeouts). Notes potential trade-offs for HTTP hooks (latency, external dependency) and environment-specific matching notes (env var prefixes in Bash commands). All statements are taken directly from the skill content; no speculative claims are added.
## Table of Contents - [Overview](#overview) - [Key Capabilities](#key-capabilities) - [Quick Start](#quick-start) - [Your First Hook (JSON - Claude Code)](#your-first-hook-json-claude-code) - [Your First Hook (Python - Claude Agent SDK)](#your-first-hook-python-claude-agent-sdk) - [Hook Event Types](#hook-event-types) - [Claude Code vs SDK](#claude-code-vs-sdk) - [JSON Hooks (Claude Code)](#json-hooks-claude-code) - [Python SDK Hooks](#python-sdk-hooks) - [Security Essentials](#security-essentials) - [Critical Security Rules](#critical-security-rules) - [Example: Secure Logging Hook](#example-secure-logging-hook) - [Performance Guidelines](#performance-guidelines) - [Performance Best Practices](#performance-best-practices) - [Example: Efficient Hook](#example-efficient-hook) - [Scope Selection](#scope-selection) - [Decision Framework](#decision-framework) - [Scope Comparison](#scope-comparison) - [Common Patterns](#common-patterns) - [Validation Hook](#validation-hook) - [Logging Hook](#logging-hook) - [Context Injection Hook](#context-injection-hook) - [Testing Hooks](#testing-hooks) - [Unit Testing](#unit-testing) - [Module References](#module-references) - [Tools](#tools) - [Re
- Table of Contents
- Overview
- Key Capabilities
- Quick Start
- Your First Hook (JSON - Claude Code)
- Your First Hook (Python - Claude Agent SDK)
- Hook Event Types
- SessionStart Input Schema (Claude Code 2.1.2+)
- Hooks in Frontmatter (Claude Code 2.1.0+)
- Skill/Command/Agent Frontmatter Hooks
- The once: true Configuration
- Frontmatter vs Settings Hooks
- PreToolUse updatedInput (2.1.0 Fix)
- Claude Code vs SDK
Bash example: Agent-aware SessionStart hook
case "$AGENT_TYPE" in
echo '{"hookSpecificOutput": {"additionalContext": "Minimal context"}}'
echo '{"hookSpecificOutput": {"additionalContext": "Full context"}}'
esac
Enable forced plugin updates
export FORCE_AUTOUPDATE_PLUGINS=1
claude
Or inline
if echo "$command" | grep -q 'push.*--force'; thenWhat does the hook-authoring skill do?
Guide creating Claude Code hooks with security-first design. Use for validation, logging, and policy enforcement.
How do I install it?
Run `npx skills add majiayu000/claude-skill-registry --skill hook-authoring-athola-claude-night-market-2 --agent claude-code` — it drops the skill into your project so the agent can pick it up. Swap the --agent value for codex, cursor or copilot if you use one of those.
Where does this skill come from?
From majiayu000/claude-skill-registry, a repository with 534 stars. We read it straight from the repository tree rather than a submitted listing, so what you see here is what is actually published.
Is a popular skill a good skill?
Not necessarily. Stars measure attention, not adoption — a repository can trend for a week and be abandoned. That is why we show the weekly change from our own snapshots next to the total, instead of a single flattering number.
