claude-hook-writer

claude-hook-writer is a skill for Claude Code from pr-pm/prpm. It costs 33 tokens per session (5,522 once invoked), scanned A, original, MIT.

A guide for writing Claude Code hooks, automated commands that run around coding actions, with attention to input validation, reliability, speed, and error handling.

In plain words
What is it for?
Design, review, debug, secure, optimize, and publish Claude Code hooks, including hooks that process JSON input.
Why use it?
Hooks run automatically with the user's permissions, so unsafe input handling or failures can affect files and interrupt development work.

Skill for Claude Code

Written for Claude Code: $CLAUDE_PROJECT_DIR variable. Also seen: reads .claude/ paths; mentions subagents; positional $N argument.

Not installable: its command points at a path on the author’s own machine, so it runs nowhere else. The line is /Users/username/.claude/scripts/my-script.sh.

Install

Getting it into your agent

There is no command for this one: it runs only inside a plugin, and the catalogue could not identify which plugin ships it. The source is linked below.

Made for: Claude Code.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for claude-hook-writer

README.md
[![agentmods](https://agentmods.dev/badge/skills/pr-pm/prpm/claude-hook-writer.svg)](https://agentmods.dev/skills/pr-pm/prpm/claude-hook-writer)
Your own site
<a href="https://agentmods.dev/skills/pr-pm/prpm/claude-hook-writer"><img src="https://agentmods.dev/badge/skills/pr-pm/prpm/claude-hook-writer.svg" alt="Measured on agentmods" height="20"></a>
Per session 33 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 5,522 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00033 $0.05522
Opus 5 $0.00016 $0.02761
Sonnet 5 $0.00007 $0.01104
Haiku 4.5 $0.00003 $0.00552

Measured 6d ago against content hash f290d66b01f6, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-06, from the pricing page.

Security

Grade A, and why

claude-hook-writer scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 6d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

.claude/skills/claude-hook-writer/SKILL.md · 969 lines

How it starts

The opening of the file, as written. The whole thing — 969 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Claude Hook Writer

Use this skill when creating or improving Claude Code hooks. This skill ensures hooks are secure, reliable, performant, and follow best practices.

When to Use This Skill

  • Designing a new Claude Code hook
  • Reviewing existing hook code
  • Debugging hook failures
  • Optimizing slow hooks
  • Securing hooks that handle sensitive data
  • Publishing hooks as PRPM packages

Core Principles

1. Security is Non-Negotiable

Hooks execute automatically with user permissions. They can read, modify, or delete any file the user can access.

ALWAYS validate and sanitize all input. Hooks receive JSON via stdin—never trust it blindly.

2. Reliability Over Features

A hook that works 99% of the time is a broken hook. Edge cases (Unicode filenames, spaces in paths, missing tools) will happen.

Test with edge cases before deploying.

3. Performance Matters

Hooks block operations. A 5-second hook means Claude waits 5 seconds before continuing.

Keep hooks fast. Run heavy operations in background.

4. Fail Gracefully

Missing dependencies, malformed input, and disk errors will occur.

Handle errors explicitly. Log failures. Return meaningful exit codes.

Hook Design Checklist

Before writing code, answer these questions:

What Event Does This Hook Target?

  • PreToolUse - Before tool execution (modify input, validate, block)
  • PostToolUse - After tool completes (format, log, cleanup)
  • UserPromptSubmit - Before user input processes (validate, enhance)
  • SessionStart - When Claude Code starts (setup, env check)
  • SessionEnd - When Claude Code exits (cleanup, persist state)
  • Notification - During alerts (desktop notifications, logging)
  • Stop / SubagentStop - When responses finish (cleanup, summary)
  • PreCompact - Before context compaction (save important context)

Common mistake: Using PostToolUse for validation (too late—tool already ran). Use PreToolUse to block operations.

Which Tools Should Trigger This Hook?

Read the full file on GitHub · 969 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 6d ago First seen · 969 lines · 33 tokens per session scan A f290d66b01f6

Subscribe to this mod's changes

claude-hook-writer is a skill published in the GitHub repository pr-pm/prpm (120 stars, last pushed 2mo ago), licensed MIT. It adds 33 tokens to every session and 5,522 once invoked, about $0.0002 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.