Skip to content
suit Hooks
Login

Hooks

A harness runs hooks: programs it starts at events such as Stop or PreToolUse, passing a JSON document on standard input and reading the exit status, standard output and standard error. Suit tells the harness once, by a need, to call one fixed command for an event. After that, which programs run is decided by what suit has linked into slots.

The fixed command is suit-run hook EVENT, the dispatcher. It lives in the small front program, not in suit, because a hook can run on every tool call and must start fast (see decisions.md). suit hook EVENT in the big program calls the same code, for convenience and testing.

Layout

An outfit says slot hook/EVENT = PATH for one program, or slot hook/EVENT/NAME = PATH for several. suit apply links them at $SUIT_HOME/slots/hook/EVENT and $SUIT_HOME/slots/hook/EVENT/NAME. For one event, the slot is a link to one program or a folder of links, never both. If the outfits that apply need both for one event, suit plan and suit apply stop with an error naming both outfits. Nested slot names needed no code change in placement; they are tested in test/place.sh.

Rules

Exit status

Result Dispatcher exits
No slot, or every program exits 0 0
A program exits 2 2, at once; no later program runs
No 2, but some program exits non-zero the first non-zero status
A program killed by a signal counts as 128 plus the signal
A program cannot be started counts as 126
Bad EVENT 64
Input over 16 MiB 65

Exit 2 means "block" in the harnesses that have blocking hooks, so nothing after a block runs.

Register once in a harness

The wardrobe holds needs/claude-stop-hook.md:

Open ~/.claude/settings.json and add to "hooks" an entry for "Stop" whose
command is "suit-run hook Stop". Keep every other setting as it is.

and the config says:

[need claude stop-hook]
prompt = needs/claude-stop-hook.md
done = ~/.claude/settings.json contains "suit-run hook Stop"

After that, slot hook/Stop/announce = files/tts/announce.sh in an outfit is all it takes to run a program at Stop. suit hooks lists, one line per event and program in order, EVENT NAME -> TARGET, with (missing) or (not executable) where true. It changes nothing.

Speed

With no slot present, suit-run hook NOSUCHEVENT is checked by make check-budget in the same way as the no-change run: the median of per-round differences over the empty program must be under 1 ms. Measured on the development machine: 0.15 to 0.29 ms (the no-change run: 0.47 to 0.83 ms). suit-run grew from 35,064 to 35,512 bytes stripped.

Limits