| name | pi-extensions |
| description | Pi extension development master reference.
Use when: building pi extensions, debugging extension behavior, or choosing the right pattern.
|
Pi Extensions โ LLM Master Reference
Start Here (Read Order)
The guides/ and references/ directories contain deeper narratives and examples. Use them after scanning the three master docs above.
One-Line Directives
- Writing a new extension? โ Read
ARCHITECTURE.md ยง1โยง5, then copy the matching pattern from PATTERNS.md.
- Extension is broken? โ Check
ANTI-PATTERNS.md first.
- Extension is slow to start? โ
references/startup-optimization.md โ jiti bottleneck, .js vs .ts, discovery cost.
- Need TUI component? โ
PATTERNS.md ยงP12โยงP14, then guides/02-paradigms.md for narrative.
- Need beautiful TUI rendering? โ
references/tui-beautiful-rendering.md โ box drawing, overlays, badges, SVG widgets.
- Need multi-agent patterns? โ
references/extension-patterns-from-source.md โ agent coordination, tasks, feeds.
- Need custom provider/OAuth? โ
PATTERNS.md ยงP19โยงP20, then guides/07-advanced-patterns.md.
- Need RPC safety? โ
ANTI-PATTERNS.md ยงA2, then guides/05-rpc-mode.md.
Master Decision Trees
Which document do I need?
I need to understand how extensions work
โโโบ ARCHITECTURE.md
I need working code to copy
โโโบ PATTERNS.md
I need to know what NOT to do
โโโบ ANTI-PATTERNS.md
I need a step-by-step first tutorial
โโโบ guides/01-quickstart.md
I need deep narrative on tools/events/UI
โโโบ guides/02-paradigms.md
I need state persistence strategies
โโโบ guides/03-state.md
I need production architecture (workflows, memory)
โโโบ guides/04-production.md
I need RPC mode specifics
โโโบ guides/05-rpc-mode.md
I need pi internals (loader, runner, binding)
โโโบ guides/06-internals.md
I need startup optimization, speed up extension loading
โโโบ references/startup-optimization.md
I need provider plugins, OAuth, overrides
โโโบ guides/07-advanced-patterns.md
Which paradigm should I use?
Need LLM to perform action? โโโโโโโโโโโโโโโโบ Tool (PATTERNS P2โP5)
Need user to type /command? โโโโโโโโโโโโโโโโบ Command (PATTERNS P6โP7)
Need keyboard shortcut? โโโโโโโโโโโโโโโโโโโโบ Shortcut (guides/02-paradigms.md)
Need to react to system events? โโโโโโโโโโโโบ Event handler (PATTERNS P8โP11)
Need interactive TUI? โโโโโโโโโโโโโโโโโโโโโโบ Custom UI (PATTERNS P12โP14)
Need to inject a model provider? โโโโโโโโโโโบ registerProvider (PATTERNS P19โP20)
Need to override a built-in tool? โโโโโโโโโโบ Tool override (PATTERNS P4)
Which state persistence mechanism?
State should go to LLM context? โโโโโโโโโโโโบ sendMessage({ customType, ... })
State is extension-private? โโโโโโโโโโโโโโโโบ appendEntry("customType", data)
State is user preference (cross-project)? โโบ File in ~/.pi/agent/
State is project-local? โโโโโโโโโโโโโโโโโโโโบ File in .pi/
State is temporary cache? โโโโโโโโโโโโโโโโโโบ Local variable (reconstructed on reload)
Document Map
Master References (Read First)
Progressive Guides (Read as Needed)
| File | Level | Topic |
|---|
guides/01-quickstart.md | ๐ฑ Beginner | First extension in 5 minutes |
guides/02-paradigms.md | ๐ฟ Intermediate | Tools, commands, events, UI deep dive |
guides/03-state.md | ๐ณ Advanced | Persistent and branch-resilient state |
guides/04-production.md | ๐๏ธ Expert | Multi-mode, workflows, memory systems |
guides/05-rpc-mode.md | ๐ RPC | RPC mode compatibility and degradation |
guides/06-internals.md | โ๏ธ Internals | Loader, runner, event dispatch, binding |
guides/07-advanced-patterns.md | ๐ Advanced | Provider plugins, OAuth, tool overrides, file mutation queues |
Reference Docs
Tutorials
Examples
5-Minute Quick Test
Prerequisite: This skill is installed (cloned to skills/pi-extensions).
Below creates a sample Extension, placed in ~/.pi/agent/extensions/ โ separate from the skill directory.
mkdir -p ~/.pi/agent/extensions
cat > ~/.pi/agent/extensions/hello.ts << 'EOF'
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
export default function (pi: ExtensionAPI) {
pi.registerCommand("hello", {
description: "Say hello",
handler: async (_args, ctx) => {
ctx.ui.notify("Hello from Pi Extensions!", "success");
},
});
}
EOF
pi -e ~/.pi/agent/extensions/hello.ts
Quick Import Cheat Sheet
import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
import { Type } from "@sinclair/typebox";
import { StringEnum } from "@earendil-works/pi-ai";
import { Container, Text, SelectList } from "@earendil-works/pi-tui";
import { withFileMutationQueue } from "@earendil-works/pi-coding-agent";
import { isToolCallEventType, isBashToolResult } from "@earendil-works/pi-coding-agent";
Hot Topics
Dynamic Model Injection
Use pi.registerProvider() for proxies, custom endpoints, or team-wide model configs. See PATTERNS.md ยงP19โP20 and guides/07-advanced-patterns.md.
Tool Override
Register a tool with the same name as a built-in (read, bash, edit, write) to wrap or replace it. See PATTERNS.md ยงP4.
Parallel Execution Safety
Custom tools that mutate files must use withFileMutationQueue() to avoid race conditions with built-in edit/write. See PATTERNS.md ยงP5 and ANTI-PATTERNS.md ยงA4.
RPC Safety
ctx.hasUI is true in RPC, but custom() returns undefined. Use select/confirm/input/editor for blocking dialogs that work in both modes. See ANTI-PATTERNS.md ยงA2 and guides/05-rpc-mode.md.
Master references: ARCHITECTURE ยท PATTERNS ยท ANTI-PATTERNS