← Portal ↑ Claude Artifacts

🪝 Hooks

The scripts the AI tools run on their own at fixed moments, which repo ships each one, and which tools run the safety guard
Generated from claude-shared@79653f3 2026-11-22 · claude-admin@3e5c95c 2026-11-11 · claude-dev@2ac6a94 2026-11-11
12
Registrations
9
Scripts
8
Events used
4
Can block
4
Tools given the guard

What a hook is

A hook is a script the AI tool runs by itself at a fixed moment: when a session starts, when you submit a prompt, before every shell command, when Claude finishes a reply. Claude does not decide whether it runs.

That is the difference from a skill. A skill is instructions Claude follows when they fit; a hook runs every time its moment comes. A hook can stay silent, add a note for Claude to read, write a file, or block the action, in which case Claude is shown the reason.

Hooks by repo

Each repo is a Claude Code plugin, and Claude Code loads the plugin's hooks/hooks.json when a session starts. Everyone has claude-shared; administrators also have claude-admin, developers claude-dev (why three repos).

claude-shared
for everyone · 12 registrations

12 registrations of 9 scripts across 8 events. They run for everyone, in Claude Code.

context-save-check.sh context-save-on-prompt.sh context-save-wip-pretooluse.sh context-save-wip-resume.sh destructive-guard.sh notification-logger.sh session-end.sh session-start.sh validate-decision-card.sh
claude-admin
for administrators · 0 registrations

Ships no hooks. A hook registered in this repo's hooks/hooks.json would run only for administrators, and only in Claude Code.

claude-dev
for developers · 0 registrations

Ships no hooks. A hook registered in this repo's hooks/hooks.json would run only for developers, and only in Claude Code.

When each hook runs

In the order a session meets them. Runs on narrows a hook to some tools; every time means whenever the event fires.

SessionStartA session opens or resumes.
claude-shared/skills/refocus/hooks/session-start.sh
runs on: every time
adds a note

Marks a session started by /refocus as a child, which may not start refocus sessions of its own, and lists incoming briefs and finished results waiting to be picked up.

claude-shared/hooks/context-save-wip-resume.sh
runs on: every time
adds a note

If an earlier session left a work-in-progress snapshot, tells the new session to read it first. Leaves deleting it to Claude, once the contents are saved properly.

UserPromptSubmitYou press Enter on a prompt, before Claude reads it.
claude-shared/hooks/context-save-on-prompt.sh
runs on: every time
can block adds a note

When you type /clear, /compact, /exit or /quit, checks for work that would be lost. With more than 15 changed lines of code and nothing new in docs/context/ it blocks the command and lists what to save; otherwise it lets the command through with the same checklist. A fresh work-in-progress snapshot counts as saved.

PreToolUseClaude is about to run a tool, such as a shell command or a file edit.
claude-shared/hooks/destructive-guard.sh
runs on: shell commands, file edits, file writes, notebook edits
can block

The safety guard. Stops shell commands and file edits that cross the autonomous-mode boundary: anything under projects/data or projects/gitlab (except projects/gitlab/docs), destructive database commands, removing datastore volumes, rewriting git history or force-pushing main, and deleting files outside the project. Claude is shown the reason and has to ask you before trying again.

claude-shared/hooks/context-save-wip-pretooluse.sh
runs on: shell commands, file edits, file writes, notebook edits
writes a file never blocks

During a long turn, refreshes the work-in-progress snapshot (wip.md beside the session transcript) once the transcript has grown enough and context is filling up, so something survives if the session runs out mid-turn. Silent.

claude-shared/hooks/validate-decision-card.sh
runs on: shell commands
can block

When a shell command creates a GitLab DECISION card, checks that its options are "- [ ]" checkboxes the owner can tick, and blocks the command when they are prose or a table.

NotificationClaude Code shows you a notification, for example while it waits for your permission.
claude-shared/hooks/notification-logger.sh
runs on: every time
writes a file never blocks

Appends each notification as one JSON line to ~/.claude/notifications/<session>.jsonl. No network, never blocks.

StopClaude finishes its reply.
claude-shared/hooks/context-save-check.sh
runs on: every time
can block adds a note writes a file

Reminds Claude to record decisions in docs/context/. When more than 15 lines of code changed, nothing was saved and context pressure is high, it asks to block the stop so Claude saves first. From medium pressure it also writes the work-in-progress snapshot. Thresholds: Context Save page.

SubagentStopA sub-agent finishes its task.
claude-shared/hooks/context-save-check.sh
runs on: every time
can block adds a note writes a file

Reminds Claude to record decisions in docs/context/. When more than 15 lines of code changed, nothing was saved and context pressure is high, it asks to block the stop so Claude saves first. From medium pressure it also writes the work-in-progress snapshot. Thresholds: Context Save page.

PreCompactThe conversation is about to be compacted to free up context.
claude-shared/hooks/context-save-check.sh
runs on: every time
can block adds a note writes a file

Reminds Claude to record decisions in docs/context/. When more than 15 lines of code changed, nothing was saved and context pressure is high, it asks to block the stop so Claude saves first. From medium pressure it also writes the work-in-progress snapshot. Thresholds: Context Save page.

SessionEndThe session closes.
claude-shared/hooks/context-save-check.sh
runs on: every time
can block adds a note writes a file

Reminds Claude to record decisions in docs/context/. When more than 15 lines of code changed, nothing was saved and context pressure is high, it asks to block the stop so Claude saves first. From medium pressure it also writes the work-in-progress snapshot. Thresholds: Context Save page.

claude-shared/skills/refocus/hooks/session-end.sh
runs on: every time
adds a note

Warns when a /refocus child session exits without /refocus-complete, so the unfinished brief is noticed on the next resume. Changes nothing.

The context-save hooks share one idea: decisions should reach docs/context/ before a session forgets them. Thresholds, the snapshot and how a manual save works: Context Save.

One guard, every tool

Only the safety guard reaches beyond Claude Code. Other tools cannot read a plugin's hooks.json, so setup.py writes each one's own hooks file, pointing at the same destructive-guard.sh. The script translates each tool's tool names into one policy and answers in the form that tool understands. Every other hook on this page runs in Claude Code only.

ToolRegistration written by setup.pyEvent · matcherHow it blocksNotes
Antigravity~/.gemini/config/hooks.jsonPreToolUse · * JSON {decision, reason} on stdout, nothing else—
Claude Code~/.claude/settings.jsonPreToolUse · Bash|Edit|Write|NotebookEdit exit 2, reason on stderrregisters a real copy at ~/.claude/hooks/destructive-guard.sh, in addition to the plugin's own registration
Codex~/.codex/hooks.jsonPreToolUse · .* exit 2, reason on stderrCodex runs the hook only once it is trusted; setup.py records that trust
Gemini CLI~/.gemini/settings.jsonBeforeTool · .* JSON decision deny on stdoutGemini CLI is no longer installed on linuxserver.lan; the adapter stays for machines that have it
OpenCodeNo hook support in its adapter, so the guard does not run there.
A hooks file is not proof the guard runs: a tool can skip an untrusted or disabled hook. setup.py --status reports each tool's registration as registered and trusted, or untrusted, disabled, stale or missing. MCP tool calls are not covered; the MCP server's own access control applies there.

Present but not running

A script runs only if a hooks.json names it. These are kept so they can be turned back on.

claude-shared/hooks/agent-memory-inbox.sh
dormant

Would remind you at session start of unresolved agent-memory items. Unregistered since 2026-08-01; hooks/README.md says why and what to fix before turning it back on.

Tests

Change a hook, run its suite first; the guard's suite covers every tool's envelope.

~/projects/claude-skills/claude-shared/hooks/test-context-save-wip.sh
~/projects/claude-skills/claude-shared/hooks/test-destructive-guard.sh

Hooks from outside these repos

Your own ~/.claude/settings.json, and other projects, can register more hooks (the Phoenix tracing hooks are one example). They are not part of these repos and are not listed here. In Claude Code, /hooks shows everything that is loaded.

Adding or changing a hook

  1. Pick the repo by who it should run for: everyone → claude-shared, administrators → claude-admin, developers → claude-dev.
  2. Put the script in that repo's hooks/, make it executable, and register it in hooks/hooks.json as ${CLAUDE_PLUGIN_ROOT}/hooks/<script>.
  3. Run its tests, commit, and start a new session: hooks load when a session starts.
  4. Add one sentence for it to HOOKS in scripts/hooks_catalog.py and regenerate this page. The generator refuses to run until every registered script is described.

How this page is made

Generated from each repo's hooks/hooks.json, the scripts in hooks/ and the hooks_ensure entries in claude-shared/adapters/. Never edit it by hand:

cd ~/projects/claude-skills/claude-shared
python3 scripts/hooks_catalog.py --publish ~/projects/nginx/sites/claude-artifacts          # regenerate and publish
python3 scripts/hooks_catalog.py --check --publish ~/projects/nginx/sites/claude-artifacts  # exits 1 if stale