pi-optimizer
Context optimization tools for pi coding agent
Package details
Install pi-optimizer from npm and Pi will load the resources declared by the package manifest.
$ pi install npm:pi-optimizer- Package
pi-optimizer- Version
0.7.1-alpha.0- Published
- Sep 20, 2026
- Downloads
- 126/mo · 126/wk
- Author
- thien2218
- License
- MIT
- Types
- extension
- Size
- 206.1 KB
- Dependencies
- 2 dependencies · 3 peers
Pi manifest JSON
{
"extensions": [
"./index.js"
]
}Security note
Pi packages can execute code and influence agent behavior. Review the source before installing third-party packages.
README
pi-optimizer
Context optimization extension for Pi. It gives coding agents more useful context by improving code navigation and reducing repeated or noisy tool output. It is also built into surgent.
Why use it
Long coding sessions accumulate large tool results, repeated file content, and output that no longer helps with current task. That context costs tokens and can distract model from relevant code.
pi-optimizer keeps useful evidence while removing avoidable noise. It works automatically after installation and adds structural tools for reading only code needed for current task.
What it does
- Adds
code_map, which uses Tree-sitter to index symbols and declarations before files are read in full. - Adds
inspect, which returns one selected symbol body for targeted code reading and edits. - Supports TypeScript, JavaScript, Python, Go, Java, and Rust code navigation.
- Compacts Bash output by stripping terminal control sequences and collapsing repeated or similar lines.
- Formats grep results by grouping matches under file paths and stores smaller summaries in session history.
- Removes older
readandinspectresults when newer results fully cover same content. - Prunes empty tool results and superseded tool calls from model context and persisted sessions.
These changes reduce context growth, improve prompt-cache reuse, and leave more room for requirements, code, and reasoning.
Requirements
- Node.js 22.19 or newer
- Pi coding agent
Install
Install package through Pi:
pi install npm:pi-optimizer
Confirm installation:
pi list
Start or restart Pi in a repository. Extension loads automatically; agent can then use code_map and inspect, while output optimization runs in background.
Important: surgent already includes this extension. Do not install standalone package alongside surgent in same configuration, because both copies would register same tools and hooks.