Skip to main content
Extensions are TypeScript modules that extend Pi’s behavior. They can register custom tools, subscribe to lifecycle events, add commands, and create custom UI components.

What You Can Build

Extensions enable:
  • Custom tools - Register tools the LLM can call via pi.registerTool()
  • Event interception - Block or modify tool calls, inject context, customize compaction
  • User interaction - Prompt users via ctx.ui (select, confirm, input, notify)
  • Custom UI components - Full TUI components with keyboard input
  • Custom commands - Register commands like /mycommand
  • Session persistence - Store state that survives restarts
  • Custom rendering - Control how tool calls/results and messages appear

Quick Start

Create ~/.pi/agent/extensions/my-extension.ts:
Test with:

Extension Structure

Building a Custom Tool

Complete Tool Example

Here’s a complete working example:

Event Handling

Subscribe to lifecycle events:

State Management

Store state in tool result details for proper branching support:

User Interaction

Prompt users with dialogs:

Available Imports

Next Steps

  • See Creating Skills for specialized task workflows
  • See Custom Providers for adding LLM providers
  • Check packages/coding-agent/examples/extensions/ for more examples