pi-mono/packages/coding-agent/examples
Armin Ronacher 8562bcf66a feat(coding-agent): codemode and MCP
This adds codemode and MCP support to pi. Codemode (packages/codemode) runs
model-written JavaScript in a QuickJS wasm VM inside a worker. From there the
script calls pi's tools as async functions, uses a per-session store, and can
read the model catalog and run classifiers. The codemode tool in coding-agent
is compatible with Codex's exec tool, and codemode.mode works like Codex's
tool modes (on or only). Large results are written to a JSON temp file. MCP
(packages/mcp) is a standalone client for stdio and streamable HTTP servers,
with OAuth.

The core only gets general mechanisms; codemode, tool_search and MCP are
built-in extensions that use them. Other extensions can replace these
built-ins. Tools declare an exposure: direct, model-only, codemode, deferred
or hidden. prepareLoadout() lets an orchestrating tool change which tool
declarations the model sees. ctx.executeTool() runs nested calls through
validation and the tool_call/tool_result hooks. Those calls emit events with
parentToolCallId and are recorded as bounded nestedCalls on the parent
result, which compaction and HTML export use. Tools can also return
structuredContent with an outputSchema, and can report errors with isError
instead of throwing. MCP servers come from mcp.json (global, or per project
after the project is trusted) or from pi.registerMcpServer(). They are
managed with /mcp and pi mcp list|login|logout, and their runtimes load on
first use.

Closes #10040
2026-09-29 09:12:50 +02:00
..
extensions feat(coding-agent): Virtual models (#10035) 2026-09-28 23:30:45 +02:00
plugins/pi-example-plugin feat: add transactional replicated state 2026-09-21 16:07:59 +02:00
sdk feat(coding-agent): codemode and MCP 2026-09-29 09:12:50 +02:00
README.md feat: build with TypeScript 7 and run sources with plain node 2026-09-25 13:14:33 +02:00
rpc-client.ts feat: build with TypeScript 7 and run sources with plain node 2026-09-25 13:14:33 +02:00
rpc-extension-ui.ts feat: build with TypeScript 7 and run sources with plain node 2026-09-25 13:14:33 +02:00

Examples

Example code for the pi-coding-agent SDK, process integration, and extensions.

CLI integration

rpc-client.ts uses the typed RpcClient to run Pi in a child process, stream events, and wait for the run to settle.

Build the coding-agent package before running it from a repository checkout:

node examples/rpc-client.ts "Explain this repository"

Directories

sdk/

Programmatic usage via createAgentSession(). Shows how to customize models, prompts, tools, extensions, and session management.

extensions/

Example extensions demonstrating:

  • Lifecycle event handlers (tool interception, safety gates, context modifications)
  • Custom tools (todo lists, questions, subagents, output truncation)
  • Commands and keyboard shortcuts
  • Custom UI (footers, headers, editors, overlays)
  • Git integration (checkpoints, auto-commit)
  • System prompt modifications and custom compaction
  • External integrations (SSH, file watchers, system theme sync)
  • Custom providers (Anthropic with custom streaming, GitLab Duo)

plugins/pi-example-plugin/

An experimental plugin package that Pi automatically builds into separate Session-worker and TUI Chord facets.

Documentation