Which moments a hook can attach to, and what it can do there. Event names link to each harness’s documentation. “Block”, “deny” and “modify” change what the agent does; “observe only” can watch but not intervene. Where hook files live is on the Locations page.
| Moment | piExtension event handlers |
|---|---|
| Hook types | Extension event handlers |
| Session and workspace | |
| Project trust is decided | project_trustdecide The first handler answering yes or no wins; only user-level and -e extensions can answer. |
| Session starts | session_startobserve only |
| Resources are discovered | resources_discoverload extra resources Returns extra skill, prompt and theme paths, accumulated across handlers. |
| Session details change | session_info_changedobserve only |
| Before switching sessions | session_before_switchcancel |
| Before forking a session | |
| Before navigating the session tree | session_before_treecancel, replace, modify |
| After navigating the session tree | session_treeobserve only |
| Session ends | |
| Prompt and turn | |
| User submits a prompt | |
| Before the agent starts | before_agent_startadd context, modify, replace Returning systemPrompt replaces the whole system prompt. Since 1.2.0 also fires for triggered extension messages. |
| Agent starts | agent_startobserve only |
| Turn starts | turn_startobserve only |
| Agent finishes its turn | agent_before_settleadd context, queue follow-up The last point at which a handler can append entries and request one more provider call. |
| Turn ends | |
| Agent ends | agent_endobserve only |
| Agent settles | agent_settledobserve only |
| Tools | |
| Before a tool runs | tool_callblock, modify Mutating event.input patches arguments without re-validation. The first block wins; a thrown error blocks the tool. |
| Tool execution starts | tool_execution_startobserve only |
| Tool execution reports progress | tool_execution_updateobserve only |
| Tool execution ends | tool_execution_endobserve only |
| After a tool runs (any result) | |
| Shell, terminals and files | |
| User runs a shell command (!) | user_bashreplace, delegate, block User ! and !! commands, not the agent's bash tool. The first handler to answer wins; a failure blocks the command. |
| MCP | |
| MCP servers are registered or removed | mcp_servers_changetake over Handling it makes the extension responsible for connecting registered servers. |
| Context and compaction | |
| Before context is sent to the model | contextmodify context_with_systemmodify, replace Runs after every context handler, on the full transcript including system messages. |
| Prompt cache warming is decided | |
| Before context is compacted | session_before_compactcancel, replace |
| After context is compacted | session_compactobserve only |
| Compaction fails | session_compact_failedobserve only |
| Model and provider | |
| Model is selected | model_selectobserve only |
| Thinking level is selected | thinking_level_selectobserve only |
| Before provider headers are sent | before_provider_headersmodify |
| Before a provider request | before_provider_requestreplace Each returned payload replaces the request and is passed to the next handler. |
| Provider streams a response | provider_stream_eventobserve only Handlers are awaited in stream order, so a slow handler delays the stream. |
| After a provider response | after_provider_responseobserve only |
| Messages and interface | |
| Message starts | message_startobserve only |
| Message updates | message_updateobserve only |
| Message ends | |
| Extension prompt opens | |
| Extension prompt closes | ui_prompt_endobserve only |
Notes and sources
pi
- In-process TypeScript extension events, run in extension load order; extensions run with full user permissions.
- pi's documentation names its extension type definitions as the event reference.
- Project extensions load only after the project is trusted.
- pi 1.2.0 extension event overloads, Source code, checked 2026-10-14