Extension Examples
Example extensions for pi-coding-agent.
Usage
Examples
Lifecycle & Safety
| Extension |
Description |
permission-gate.ts |
Prompts for confirmation before dangerous bash commands (rm -rf, sudo, etc.) |
protected-paths.ts |
Blocks writes to protected paths (.env, .git/, node_modules/) |
confirm-destructive.ts |
Confirms before destructive session actions (clear, switch, fork) |
dirty-repo-guard.ts |
Prevents session changes with uncommitted git changes |
Custom Tools
| Extension |
Description |
todo.ts |
Todo list tool + /todos command with custom rendering and state persistence |
hello.ts |
Minimal custom tool example |
question.ts |
Demonstrates ctx.ui.select() for asking the user questions |
tool-override.ts |
Override built-in tools (e.g., add logging/access control to read) |
ssh.ts |
Delegate all tools to a remote machine via SSH using pluggable operations |
subagent/ |
Delegate tasks to specialized subagents with isolated context windows |
Commands & UI
| Extension |
Description |
preset.ts |
Named presets for model, thinking level, tools, and instructions via --preset flag and /preset command |
plan-mode.ts |
Claude Code-style plan mode for read-only exploration with /plan command |
tools.ts |
Interactive /tools command to enable/disable tools with session persistence |
handoff.ts |
Transfer context to a new focused session via /handoff <goal> |
qna.ts |
Extracts questions from last response into editor via ctx.ui.setEditorText() |
status-line.ts |
Shows turn progress in footer via ctx.ui.setStatus() with themed colors |
snake.ts |
Snake game with custom UI, keyboard handling, and session persistence |
send-user-message.ts |
Demonstrates pi.sendUserMessage() for sending user messages from extensions |
timed-confirm.ts |
Demonstrates AbortSignal for auto-dismissing ctx.ui.confirm() and ctx.ui.select() dialogs |
modal-editor.ts |
Custom vim-like modal editor via ctx.ui.setEditorComponent() |
notify.ts |
Desktop notifications via OSC 777 when agent finishes (Ghostty, iTerm2, WezTerm) |
overlay-test.ts |
Test overlay compositing with inline text inputs and edge cases |
overlay-qa-tests.ts |
Comprehensive overlay QA tests: anchors, margins, stacking, overflow protection |
Git Integration
| Extension |
Description |
git-checkpoint.ts |
Creates git stash checkpoints at each turn for code restoration on fork |
auto-commit-on-exit.ts |
Auto-commits on exit using last assistant message for commit message |
System Prompt & Compaction
| Extension |
Description |
pirate.ts |
Demonstrates systemPromptAppend to dynamically modify system prompt |
custom-compaction.ts |
Custom compaction that summarizes entire conversation |
External Dependencies
| Extension |
Description |
chalk-logger.ts |
Uses chalk from parent node_modules (demonstrates jiti module resolution) |
with-deps/ |
Extension with its own package.json and dependencies |
file-trigger.ts |
Watches a trigger file and injects contents into conversation |
Writing Extensions
See docs/extensions.md for full documentation.
Key Patterns
Use StringEnum for string parameters (required for Google API compatibility):
State persistence via details: