> ## Documentation Index
> Fetch the complete documentation index at: https://docs.actual.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Hooks

> The hook events the plugin registers in Claude Code and Codex, the Actual CLI command each one runs, and how every one of them fails open.

The plugin works through hooks: Claude Code and Codex call a plugin script at fixed points in a session, and each script hands the moment to the Actual CLI. The plugin registers 7 hook events in Claude Code and 5 in Codex, and adds a mod in Claude Code. Every hook does nothing in a repository without rule files in `.actual/rules/` (or the directory `ACTUAL_RULES_DIR` names), so installing the plugin changes nothing in a repository Actual doesn't govern. The one exception is the plan-approval hook once you turn on unattended mode.

```mermaid theme={null}
flowchart LR
  A[Session starts] -->|SessionStart| B[CLI version check]
  B --> C[You send a prompt]
  C -->|UserPromptSubmit| D[Turn's start commit recorded]
  D --> E[Agent reads files]
  E -->|PostToolUse Read| F[Rules briefed]
  F --> G[Agent leaves plan mode]
  G -->|PreToolUse ExitPlanMode| H[Plan checked]
  H --> I[Agent edits]
  I -->|Stop| J[Changes checked]
```

## Claude Code

| Event | Matcher | Script | What it does for you | Actual CLI command |
| - | - | - | - | - |
| `SessionStart` | `startup`, `resume`, `clear`, `compact`, `fork` | `preflight.sh` | Tells the agent governance is active and how many rule files it found. Offers to install a missing CLI, to upgrade one older than 0.8.0 with the command for however it was installed, and to upgrade one older than 0.9.0 when your rule files carry a YAML header. Never installs anything itself. | `actual --version`, `actual version --json` |
| `UserPromptSubmit` | every prompt | `turn-start.sh` | Records the commit each turn starts from, so the change check at the end of the turn also sees work the agent committed during it. Silent; needs CLI 0.7.0 or later. | `actual impl-check --claude-hook` |
| `PreToolUse` | `ExitPlanMode` | `plan-gate.sh` | Checks the plan when the agent leaves plan mode, before your approval dialog. A conflict denies the call and sends the agent back to revise; where the mod loads, you're asked first whether to revise or override. | `actual plan-check --claude-hook` |
| `PreToolUse` | `Edit`, `Write` | `rules-brief.sh` | Briefs the rules for a file written without being read first, usually a new one. The brief arrives with the result, after the write, as a reminder. | `actual rules brief --claude-hook` |
| `PreToolUse` | `Bash` | `report-use-allow.sh` | Lets the agent run `actual rules report-use` with only its own flags, for this session and repository, without a permission prompt. Any other command goes through Claude Code's usual permission flow. | none |
| `PermissionRequest` | `ExitPlanMode` | `plan-approval.sh` | With unattended mode on, approves a plan the check passed or couldn't check, so nobody has to answer the plan dialog. Silent otherwise. | none |
| `PostToolUse` | `Read` | `rules-brief.sh` | Briefs the rules governing a file the agent read, before its first edit. Stands down where the mod loads, since the mod briefs reads itself. | `actual rules brief --claude-hook` |
| `Stop` | every turn | `impl-gate.sh` | Checks the turn's changes: tracked edits plus new files git doesn't ignore, against the commit the turn started from. A conflict sends the agent back to fix it; where the mod loads, you're asked first. After a turn that changed files, and only while telemetry is on, it also asks the agent which decisions it used. | `actual impl-check --claude-hook` |
| `SessionEnd` | every end | `session-end.sh` | Hands the session's end to the CLI, which queues the session-end telemetry event and starts its uploader. No install, version check or network wait. | an internal CLI command |

The plan check and the change check each have 180 seconds, and show a status line while they judge, such as "Checking plan against architecture rules...".

## Codex

Codex runs a plugin's hooks only after you trust them: open `/hooks` in the CLI, or **Settings → Hooks** in the app, review the plugin's hooks and trust them. Codex records that trust against the plugin's content, so after each update the hooks stay off until you review them again. Every Codex hook needs CLI 0.15.0 or later, which `actual plan-check --help` shows by naming `codex-hook`.

| Event | Matcher | Script | What it does for you | Actual CLI command |
| - | - | - | - | - |
| `SessionStart` | `startup`, `resume`, `clear`, `compact`, `fork` | `preflight.sh` | Tells the agent governance is active, or offers the install or upgrade a missing or too-old CLI needs. After a compact or clear, resets what the session was briefed, so the next read briefs again. | `actual rules brief --codex-session-start` |
| `UserPromptSubmit` | every prompt | `turn-start.sh` | Records the commit the turn starts from. After a conflict ended the last turn, hands the conflicts to the agent with your reply, or records a typed `actual override` and keeps that message from the agent. | `actual impl-check --codex-hook` |
| `PreToolUse` | `Edit`, `Write` (the names Codex matches `apply_patch` by) | `rules-brief.sh` | Briefs the files a patch adds or updates, before it applies, and shows you one line naming what the brief carried. | `actual rules brief --codex-hook` |
| `PostToolUse` | `Bash` | `rules-brief.sh` | Briefs the files a read-only shell command reads, such as `cat`, `head`, `sed -n`, `grep` or `rg`. | `actual rules brief --codex-hook` |
| `PostToolUse` | `request_user_input` | `gate-answer.sh` | Records your answer when a check's picker asks whether to revise or override, and why. | `actual impl-check --codex-hook` |
| `Stop` | every turn | `plan-gate.sh` | Checks the plan a Plan-mode turn proposed, once the turn ends. A conflict ends the turn and asks you, or sends the agent back in an unattended run. | `actual plan-check --codex-hook` |
| `Stop` | every turn | `impl-gate.sh` | Checks the turn's changes, and tells you when the CLI is missing, unreadable or too old. | `actual impl-check --codex-hook` |
| `Stop` | every turn | `session-summary.sh` | Shows the session summary line when it has changed since it was last shown. | `actual session summary --codex-hook` |

Codex has no session-end hook, so a Codex session sends no session-end event. [Codex](https://docs.actual.ai/guides/codex.md) covers what governance looks like there.

## The Claude Code mod

Beside its hooks, the plugin loads a mod in Claude Code (`hooks/register.js`, with the override dialog in `hooks/override-dialog.js`). It needs Claude Code 2.1.287 or later; on 2.1.285 and 2.1.286, set `CLAUDE_CODE_ENABLE_FUNCTION_HOOKS=1` to load it. Where it loads, it:

* **Briefs every read.** It briefs reads through the Read tool and through shell commands Claude Code marks read-only, and an edit or write of a file never read. Briefing shares one budget (48,000 characters per session by default) and one record of what the agent has already been told, so a file read twice is briefed once.
* **Reports each brief.** Each read of a governed file adds one line to the transcript, such as `actual-cli: ▌ BRIEFED    2 ADRs · 8 of 35 rules    tokens.ts`. The model never reads these lines. `/rules-brief` opens a pane listing the session's reads.
* **Shows the session summary.** A row above the prompt counts the decisions added to the agent's context and the folders it worked in that no decision covers.
* **Asks you about a denial.** When a check denies, it asks whether to revise or override, and records the override you choose. It also records a typed `/actual-cli:override`. See [Overrides](https://docs.actual.ai/guides/overrides.md).

Without the mod, the `Read` hook still briefs reads through the Read tool, with no cap and no transcript line, and you record an override with `actual check-override` from a terminal.

## Fail-open behavior

Only an explicit deny from `plan-check` or `impl-check` can block. Everything else lets the plan or the turn through:

* **No rule files.** Every hook exits silently.
* **The CLI is missing, too old, unreadable or crashes.** You get a message, never a block.
* **No runner, a failed judge call, or no plan or diff to read.** A notice says the work wasn't checked.
* **Too many rules for one check.** Past about 60 selected rules, a prioritized part of them is judged, and the notice says how many of how many were checked.
* **A rule that stays unresolved.** It stops blocking after 3 denied rounds per session. `ACTUAL_PLAN_CHECK_MAX_ROUNDS` and `ACTUAL_IMPL_CHECK_MAX_ROUNDS` change the limit; see [Environment variables](https://docs.actual.ai/cli/environment-variables.md).
* **Briefing.** It never blocks anything.
* **The CLI's own judge.** Every hook and the mod stay silent inside the `claude` subprocess the CLI runs as its judge, which it marks with `ACTUAL_CLI_SUBPROCESS=1`.

Round-limit passes and overrides are logged in `~/.actualai/actual/plan-check-overrides.log`. Treat a denial as a strong nudge with a record behind it, not a security control.

To turn every hook off, set `ACTUAL_PLAN_GATE=off`. [Settings](https://docs.actual.ai/plugin/settings.md) lists that switch and the others.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.