Files
MyAiConfiguration/docs/hooks.md
T
Julian LechnerandClaude Opus 5.5 2b2403e1de
CI / CI configuration security checks (push) Successful in 3s
CI / Capabilities and shell quality (push) Successful in 11s
CI / Python tests and compilation (push) Successful in 31s
CI / QMD unit tests (push) Successful in 7s
CI / Build and inspect generated packages (push) Successful in 25s
CI / PowerShell tests on Ubuntu (push) Successful in 2m13s
CI / Installed client configuration smoke tests (push) Successful in 1m15s
CI / Bash integration and installation guards (push) Successful in 1m43s
docs: add Roast Room to README and bring docs up to date
The README now lists Roast Room as a feature and an extension, with its
Git and Node.js requirements. It also fixes the broken %APPDATA%\npm path
and describes the current skill catalog and Codex execpolicy rules.

The docs now match the code: Codex registers PreCompact and SessionStart
hooks, the command-safety hook and execpolicy lists include the new
blocked commands, the media skill has seven references, direct reads need
no research skill, and test-uninstall.py is listed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-20 10:02:46 +01:00

7.6 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 matches Bash and on Windows checks both dialects (-Shell unknown), because Codex reports PowerShell script text as Bash.
Codex and Claude PreToolUse Remind the agent to run semantic-search before the first open search and again after every 10 open searches without it; a no-op unless QMD's qmd-search.mjs is installed. Shell commands are checked inside the command-safety hook process, so each shell call starts one hook process. Claude adds a separate hook for Grep and Glob (Show-SearchReminder/show-search-reminder.sh).
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).
Codex and Claude PreCompact Record the compaction timestamp under the installed configuration root and point to existing workspace task state.
Codex and Claude SessionStart Print an absolute pointer if the workspace's .ai-session/state.json exists.
Codex SessionStart Print the installed Caveman skill (Show-CavemanMode/show-caveman-mode.sh) so caveman style is always on, as the Claude plugin does; CAVEMAN_DEFAULT_MODE=off disables it, and it is a no-op without the skill.
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 repeats after every 10 open searches without qmd-search.mjs, which also covers context lost to compaction, and stays silent while the session keeps using 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, git checkout -- <path> or git checkout ., git restore of working-tree files, git push --force (including -f and +refspec), git stash clear, find -delete, Remove-Item -Recurse (including ri and, outside Bash, the rm/del/rd aliases), del/rd /s /q, and format <drive>:. Heredoc bodies count as text, not commands. 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. Codex gets the same backstop as execpolicy rules in ~/.codex/rules/my-ai-configuration.rules (prefix_rule with decision = "forbidden" for git reset --hard, git clean, git checkout --, git push --force, git push -f, rm -rf, and rm -fr); prefix rules cannot express Remove-Item ... -Recurse. Neither layer catches 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. Codex cannot run a status-line script; its [tui] status_line in the managed config.toml shows the equivalent built-in items (model, reasoning, limits, project, branch, and context use).