Skip to main content

Module hooks

Module hooks 

Source
Expand description

The hook.toml definition and every per-target hook rule.

A hook is written once as Claude’s hooks JSON in TOML ([hooks], see portable), a native hook per target ([targets]), or both. This module owns what is authored (HookDef) and which targets receive it (HookDef::select); read turns text into a HookDef, output says what it installs on one target, targets is the per-target table and render turns a [hooks] table into a profile’s entries. Nothing here touches the filesystem: the caller reads the bytes and places the result, and adds the location (a path, or a package and version) to the path-free diagnostics.

Modules§

portable
The portable [hooks] table: Claude’s "hooks" object, written as TOML.
render
A portable hook rendered for one target: finished entries per event, and what was left out. Renderers emit only what the target’s parser accepts; they never pass Claude’s JSON through blindly.
targets
What each target root takes of a hook: one Target row per root, holding where its hooks are placed (the merge file and its trust gate, or the file directory), the events it accepts, the harness version that table was last checked against, how [hooks] is rendered for it (for a TypeScript harness, its glue, limits and native hook contract), and what its generated files are called. A new target is one row here; the binary only places what the row describes. Nothing about a target is kept anywhere else.

Structs§

FileOutput
A file target’s files for a hook: the authored native hook as written, and the file generated from [hooks].
HookDef
A hook.toml.
HookRead
What reading a hook.toml found. def is None when a diagnostic is an error.
MergeOutput
One merge target’s events for a hook: [hooks] rendered, with the native hook’s events replacing the generated ones they name.
NativeHook
One target’s native hook table.
NativeHookError
Why a native hook’s text is refused. The caller adds the file it came from.
OutputFile
A file a hook installs on a file target.
Tokens
The values a hook’s text is substituted with.

Enums§

HookOutput
What a hook installs on one target.
Origin
Where a hook.toml came from. The project’s own is strict. A dependency’s is lenient where one author’s slip should not stop a sync: an unknown top-level key is ignored and a merge native hook’s unknown event is skipped, each with a warning.

Constants§

HOOK_DIR_TOKEN
The authored placeholder for the directory a hook’s files are installed in.
HOOK_TARGET_TOKEN
The authored placeholder for the target a hook is installed for.
REMOVED_SCHEMA_CODE
Diagnostic code of a hook.toml in the removed v0.11.0 schema.
REMOVED_SCHEMA_MESSAGE

Functions§

read
Read a hook.toml. dir_name names the hook when the file does not.
uses_removed_schema
Whether hook.toml text is in the schema Mars 0.11 removed. Text that is not TOML is not.