manage-hooks

Guidance for hooks, which are automatic actions triggered by coding-agent events such as tool use or the end of a session.

In plain words
What is it for?
Creating, configuring, debugging, and managing command, prompt, and multi-step agent hooks.
Why use it?
It helps automate checks and control what the agent can do without changing the agent’s core code.

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/cfircoo/claude-code-toolkit/create-hooks
Any agent
npx skills add cfircoo/claude-code-toolkit --skill create-hooks
Clone the repo
git clone --depth 1 https://github.com/cfircoo/claude-code-toolkit

Made for: Claude Code, Codex.

Per session 76 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 1,682 The whole file, excluding the scripts and references it only reads on demand.
Security scan D 2 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.00076 $0.01682
Opus 5 $0.00038 $0.00841
Sonnet 5 $0.00015 $0.00336
Haiku 4.5 $0.00008 $0.00168

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

Security

Grade D, and why

manage-hooks scanned grade D with 2 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 2d 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.

Reads agent configuration directoriesmediumAgent snooping

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

- User-global: `~/.claude/settings.json`

Recursive force deletehighDestructive command

rm -rf with a variable or a broad path is one typo away from removing the wrong tree.

| 1, "create", "add", "build", "set up" | "create a hook", "add a PreToolUse hook", "block rm -rf" | workflows/create-hook.md |
skills/create-hooks/SKILL.md · 130 lines

How it starts

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

<essential_principles> Hooks are event-driven automation for Claude Code that execute shell commands, LLM prompts, or multi-turn agents in response to tool usage, session events, and user interactions. They provide deterministic control over Claude's behavior without modifying core code.

1. Three Hook Types:

  • command — shell command, deterministic, fast. Exit 0 = proceed, exit 2 = block. JSON stdout for structured control.
  • prompt — single-turn LLM evaluation (Haiku default). Returns {"ok": true} or {"ok": false, "reason": "..."}.
  • agent — multi-turn subagent with tool access (up to 50 turns). Same ok/reason output. Use when verification needs codebase access.

2. Event → Matcher → Hook — Events (PreToolUse, Stop, etc.) trigger matchers (regex on tool name/context) which fire hooks. See <quick_reference> for the full event table.

3. Configuration Locations (highest priority first):

  • User-global: ~/.claude/settings.json
  • Project shared: .claude/settings.json
  • Project local: .claude/settings.local.json
  • Or use /hooks interactive menu in Claude Code

4. Environment Variables:

Variable Value
$CLAUDE_PROJECT_DIR Project root directory
${CLAUDE_PLUGIN_ROOT} Plugin directory (plugin hooks only)
$ARGUMENTS Hook input JSON (prompt/agent hooks only)
$CLAUDE_ENV_FILE Path for persisting environment variables

5. Safety Essentials:

  • Stop hook loops: Always check stop_hook_active field in Stop/SubagentStop hooks — exit 0 if true
  • Timeouts: Set reasonable values in seconds (default: 10 min commands, 60s agents, 30s prompts)
  • Permissions: chmod +x on script files
  • Path safety: Quote "$CLAUDE_PROJECT_DIR" for spaces
  • Shell profiles: Wrap echo in ~/.zshrc/~/.bashrc with [[ $- == *i* ]] checks — non-interactive shells can corrupt JSON output
  • PermissionRequest: Doesn't fire in headless mode (-p); use PreToolUse instead </essential_principles>
  1. Create a new hook
  2. Debug / fix a hook
  3. Create a toolkit hook (distributable)
  4. Get guidance on hook design

If $ARGUMENTS provides clear intent, skip the menu and route directly.

Intent-based routing (when $ARGUMENTS provides clear intent):

  • "block dangerous commands" → workflows/create-hook.md
  • "my hook isn't triggering" → workflows/debug-hook.md
  • "package for toolkit" → workflows/create-toolkit-hook.md
  • "what event should I use" → workflows/get-guidance.md

After reading the workflow, follow it exactly.

<quick_reference>

Event When it fires Can block? Matcher filters
PreToolUse Before tool execution Yes tool name
PostToolUse After tool succeeds Yes (decision: "block") tool name
PostToolUseFailure After tool fails No tool name
PermissionRequest Permission dialog appears Yes tool name
UserPromptSubmit User submits a prompt Yes no matcher support
Stop Claude finishes responding Yes no matcher support
SubagentStart Subagent is spawned No agent type
SubagentStop Subagent finishes Yes agent type
SessionStart Session begins/resumes No source (startup, resume, clear, compact)
SessionEnd Session terminates No reason (clear, logout, etc.)
PreCompact Before context compaction No trigger (manual, auto)
Notification Claude needs attention No type (permission_prompt, idle_prompt, etc.)
TeammateIdle Agent about to go idle Yes (exit 2) no matcher support
TaskCompleted Task marked complete Yes (exit 2) no matcher support
ConfigChange Config file changes Yes (decision: "block") config type

Read the full file on GitHub · 130 lines

Files

What ships with it

6 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. 2d ago First seen · 130 lines · 0 tokens per session scan D c0547826bab2

Subscribe to this mod's changes

manage-hooks is a skill published in the GitHub repository cfircoo/claude-code-toolkit (17 stars, last pushed 5mo ago), licensed MIT. It adds 76 tokens to every session and 1,682 once invoked, about $0.0004 per session on Opus 5. A static security scan graded it D with 2 findings (reads agent configuration directories, recursive force delete). No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.