Harness Notes

Hooks

Updated 2026-11-24,

On this page

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.

MomentpiExtension event handlers
Hook typesExtension event handlers
Session and workspace
Project trust is decided
project_trust

decide

The first handler answering yes or no wins; only user-level and -e extensions can answer.

Session starts
session_start

observe only

Resources are discovered
resources_discover

load extra resources

Returns extra skill, prompt and theme paths, accumulated across handlers.

Session details change
Before switching sessions
Before forking a session
session_before_fork

cancel, modify

Besides cancelling, can only skip conversation restore.

Before navigating the session tree
session_before_tree

cancel, replace, modify

After navigating the session tree
session_tree

observe only

Session ends
session_shutdown

observe only

Fires on quit, reload, new, resume and fork.

Prompt and turn
User submits a prompt
input

modify, take over

Transforms chain; handled short-circuits.

Before the agent starts
before_agent_start

add context, modify, replace

Returning systemPrompt replaces the whole system prompt. Since 1.2.0 also fires for triggered extension messages.

Agent starts
agent_start

observe only

Turn starts
turn_start

observe only

Agent finishes its turn
agent_before_settle

add context, queue follow-up

The last point at which a handler can append entries and request one more provider call.

Turn ends
turn_end

add context, queue follow-up

Can append entries and request one more provider call.

Agent ends
agent_end

observe only

Agent settles
agent_settled

observe only

Tools
Before a tool runs
tool_call

block, modify

Mutating event.input patches arguments without re-validation. The first block wins; a thrown error blocks the tool.

Tool execution starts
Tool execution reports progress
Tool execution ends
tool_execution_end

observe only

After a tool runs (any result)
tool_result

modify

Handlers compose; each sees earlier changes.

Shell, terminals and files
User runs a shell command (!)
user_bash

replace, 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_change

take over

Handling it makes the extension responsible for connecting registered servers.

Context and compaction
Before context is sent to the model
context

modify

context_with_system

modify, replace

Runs after every context handler, on the full transcript including system messages.

Prompt cache warming is decided
cache_warming_decision

decide

Returns warm or stop; the last handler that answers wins.

Before context is compacted
session_before_compact

cancel, replace

After context is compacted
session_compact

observe only

Compaction fails
Model and provider
Model is selected
model_select

observe only

Thinking level is selected
Before provider headers are sent
Before a provider request
before_provider_request

replace

Each returned payload replaces the request and is passed to the next handler.

Provider streams a response
provider_stream_event

observe only

Handlers are awaited in stream order, so a slow handler delays the stream.

After a provider response
Messages and interface
Message starts
message_start

observe only

Message updates
message_update

observe only

Message ends
message_end

replace

The replacement must keep the message role.

Extension prompt opens
ui_prompt_start

observe only

Pi starts waiting on a blocking extension prompt.

Extension prompt closes
ui_prompt_end

observe 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.