doc/plans/2026-04-07-pi-hooks-survey.md
Status: investigation note Date: 2026-04-07
We were asked to find the hook surfaces exposed by pi and pi-mono, then decide which ideas transfer cleanly into Paperclip.
This note is based on direct source inspection of:
badlogic/pi default branch and pi2 branchbadlogic/pi-mono packages/coding-agentpi does not expose a comparable extension hook API. What it exposes today is a JSON event stream from pi-agent.pi-mono does expose a real extension hook system. It is broad, typed, and intentionally allows mutation of agent/runtime behavior.pi has todayCurrent badlogic/pi is primarily a GPU pod manager plus a lightweight agent runner. It does not expose a pi.on(...)-style extension API like pi-mono.
The closest thing to hooks is the pi-agent --json event stream:
session_startuser_messageassistant_startassistant_messagethinkingtool_calltool_resulttoken_usageerrorinterruptedThat makes pi useful as an event producer, but not as a host for third-party runtime interception.
pi-mono haspi-mono exposes a real extension API through packages/coding-agent/src/core/extensions/types.ts.
Verified pi.on(...) hook names:
resources_discoversession_startsession_before_switchsession_before_forksession_before_compactsession_compactsession_shutdownsession_before_treesession_treecontextbefore_provider_requestbefore_agent_startagent_startagent_endturn_startturn_endmessage_startmessage_updatemessage_endtool_execution_starttool_execution_updatetool_execution_endmodel_selecttool_calltool_resultuser_bashinputpi-mono extensions can also:
registerTool(...)registerCommand(...)registerShortcut(...)registerFlag(...)registerMessageRenderer(...)registerProvider(...)unregisterProvider(...)pi.eventspi-mono hooks are not just observers. Several can actively mutate behavior:
before_agent_start can rewrite the effective system prompt and inject messagescontext can replace the message set before an LLM callbefore_provider_request can rewrite the serialized provider payloadtool_call can mutate tool inputs and block executiontool_result can rewrite tool outputuser_bash can replace shell execution entirelyinput can transform or fully handle user input before normal processingThat is a good fit for a local coding harness. It is not automatically a good fit for a company control plane.
Paperclip already has several hook-like surfaces, but they are much narrower and safer:
setup() and onHealth()The plugin event bus is already pointed in the right direction:
plugin.<pluginId>.*These ideas from pi-mono fit Paperclip with little conceptual risk:
Paperclip should continue exposing run and transcript events to plugins, for example:
This matches Paperclip's control-plane posture: observe, react, automate.
Paperclip already has this. It is worth keeping and extending.
This is the clean replacement for many ad hoc hook chains.
Paperclip already has setup() and onHealth(). That is the right shape.
If more lifecycle is needed, it should stay explicit and host-controlled.
Some pi-mono ideas do belong in Paperclip, but only inside trusted adapter/runtime code:
This should be an adapter surface, not a general company plugin surface.
These pi-mono capabilities are a bad fit for Paperclip core:
Paperclip should not let general plugins rewrite:
Those are core invariants.
pi-mono's low-friction override model is great for a personal coding harness.
Paperclip should keep plugin tools namespaced and non-shadowing.
Paperclip is an operator-controlled control plane. Repo-local plugin auto-loading would make behavior too implicit and too hard to govern.
Hooks like:
session_before_switchsession_before_forksession_before_treemodel_selectinputuser_bashare tied to pi-mono being an interactive terminal coding harness.
They do not map directly to Paperclip's board-and-issues model.
If we want a "hooks" story inspired by pi-mono, it should split into two layers:
Allowed surfaces:
Disallowed:
For adapters and other trusted runtime packages only:
This is where the best pi-mono runtime ideas belong.
If the question is "what hooks do pi and pi-mono have?":
pi: JSON output events, not a general extension hook systempi-mono: a broad extension hook API with 27 named event hooks plus tool/command/provider registrationIf the question is "what works for Paperclip too?":