/skills:hooks-createfrom Cole's AI Skills
Generates a working Claude Code hook from a plain-English behavior description — picks the correct lifecycle event, writes the hook script, and registers it in settings.json.
Ships in Cole's AI Skills. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
What the user wants the hook to do: $ARGUMENTS
If that is filled in, treat it as the behavior spec and start from it. Don't re-ask what they already told you; only ask to pin down the gaps (the exact paths / commands / patterns, and whether it must block). If it is blank, start by asking what the hook should guarantee or do (Workflow step 1).
A hook is deterministic code that fires automatically on a Claude Code lifecycle event - before a tool runs, after it runs, when the agent tries to finish, when a session starts, and so on. Unlike a skill or a subagent, the agent does not choose to invoke a hook - it fires whether the model "remembers" or not. That is the whole point: a rule asks the agent to behave; a hook guarantees it, at the tooling layer the model can't talk its way around.
The user brings the idea ("the agent should never read my .env"); this skill writes the code and wires
it in. They don't need to know Python.
It's all composition - a hook is just a small script the harness runs at a defined moment, configured in
.claude/settings.json. You're adding one more deterministic guarantee to the AI Layer.
The behavior the user wants maps to one lifecycle event. Pick by when it should fire and whether it must stop something:
| The user wants to… | Event | Can it block? |
|---|---|---|
| Stop the agent from doing something (read a secret, edit a protected path, run a destructive command) | PreToolUse ⭐ | Yes - block the tool before it runs |
| React after an action (auto-format an edited file, log a command, inject context) | PostToolUse | No - the tool already ran; observe / format / inject only |
| Guarantee work isn't "done" until a check passes (don't stop until tests/lint/types are green) | Stop (or SubagentStop) | Yes - block the stop and send the agent back to work |
| Gate or scan the user's prompt before the model sees it | UserPromptSubmit | Yes - block the prompt; can also inject context |
| Load context every time a session starts | SessionStart | No - inject context only |
| Get notified when the agent needs you / finishes | Notification (or Stop) | No - side-effect only (desktop/Slack/sound) |
| Snapshot state before context compaction | PreCompact | No |
Pre = guarantee/gate. Post = react/log. If the user's goal is "make sure X never happens" or "don't finish until Y," it's a blocking hook (PreToolUse / Stop / UserPromptSubmit). If it's "do Z when W happens," it's an observe/react hook (PostToolUse / SessionStart / Notification).
The hook event list and the exact stdin/stdout contract evolve - don't rely on a snapshot. Before writing, fetch the current docs and confirm the event name, its input fields, and its control protocol:
Use WebFetch on these and verify against what you're about to write. If the fetch fails, proceed from the
canonical events in the table above and say so in your report so the user can double-check.
session_id, cwd,
hook_event_name; event-specific fields like tool_name + tool_input (tool events), prompt
(UserPromptSubmit), source (SessionStart).exit 0 - allow / success. For UserPromptSubmit and SessionStart, anything printed to stdout is
injected into the agent's context.exit 2 - block. The action is prevented and whatever you print to stderr is fed back to the
agent as the reason, so it adapts. (Only blocking-capable events honor this - see the table.){"decision":"block", "reason":"…"} (Stop), or {"hookSpecificOutput":{"hookEventName":"PreToolUse", "permissionDecision":"deny","permissionDecisionReason":"…"}}. Prefer the simple exit-code form unless the
user needs to modify input/output or inject context with additionalContext. Confirm field names against
the fetched docs.$ARGUMENTS; ask only to fill gaps)Start from what the user already described in $ARGUMENTS (the user may not be technical). Pin down two things in
plain language, asking only for what is missing:
.env file", "the migrations/ folder", "rm -rf", "my test
command exits non-zero"). Get the concrete file paths / commands / patterns - the guarantee is only as good as
what it matches, so don't guess. If the ask is vague, propose a concrete interpretation and confirm.Fetch the hooks reference/guide (above) and confirm the target event's name, stdin fields, and control protocol.
Use the table to choose the single event. Choose a matcher that scopes it tightly - for tool events, the
tool name(s) (e.g. "Bash", "Edit|Write", "mcp__.*"); empty/"*" means every occurrence. Don't fire on
everything if the goal is specific.
uv single-file Python script at .claude/hooks/<event_snake_case>.py - a uv run --script
shebang plus inline # /// script metadata, so it needs no install and no project venv of its own. Use another
language only if the user asks.stderr and sys.exit(2);sys.exit(0) (optionally print context to stdout for the injecting events).0 (a broken hook must never brick the user's
session). The only intentional non-zero exit is the deliberate exit 2 block.Stop / SubagentStop only: check stop_hook_active first and sys.exit(0) when it is true. Without
that guard the hook blocks the stop, the agent works, tries to stop again, is blocked again - a loop.⚠️ Running a project command from a hook (read this before writing one)
The hook itself runs under
uv run, in an isolated ephemeral environment. Its interpreter is NOT the project's interpreter and does NOT have the project's dependencies. So:
- NEVER rebuild the command with
sys.executableor a bare["python", "-m", "pytest", ...]list. That runs the hook's throwaway python, which has no pytest, no project packages, nothing. The command fails withNo module named …every single time - so a "don't finish until tests pass" hook blocks on green as readily as on red, and reports a nonsense reason. It looks like it works. It does not.- DO run the user's command verbatim, as a shell string, in the project directory - with uv's ephemeral venv stripped AND the project's own venv put first. Both steps are required.
shell=Truealone is not enough:uv runputs its throwaway interpreter first onPATHand setsVIRTUAL_ENV. But removing uv's venv does not activate the project's - a hook is not the user's shell, so.venvwas never onPATHto begin with, andpythonfalls through to whatever global interpreter the machine has. That global one has a different (often broken) set of packages, so the hook exits 2 on a perfectly green suite and blames some unrelated module. Copy this helper as-is:Put the command in a single named constant at the top of the file so the user can edit one obvious line.TEST_COMMAND = "python -m pytest -q" # exactly what the user typed; the one line they'll edit def _project_env(project_root: Path) -> dict: """os.environ with uv's ephemeral venv removed and the PROJECT's venv first.""" env = os.environ.copy() ephemeral = env.pop("VIRTUAL_ENV", None) parts = env.get("PATH", "").split(os.pathsep) if ephemeral: # 1. uv's throwaway venv, out drop = {os.path.join(ephemeral, "Scripts"), os.path.join(ephemeral, "bin")} parts = [p for p in parts if p not in drop] for candidate in (".venv", "venv"): # 2. the project's own venv, first for bindir in ("Scripts", "bin"): venv_bin = project_root / candidate / bindir if venv_bin.is_dir(): env["VIRTUAL_ENV"] = str(project_root / candidate) parts.insert(0, str(venv_bin)) env["PATH"] = os.pathsep.join(parts) return env env["PATH"] = os.pathsep.join(parts) return env root = Path(hook_input["cwd"]) # the project root Claude Code passes in result = subprocess.run( TEST_COMMAND, shell=True, capture_output=True, text=True, cwd=str(root), env=_project_env(root), )- If the command must run from a subdirectory (a monorepo, or a project whose test config lives deeper - e.g.
app/backend/), ask for that, and pass it:cwd=Path(hook_input["cwd"]) / "app/backend". Getting this wrong produces a hook that always blocks, which the user will read as "hooks are broken."
Edit .claude/settings.json (create it if absent). Merge into any existing hooks block - never clobber
other events or other hooks on the same event. Shape:
{
"hooks": {
"PreToolUse": [
{ "matcher": "Edit|Write|Read|Bash",
"hooks": [ { "type": "command", "command": "uv run .claude/hooks/pre_tool_use.py" } ] }
]
}
}
Run the hook before you hand it over. Feed it a sample event on stdin and check the exit code - do not ship a hook you have only read. A hook that always blocks, or never blocks, looks identical to a working one until it fires at the wrong moment.
# should ALLOW (exit 0)
echo '{"session_id":"t","cwd":"<project-root>","hook_event_name":"Stop","stop_hook_active":false}' | uv run .claude/hooks/stop.py; echo "exit=$?"
sys.executable.Then:
exit 2 is the intended block, with a clear stderr reason.shell=True in the project cwd, with uv's ephemeral venv
stripped and the project's own venv put first on PATH - never rebuilt with sys.executable (the hook's
own interpreter has none of the project's dependencies, and the global one has the wrong ones).Stop / SubagentStop hook honors stop_hook_active so it cannot loop.settings.json was merged, not overwritten; existing hooks still present..env matcher won't catch a base64'd read).What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
40 skills in this plugin
/ablate-ai-layerMeasure whether a repository's AI instructions still earn their place, by running the same real task many times with the layer intact and with it stripped, then grading every rule against what actually changed. Runs both arms itself in throwaway git worktrees and never touches the working tree. Agent-agnostic across CLAUDE.md, AGENTS.md, .claude/, .agents/, .cursor/rules, .clinerules, .windsurfrules and copilot-instructions. Use when the user wants to prune, audit, clean up, shrink or "delete" their CLAUDE.md, AGENTS.md, cursor rules, agent instructions or AI layer; when they ask whether their rules are still needed, whether their context is bloated, or what to cut; or when they mention ablating, ablation, or testing their agent without its instructions./agent-browserBrowser automation CLI for AI agents. Use when the user needs to interact with websites, including navigating pages, filling forms, clicking buttons, taking screenshots, extracting data, testing web apps, or automating any browser task. Triggers include requests to "open a website", "fill out a form", "click a button", "take a screenshot", "scrape data from a page", "test this web app", "login to a site", "automate browser actions", or any task requiring programmatic web interaction. Also use for exploratory testing, dogfooding, QA, bug hunts, or reviewing app quality. Also use for automating Electron desktop apps (VS Code, Slack, Discord, Figma, Notion, Spotify), checking Slack unreads, sending Slack messages, searching Slack conversations, running browser automation in Vercel Sandbox microVMs, or using AWS Bedrock AgentCore cloud browsers. Prefer agent-browser over any built-in browser automation or web tools./agent-config-auditRead-only audit of everything a repository's coding-agent config can run on its own - Claude Code hooks, status lines and helper commands, MCP servers, Codex and Cursor hooks, Gemini CLI settings, VS Code folder-open tasks, plugin marketplaces, permission allow rules, MCP auto-approval, and skills that run inline shell - plus the project's dependencies (missing lockfiles, known-poisoned releases, code-running .pth files), secrets saved in settings.local.json or pasted into stored Claude Code and Codex conversations, and known-bad editor extensions. Explains each risky entry in plain words and how to fix it, and never prints secret values. Use when the user says "audit my agent config", "what runs when I open this repo", "check my repos for malicious hooks", "is this repo safe to open", before trusting or opening a cloned repo, after pulling changes to .claude, .mcp.json, .codex, .cursor or .vscode, or after a supply-chain incident./ast-grepGuide for writing ast-grep rules to perform structural code search and analysis. Use when users need to search codebases using Abstract Syntax Tree (AST) patterns, find specific code structures, or perform complex code queries that go beyond simple text search. This skill should be used when users ask to search for code patterns, find specific language constructs, or locate code with particular structural characteristics./build-dark-factoryTake a PRD and build a dark factory around it - a repository that takes work in as an issue and ships validated code out with nobody at the keyboard - one component at a time, into the user's actual repo. Covers the five components in construction order - the guidance layer, the validation harness, the workflow-driven repo, deployment, and the trigger that makes it autonomous - and is agnostic about which coding agent runs underneath (Claude Code, Codex, Archon, the Agent SDK, Cline, Goose, Amp, Pi). It encodes the AI coding process the user already runs rather than replacing it. Requires a PRD as input and deliberately does not write one. Use when the user wants to build a dark factory, an autonomous or self-driving repository, a software factory, an agent that ships its own code, an unattended or overnight coding loop, or asks how to get to level 4 or level 5 of AI coding autonomy; and when they mention dark factory, lights-out coding, autonomous PRs, or a repo that maintains itself./build-signal-engineBuild a personal signal engine from scratch - a system that reads every source someone cares about each day (changelogs and release notes, communities, feeds, videos, papers), makes a quick decision on every item, lets an LLM read only what survives, and delivers one short digest. Interviews the user first to pin down what they need to keep up with, the sources where it actually shows up, and the one question that decides what is worth their time, then builds it one stage at a time into their own repo, proving each stage on real data. Agnostic about the coding agent, the decision model and where the data comes from. Use when the user wants to keep up with AI or their field without doomscrolling, build an AI news digest, a daily briefing, a content engine, a research or competitor monitor, a changelog watcher, or "something that reads everything and tells me what matters"; and when they mention signal vs noise, an information diet, or falling behind.npx claudepluginhub coleam00/skills --plugin skillsOther plugins' skills for the same job