Skip to main content

Overview

Pi’s extension system allows you to customize and extend the agent’s behavior through event hooks, custom tools, commands, and UI components. Extensions are TypeScript modules that run in the same process as the agent.

Creating an Extension

Basic Structure

Extensions export a factory function that receives the Pi API:

Extension API

The pi object provides the full extension API:
Location: packages/coding-agent/src/core/extensions/types.ts:916

Event Hooks

Session Lifecycle

Agent Lifecycle

Message Events

Tool Events

Context Manipulation

Input Interception

Compaction Hooks

Extension Context

All event handlers receive a context object:
Location: packages/coding-agent/src/core/extensions/types.ts:261

Custom Commands

Register slash commands:

Command Context

Command handlers receive an extended context:

UI Integration

Dialogs

Status Bar

Widgets

Custom Messages

Extensions can send custom message types with custom rendering:

State Persistence

Extensions can persist state across sessions:

Custom Providers

Register custom LLM providers:

OAuth Providers

Resource Discovery

Provide custom skills, prompts, and themes:

Best Practices

Check ctx.hasUI before using UI methods:
Use session_shutdown to close connections:
Don’t rely on in-memory state - persist to session:
Extensions can communicate via shared event bus:

Next Steps

Tools

Create custom tools

Sessions

Session management and branching