Add a PreToolUse hook (Show-SearchReminder/show-search-reminder.sh via agent-guards.py) that, once per session, reminds the agent to run semantic-search before the first open search. It fires on Grep/Glob and on shell search commands, never blocks, stays silent once the session ran qmd-search.mjs, and does nothing unless QMD is installed. Per-session markers are hashed and pruned after seven days. Claude matches Grep|Glob|Bash|PowerShell; Codex matches Bash. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
6.4 KiB
Hooks
Hook scripts and optional utilities live in shared/hooks/scripts/. The flashbang entry points live directly in shared/hooks/. Shipping a script does not automatically register it as a hook.
The adapters register these events:
| Client | Event | Action |
|---|---|---|
| Codex and Claude | PreToolUse |
Block clearly destructive shell commands (Validate-CommandSafety/validate-command-safety.sh); Claude matches the Bash and PowerShell tools. |
| Codex and Claude | PreToolUse |
Once per session, remind the agent to run semantic-search before the first open search (Show-SearchReminder/show-search-reminder.sh); a no-op unless QMD's qmd-search.mjs is installed. Claude matches Grep, Glob, Bash, and PowerShell; Codex matches Bash. |
| Codex and Claude | Stop |
Run the finish notification (flashbang). |
| Codex and Claude | Stop |
Push back once on an unbacked completion claim (Check-CompletionEvidence/check-completion-evidence.sh). |
| Codex and Claude | UserPromptSubmit |
Ask the agent to propose a durable rule when a prompt looks like a correction (Show-CorrectionPrompt/show-correction-prompt.sh). |
| Claude | PreCompact |
Record the compaction timestamp under the installed configuration root and point to existing workspace task state. |
| Claude | SessionStart |
Print an absolute pointer if the workspace's .ai-session/state.json exists. |
| Codex and Claude | SessionStart |
Warm the QMD index and search daemon in the background (only while local QMD search is enabled). |
The main agent alone maintains canonical task state. Hooks never write or summarize it, print its contents, or infer completed verification. The task-state hooks use the hook event's cwd, falling back to the process working directory when no workspace is supplied. Malformed event data does not fall back to another project. An absent state file is a successful no-op. Legacy state under the installed configuration root is not automatically adopted; confirm its task before migrating it. The scripts do not grant permissions, bypass approvals, or replace client permission systems.
The search reminder never blocks a tool call. It fires on Grep/Glob or on shell commands that look like searches (rg, grep, find, fd, git grep, Select-String, recursive Get-ChildItem). It stays silent for the rest of the session once it has fired or once the session ran qmd-search.mjs. It matches command text, so wrapped or aliased searches can slip through. Per-session markers are hashed session IDs under ~/.my-ai-configuration/state/search-reminder/; markers older than seven days are pruned.
The QMD warm-up hook uses the process working directory and starts only inside a Git repository when Node.js and the installed wrapper are available. It runs detached; wrapper errors are recorded in ~/.my-ai-configuration/qmd/warm.log. Disabling local search removes its hook registration. See Local QMD search for daemon behavior and storage.
When enabled during installation or update, Flashbang runs on Stop, after the main agent finishes responding. The default flash lasts about 500 milliseconds. The PowerShell command omits -WindowStyle Hidden, which can hide or minimize the shared terminal. The PowerShell hook creates a low-opacity click-through overlay without activating another window when its native GUI APIs are available; unsupported runtimes exit safely. Its native DLL cache is optional: a missing LOCALAPPDATA environment variable or an unusable cache falls back to in-process compilation instead of suppressing the notification. The Bash hook uses Python's tkinter, uses xrandr for multi-monitor bounds when available, and falls back to notify-send when the overlay is unavailable. Registered hooks are best effort: errors do not fail a Claude session.
The completion hook blocks a stop only when the last message claims completion, names no check, and the Git working tree has non-prose changes. It uses the message wording, not command output, so it is a nudge rather than proof, and it never blocks twice in a row. The correction hook matches German and English phrases, adds a fixed instruction, and stores nothing; it skips slash commands and prompts over 2,000 characters. Rules change only after user approval. Both hooks need Python and fail open. Codex skips new or changed hooks until they are trusted through /hooks.
The command-safety hook parses the command (quote-aware splitting on ;, &&, ||, |, and newlines; nested bash -c, pwsh -Command, cmd /c, and eval) and exits 2 with a reason for rm with recursive and force flags in any order, git reset --hard, git clean -f, Remove-Item -Recurse (including ri and, outside Bash, the rm/del/rd aliases), del/rd /s /q, and format <drive>:. The logic lives once in command-safety.py; the shell wrappers only resolve Python. Called with a command argument (-Command/first argument), the wrappers check that command and also reject absolute paths outside the workspace. Like the client deny rules, the hook is a guard rail against accidents, not a security boundary: it sees only command text, not what scripts, aliases, or variables expand to, and it fails open on unparsable input or missing Python.
The Claude permissions.deny patterns (Bash(rm -rf*), PowerShell(Remove-Item *-Recurse*), and the git reset --hard/git clean patterns) match only the literal command prefix. They do not catch rm -fr, rm -r -f, or a destructive command after cd x &&; the PreToolUse hook covers those variants. Treat both layers as hurdles, and rely on the sandbox, approvals, and version control for real protection.
Invoke-PostChangeVerification/invoke-post-change-verification.sh is an unregistered utility that explicitly runs the repository build when invoked; it is not an automatic requirement after each change.
All Python-based hooks find their interpreter through Resolve-Python.ps1/resolve-python.sh, which skip PATH entries that cannot run Python 3.11+ (such as the Windows Store alias). Without Python these hooks are skipped silently; doctor reports that case as a failure.
Test-SessionConfig/test-session-config.sh checks required repository inputs and is called by the build. Build and doctor do not execute the registered notification or session-state hooks. Claude's status line is a separate statusLine command, not a hook event.