Roast Room is installed as a managed Git clone under ~/.my-ai-configuration/roast-room, shared by Claude and Codex. A personal launcher skill runs it from any folder, starts its live room when needed, and only runs when invoked by name (/roast-room, $roast-room). Codex now gets what was Claude-only before: the Caveman skill with a SessionStart hook that keeps it on, PreCompact and session-pointer hooks, execpolicy deny rules mirroring Claude's permissions.deny, and Impeccable's custom agents registered in ~/.codex/agents. The command-safety hook checks both shell dialects for Codex on Windows, where PowerShell text arrives as Bash, in both the PowerShell and Bash packages. Audit fixes: - command-safety blocks git checkout -- / restore / push --force / stash clear and find -delete, and treats heredoc bodies as text - removing a clone clears read-only Git files, git errors no longer abort the extension sync, and a lock left by a dead process is replaced - with-credential passes child flags such as -k or -d through unchanged and resolves commands from PATH - uninstall strips only owned hooks from settings.json and config.toml and keeps the selection while another client is installed; update keeps CLAUDE_CODE_MAX_TOOL_USE_CONCURRENCY; Bash merges write the same bytes as PowerShell - qmd no longer trusts a stale daemon.json after a lost start race and prunes collections of deleted repositories - Bash scripts avoid GNU-only find -printf Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
38 lines
7.3 KiB
Markdown
38 lines
7.3 KiB
Markdown
# 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 (`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`). |
|
|
| 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](configuration.md#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. 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`, `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).
|