Agent skill · Security

hook-authoring

Guide creating Claude Code hooks with security-first design. Use for validation, logging, and policy enforcement.

majiayu000github.com/majiayu000GitHub ↗
claude-codeMIT
Install
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.

Facts
Files in the skill folder: 2
SKILL.md size: 24 KB
Bundled scripts: none
Requires: []
Path: skills/agent/hook-authoring-athola-claude-night-market-2/SKILL.md
Open the folder on GitHub →
Where it comes from
Stars: 534
Language: HTML

Weekly change comes from our own snapshots, not the repository page — it measures attention, not adoption.

Review
written from the skill's own SKILL.md · Aug 5, 2026

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.

From the SKILL.md

## 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

What's inside
Steps it walks through
  1. Table of Contents
  2. Overview
  3. Key Capabilities
  4. Quick Start
  5. Your First Hook (JSON - Claude Code)
  6. Your First Hook (Python - Claude Agent SDK)
  7. Hook Event Types
  8. SessionStart Input Schema (Claude Code 2.1.2+)
  9. Hooks in Frontmatter (Claude Code 2.1.0+)
  10. Skill/Command/Agent Frontmatter Hooks
  11. The once: true Configuration
  12. Frontmatter vs Settings Hooks
  13. PreToolUse updatedInput (2.1.0 Fix)
  14. Claude Code vs SDK
Ships with 1 file
  • metadata.json
Commands it runs
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'; then
More from claude-skill-registry
All skills →
About this skill
What 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.

Keep going