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
Targetrow 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§
- File
Output - A file target’s files for a hook: the authored native hook as written, and the file
generated from
[hooks]. - HookDef
- A
hook.toml. - Hook
Read - What reading a
hook.tomlfound.defisNonewhen a diagnostic is an error. - Merge
Output - One merge target’s events for a hook:
[hooks]rendered, with the native hook’s events replacing the generated ones they name. - Native
Hook - One target’s native hook table.
- Native
Hook Error - Why a native hook’s text is refused. The caller adds the file it came from.
- Output
File - A file a hook installs on a file target.
- Tokens
- The values a hook’s text is substituted with.
Enums§
- Hook
Output - What a hook installs on one target.
- Origin
- Where a
hook.tomlcame 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 Diagnosticcode of ahook.tomlin the removed v0.11.0 schema.- REMOVED_
SCHEMA_ MESSAGE
Functions§
- read
- Read a
hook.toml.dir_namenames the hook when the file does not. - uses_
removed_ schema - Whether
hook.tomltext is in the schema Mars 0.11 removed. Text that is not TOML is not.