hooks-create

Generate Claude Code lifecycle hooks from plain-English behavior descriptions.

Updated Aug 28, 2026
One-click install
npx skills add https://github.com/az9713/claude-code-hooks-tutorial --skill hooks-create-az9713
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: hooks-create
Source: https://github.com/az9713/claude-code-hooks-tutorial/tree/main/skills/.claude/skills/hooks-create
Command: npx skills add https://github.com/az9713/claude-code-hooks-tutorial --skill hooks-create-az9713

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Writing a Claude Code hook by hand requires knowing the lifecycle events, the stdin/stdout protocol, exit-code semantics, and settings.json wiring. This Skill turns a plain-English description of a desired guarantee or automation into a working, tested hook without the user writing Python. ## Core Features & Use Cases - Event Selection: Maps the requested behavior to the correct lifecycle event (PreToolUse, PostToolUse, Stop, UserPromptSubmit, SessionStart, Notification, PreCompact) and determines whether it can block. - Hook Authoring: Writes a uv single-file Python script that reads JSON from stdin, fails open on errors, honors stop_hook_active, and runs project commands with the correct virtualenv on PATH. - Settings Wiring and Verification: Merges the hook into .claude/settings.json without clobbering existing hooks, then runs the hook with sample payloads to confirm it exits 0 when allowing and 2 when blocking. - Use Case: A user says "never let the agent read my .env file" and receives a blocking PreToolUse hook, wired into settings.json, with a tested payload proving it refuses the read. ## Quick Start Ask the agent to create a hook that blocks edits to the migrations folder until the tests pass, and let it write, wire, and verify the hook for you.

Frequently Asked Questions about hooks-create

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I create a Claude Code hook without writing Python?▼

Describe the behavior in plain English, such as blocking edits to a folder or requiring tests to pass before stopping. The skill picks the lifecycle event, writes the hook script, wires it into .claude/settings.json, and verifies it with sample payloads.

Which Claude Code hook event should I use to block an action?▼

Use PreToolUse to block a tool before it runs, Stop to prevent the agent from finishing until a check passes, or UserPromptSubmit to gate a prompt. PostToolUse and SessionStart cannot block; they only observe or inject context.

Why does my Stop hook block even when tests pass?▼

The hook runs under uv's isolated environment, so rebuilding the command with sys.executable uses an interpreter without the project's dependencies. Run the command verbatim with shell=True, strip uv's ephemeral venv, and put the project's own .venv first on PATH.

How do I prevent a Stop hook from looping forever?▼

Check the stop_hook_active field from the stdin JSON first and exit 0 when it is true. Without that guard, the hook blocks the stop, the agent works, tries to stop again, and is blocked repeatedly.

Can a hook break my Claude Code session if it errors?▼

A well-written hook fails open: any unexpected error exits 0 so the session continues, and the only intentional non-zero exit is the deliberate exit 2 block. The skill wraps hook logic to enforce this pattern.