Hook bash, follow-up prompts, and PI UI actions onto tool calls and session events from one hooks.yaml file. This directory is the full reference; the top-level README covers install and a 60-second tour.
setup.md: install the extension, choose hook file locations, trust project hooks, and read the canonical environment-variable tablehooks-reference.md: exact hook fields, events, conditions, actions, and PI-specific behavioragent-authoring-guide.md: practical rules for people and agents writinghooks.yamldebugging-hooks.md: persistent hook logs, tailing, and debugging workflowexamples/: copy-paste examples for each major capabilitymaintaining.md: maintainer-only SDK matrix and runtime smoke checklist
- Run
bashbefore or after tool calls - Block pre-tool calls from
bashhooks with exit code2 - Ask for user confirmation before a tool runs
- Show UI notifications and status-bar entries when PI has a UI surface
- Send follow-up prompts back into the current PI session with
tool:actions - React to session lifecycle events:
session.created,session.idle, andsession.deleted - React to
file.changed, which PI synthesizes after recognized file mutations, includingcp/git cp,mv/git mv,rm/git rm,touch, andmkdir - Filter hooks by file extension or glob patterns, including post-tool mutation hooks with changed paths
- Restrict hooks to
all,main, orchildsessions - Queue selected hooks asynchronously so they do not block the agent turn
- Layer one global root hook file and one trusted project root hook file, with gated imports and id-based replacement or disable behavior
These are the details that matter most when authoring hooks:
- The documented support range is
@earendil-works/pi-coding-agent ^0.74.0. - Only one global root config and one project root config are discovered.
- Project-root imports require project trust. Global-root imports require
PI_YAML_HOOKS_ALLOW_GLOBAL_IMPORTS=1; package imports requirePI_YAML_HOOKS_ALLOW_PACKAGE_IMPORTS=1; project imports outside the trust anchor requirePI_YAML_HOOKS_ALLOW_PROJECT_IMPORTS_OUTSIDE_TRUST_ANCHOR=1. - Later files stay compatible with the same explicit
override:/disable:behavior byid. - Project hook files are ignored until the repo or worktree trust anchor is trusted.
command:actions are rejected at load time on PI.tool:does not imperatively invoke a tool; it sends a follow-up prompt to the current session.confirm:blocks only ontool.before.*hooks.session.deletedis best-effort and intentionally lossy: PI fires it for shutdown and for session switches like/new,/resume, and/fork;pi-yaml-hooksforwards PI'sreason(quit,reload,new,resume, orfork) on the envelope so hooks can disambiguate.file.changedis synthesized from recognized mutation tools. On stock PI that meanswrite,edit, and somebashcommands such ascp,mv,rm,touch, andmkdir.- Type-only consumers can
import type { HookConfig, HookEvent, BashHookContext, SessionDeletedReason } from "pi-yaml-hooks/types". The subpath ships only types; runtime imports go throughpi-yaml-hooks.
This is the canonical reading order. The top-level README links here.
If you are new to the project:
- Read
setup.md - Skim
hooks-reference.md - Copy from
examples/ - Keep
agent-authoring-guide.mdopen while writing new hooks
If you are releasing or widening SDK support, also work through maintaining.md.