Hooks
Hooks run at six points of the loop: shell commands from hooks in config, and plugin handlers registered with oi.on(event, fn). Plugin hooks run first, then shell hooks in config order.
| Event | When | Answer |
|---|---|---|
session_start |
the first turn of a session in this process | context |
user_prompt |
before the model sees a message | block, context |
before_tool |
before the permission check | deny, input (a rewritten input) |
after_tool |
after a tool ran, before the model sees its result | content (replace), append |
stop |
an agent is about to end its turn | continue (feedback; the agent keeps working, at most 8 times a turn) |
notification |
an approval waits; a turn ended | ignored |
{ "hooks": {
"after_tool": [{ "matcher": "write|edit", "command": "zig fmt \"$OI_FILE\"" }],
"stop": [{ "command": "zig build test >/dev/null 2>&1 || { echo 'the tests fail: fix them' >&2; exit 2; }", "timeout_ms": 300000 }],
"notification": [{ "command": "notify-send oi \"$OI_MESSAGE\"" }] } }- Input. A shell hook gets the event as JSON on stdin, plus
OI_HOOK_EVENT,OI_SESSION_ID,OI_TOOL_NAME,OI_FILEandOI_MESSAGEin its environment.matcheris a regex that must match the whole tool name. - Exit status.
0succeeds. A JSON object on stdout is the hook's answer; forsession_startanduser_prompt, plain text on stdout becomescontext.2speaks with stderr: it denies the tool, blocks the prompt, appends to the tool result (after_tool), or sends the agent back to work (stop).- Anything else is reported and ignored.
- Plugins. A plugin hook returns the same fields.
- Sandbox and trust. Shell hooks run in the OS sandbox like
bash; stdin is written while the output drains, andtimeout_ms(default 60 s) kills a hook that hangs. Hooks from your own files (~/.config/oi/config.json,projects.json) run as configured. Hooks from a repository's shared.oi/config.jsonrun only after you approve them ("always" saves ahook(<command>)rule), or when one of your ownhook(...)rules or anautomode you chose (flag, your config, Shift+Tab) allows them. The repository's own rules andpermission_modenever approve its hooks.