pi-trim

Pi coding agent extension that trims Pi-specific identity and documentation from the system prompt to reduce context usage.

Packages

Package details

extension

Install pi-trim from npm and Pi will load the resources declared by the package manifest.

$ pi install npm:pi-trim
Package
pi-trim
Version
0.2.2
Published
Nov 2, 2026
Downloads
719/mo · 81/wk
Author
zhexusun10
License
MIT
Types
extension
Size
21.9 KB
Dependencies
0 dependencies · 2 peers
Pi manifest JSON
{
  "image": "https://raw.githubusercontent.com/zhexusun10/pi-trim/main/assets/before-after.png",
  "video": "https://raw.githubusercontent.com/zhexusun10/pi-trim/main/assets/demo.mp4",
  "extensions": [
    "./extensions/index.ts"
  ]
}

Security note

Pi packages can execute code and influence agent behavior. Review the source before installing third-party packages.

README

pi-trim

Less Pi in Pi.

Strip Pi-specific identity and documentation from the system prompt. Keep the coding assistant, tools, and your instructions.

Compatible with Pi 1.5.0, including its new default preamble. Older supported Pi versions still work.

CI npm License: MIT Pi 1.5.0

简体中文 · Measured results · Source

Pi 1.5.0 default system text: 459 to 199 tokens, measured with o200k_base

Install

The Pi 1.5.0 compatibility fix is available now from GitHub:

pi install git:github.com/zhexusun10/pi-trim

The fix is prepared for npm as pi-trim 0.2.2. Once 0.2.2 is published, install or update the npm package with:

pi install npm:pi-trim
# Existing npm installation: pi update npm:pi-trim

Then start a new Pi process, or use /reload in an existing session.

What changes?

What happens if Pi knows less about Pi?

Pi already keeps its default prompt small. This package removes three recognizable pieces of its own boilerplate:

Before After
You are an expert coding assistant operating inside pi, a coding agent harness. You are an expert coding assistant.
You are a coding assistant running inside pi, a coding agent harness. (introduced in Pi 1.5.0) You are a coding assistant.
Pi's <docs> section: pointers to its README, SDK, extensions, themes, skills, and TUI documentation Removed from the provider-bound system messages
The exact rule telling the model to inspect PI_* environment variables Removed

Tool descriptions and schemas, other rules, project instructions, skills, addenda, custom sections, and conversation messages remain intact. A user-defined docs section with different contents is preserved. This is a targeted transformation, not a filter for every occurrence of pi or docs.

You can still ask the model about Pi, but its automatic documentation pointers are gone. Provide the relevant paths or links yourself when doing Pi SDK or extension work.

Inspect it

/pi-trim
/pi-trim status
/pi-trim diff

status reports original and remaining character counts, a chars / 4 token estimate, and changed sections. diff shows the exact removed or replaced text.

Before the first model request, the command previews the base prompt. Afterwards, it describes the system text in the most recent request, including system-message updates. Tool schemas are excluded. Other extensions running later can change that request again.

Illustrated pi-trim command demo, based on the measured fixture

The animation is an illustrated command demo, not a recording of a live model session.

Measured prompt reduction

Pi 1.5.0 default system text Tokens
Before 459
After 199
Removed 260 (56.6%)

Measured using gpt-tokenizer 4.0.0, o200k_base, with default read/bash/edit/write tool snippets and guidelines. Installation paths are normalized to /opt/pi, and the working directory to /workspace. No project instructions, skills, or addenda. Tool schemas and provider formatting are excluded.

These are tokenizer counts for the published fixture, not provider billing totals. Adding your project context reduces the percentage saved. Smaller prompts do not establish better task success, latency, or cost; see the benchmark methodology and results.

npm ci --ignore-scripts
npm run benchmark

Coding-task comparison

A historical single paired pass using Pi 1.0 over ten small JavaScript tasks with openai-codex / gpt-6-sol:

Metric Default Pi pi-trim
Task success 10 / 10 10 / 10
Total input tokens, including cached input 63,903 50,699 (-20.7%)
Median first text delta (includes CLI startup) 14.179 s 13.673 s
Pi-reported model-price cost estimate $0.090297 $0.095274 (+5.5%)

Aggregate tool-call counts were identical. This run does not establish better latency, quality, or cost: it is small, cache state was uncontrolled, and there were timing outliers. Raw data, full metrics, and caveats.

How it works

The extension hooks context_with_system before each model call. It clones recognized system messages, transforms only the relevant content or named sections, and returns the replacement messages. It preserves tool additions/removals and section-deletion markers in mid-session updates. Pi's stored transcript is not rewritten.

The extension itself makes no network requests, telemetry, model calls, file reads, or file writes. It only transforms system messages in memory and shows reports on request. Pi's own behavior and installation operations are separate.

The generated default prompts of Pi 1.0.0, 1.4.0, and 1.5.0 are tested with Node.js 22.19+. The manifest follows Pi's host-provided peer dependency convention; it does not bundle Pi. Earlier Pi versions without context_with_system are unsupported. Upstream prompt changes may require new matching rules; unknown content passes through.

Update and remove

For the GitHub version:

pi update git:github.com/zhexusun10/pi-trim
pi remove git:github.com/zhexusun10/pi-trim

For an npm installation, use npm:pi-trim instead. Update to 0.2.2 or later once it is published. Restart Pi or run /reload after removal.

Migrating from the old strip-pi-docs.ts script? See the migration guide, especially if it previously patched your Pi installation.

Development

npm ci --ignore-scripts
npm run check
npm test
npm run benchmark
pi -e .

No build step or runtime dependencies. Pi loads the TypeScript extension directly. Tests cover preservation of project context, tools, custom sections, text blocks, and mid-session updates. CI also checks real Pi-generated prompts and sends a request through the Pi CLI to a local faux provider, without network access or model credentials.

For real coding-task comparisons, see benchmarks/README.md. Contributions and bug reports are welcome; include the Pi version and a minimal prompt example with private content removed.

License

MIT. An independent community package, not an official Pi product.