claude-code-hooks

claude-code-hooks is a skill for Claude Code, Codex from daymade/claude-code-skills. It costs 247 tokens per session (21,560 once invoked), scanned C, original, MIT.

A guide to Claude Code hooks, which are shell commands that run around tool calls or session events and can allow or block an action.

In plain words
What is it for?
It helps create, test, register, and debug guards for events such as PreToolUse, PostToolUse, SessionStart, and Stop.
Why use it?
It helps enforce rules that written instructions may be ignored, especially before irreversible actions such as deleting files or publishing data.

Skill for Claude CodeCodex

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add skills/daymade/claude-code-skills/claude-code-hooks
Any agent
npx skills add daymade/claude-code-skills --skill claude-code-hooks
Clone the repo
git clone --depth 1 https://github.com/daymade/claude-code-skills

Made for: Claude Code, Codex.

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-code-hooks

README.md
[![agentmods](https://agentmods.dev/badge/skills/daymade/claude-code-skills/claude-code-hooks.svg)](https://agentmods.dev/skills/daymade/claude-code-skills/claude-code-hooks)
Your own site
<a href="https://agentmods.dev/skills/daymade/claude-code-skills/claude-code-hooks"><img src="https://agentmods.dev/badge/skills/daymade/claude-code-skills/claude-code-hooks.svg" alt="Measured on agentmods" height="20"></a>
Per session 247 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 21,560 The whole file, excluding the scripts and references it only reads on demand.
Security scan C 3 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 $0.00247 $0.21560
Opus 5 $0.00123 $0.10780
Sonnet 5 $0.00049 $0.04312
Haiku 4.5 $0.00025 $0.02156

Measured 4d ago against content hash f6e367403e34, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade C, and why

claude-code-hooks scanned grade C with 3 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 4d ago.

The scan reads SKILL.md. This mod also ships 2 executable files (scripts/test_hook.group-name-guard.sh, scripts/test_hook.sh), listed below but not scanned — reading those needs a real analyzer, not pattern matching.

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.

Asks for rootmediumPrivilege escalation

A mod that escalates privileges can change anything on the machine, not only the project.

command position" for `timeout 5 TRIGGER`, `sudo -u root TRIGGER` and

Reads agent configuration directoriesmediumAgent snooping

.claude/, .codex/, .gemini/ hold keys, settings and other credentials a mod has no legitimate need for.

(`~/.claude/settings.json` in this setup; the Registration section of

Makes network callslowCapability

Not a fault in itself. Listed so you know the mod talks to something, and to what.

verifier was required to curl the raw source and grep for the exact string
daymade-claude-code/claude-code-hooks/SKILL.md · 1,240 lines

How it starts

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

Claude Code Hooks

Claude Code fires hooks at tool-call boundaries. A hook is a shell command that receives a JSON event on stdin and, for blocking hooks, decides via its exit code whether the tool call proceeds. This is the only mechanism that structurally stops a behavior — a prose rule in CLAUDE.md is a suggestion the completion drive can override; a hook is a wall.

When a hook is the right tool (and when it isn't)

Write a hook when a rule keeps getting violated even though it's already written down. The tell: you added the prose rule, it read clearly, and the behavior recurred anyway — because at the moment of action, attention is 100% on "get the thing done" and the reminder loses. That recurrence is the signal to move the rule from prose (advisory) to a hook (enforced). Governance rule of thumb: Tier-0 irreversible action + only prose, no hook → it should be a hook. (Tier-0 here = an action whose damage cannot be undone from inside the session: destroying uncommitted work, pushing secrets to a remote, deleting files, publishing something outward. The test is reversibility, not severity.)

Do not reach for a hook when: the rule has never actually recurred (don't pre-build guards for hypothetical mistakes — cost with no proven benefit), or the "rule" is a judgment call with no mechanical signature (a hook can only match tokens/patterns; it can't judge whether a design is good).

If the symptom is “it keeps reviewing / waiting / retrying,” do not assume the answer is another hook. First complete the Loop Contract in rule 7 and read pitfall #36. The loop may be created entirely by an agent repeatedly applying a prose rule.

Hook types and what the exit code means

Type Fires Exit 0 Exit 2 Other
PreToolUse before a tool runs allow block the call (stderr → shown to model as guidance) any other exit = "non-blocking error" → the call proceeds — but only while stdout carries no valid JSON. Claude Code reads JSON output on every exit code, and valid JSON overrides the code entirely. The skeletons here print nothing on stdout, so their fail-open reasoning holds; add a permissionDecision payload and the exit code stops being the decision
PostToolUse after a tool ran quiet unless it prints a hookSpecificOutput JSON on stdout — that is how context injection works, and it happens at exit 0 feedback to the model (can't un-run the tool)
SessionStart session begins proceed cannot block — stderr shows the user a hook-error notice, Claude never sees it, the session starts anyway exit 0 anyway: not because a non-zero would block (it can't), but because anything non-zero puts a <hook> hook error in the user's transcript on every single session start. Takes a matcher on how the session startedstartup, resume, clear, compact, fork
Stop (+ SubagentStop) the model is about to finish responding let it stop block the stop — forces the model to keep going (stderr → fed back as the reason) loop safety: the hook checks stop_hook_active (necessary, not sufficient — rule 7). The harness's consecutive-block ceiling (default 8) is not a general backstop — its counter resets on any continuation that executed tools, so it never arrives for a hook whose remediation involves tool calls, which is most of them (#27). Carry your own bound. All Stop hooks for an event run in parallel — one block round can carry several hooks' feedback

Read the full file on GitHub · 1,240 lines

Files

What ships with it

5 files beside SKILL.md in the same directory: the scripts, references and assets a skill reads on demand. Not counted in the per-session cost; read them before you install if any of them is executable.

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. 4d ago First seen · 1,240 lines · 247 tokens per session scan C f6e367403e34

Subscribe to this mod's changes

claude-code-hooks is a skill published in the GitHub repository daymade/claude-code-skills (1,375 stars, last pushed today), licensed MIT. It adds 247 tokens to every session and 21,560 once invoked, about $0.0012 per session on Opus 5. A static security scan graded it C with 3 findings (asks for root, reads agent configuration directories, makes network calls). No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.

Related

Other skills, from other repositories

systematic-debugging

Use when encountering any bug, test failure, or unexpected behavior, before proposing fixes.

obra/superpowers · 21 tokens

brainstorming

You MUST use this before any creative work - creating features, building components, adding functionality, or modifying behavior. Explores user intent, requirements and design before implementation.

obra/superpowers · 37 tokens

auto-perf-optimize

Run agent-driven VS Code performance or memory investigations. Use when asked to launch Code OSS, automate a VS Code scenario, run the Chat memory smoke runner, capture renderer heap snapshots, take workflow screenshots, compare run summaries, or drive a repeatable scenario before heap-snapshot analysis.

microsoft/vscode · 62 tokens

chat-perf

Run chat perf benchmarks and memory leak checks against the local dev build or any published VS Code version. Use when investigating chat rendering regressions, validating perf-sensitive changes to chat UI, or checking for memory leaks in the chat response pipeline.

microsoft/vscode · 51 tokens

chat-pet-sprite-creation

Use when creating or changing VS Code chat pet sprite art, sprite sheets, state animations, eye treatments, Stable/Insiders variants, or pet transitions under src/vs/workbench/contrib/chat/browser/widget/media/chatPet.

microsoft/vscode · 53 tokens

cpu-profile-analysis

Analyze V8/Chrome CPU profiles (.cpuprofile) and DevTools trace files (Trace-.json). Use when: profiling performance, investigating slow functions, comparing code paths, finding bottlenecks, analyzing timeToRequest, understanding call trees from sampling profiler data, analyzing layout/paint/rendering, investigating…

microsoft/vscode · 71 tokens