@victor-software-house/pi-context-optimizer
v1.0.0
Published
Pi extension for command rewriting and tool-output compaction optimization.
Downloads
208
Readme
@victor-software-house/pi-context-optimizer
Pi extension for command rewriting and tool output compaction in the Pi coding agent.

@victor-software-house/pi-context-optimizer rewrites selected bash commands through RTK and compacts noisy tool output from bash, read, and grep so the agent spends less context on low-value text.
Status
This repository is the maintained public standalone continuation of earlier RTK-related Pi extension work.
Features
Command handling modes
rewrite— rewrite supportedbashcommands through RTK automaticallysuggest— keep original commands, but show RTK suggestionscompact-only— disable command rewriting and keep output compaction enabled
Rewrite coverage
Supported command families include:
- Git and GitHub
- Filesystem and search commands
- Rust toolchain commands
- JavaScript and TypeScript tooling
- Python tooling
- Go tooling
- Container tooling
- Network commands
- Package manager commands
Output compaction pipeline
- ANSI stripping
- test output aggregation
- build output filtering
- git output compaction
- linter aggregation
- search result grouping
- source code filtering
- smart truncation
- hard truncation
Read safety features
- exact output preserved for explicit range reads (
offsetorlimit) - exact output preserved for short reads
- optional exact preservation for skill reads
Operator controls
/rtksettings modal/rtk show/rtk path/rtk verify/rtk stats/rtk clear-stats/rtk reset/rtk help
Installation
Local extension folder
Place this project in one of these locations:
~/.pi/agent/extensions/pi-context-optimizer
.pi/extensions/pi-context-optimizerGit installation
pi install git:github.com/victor-software-house/pi-context-optimizerConfiguration
Default config path:
~/.pi/agent/extensions/pi-context-optimizer/config.jsonA starter config is included at config/config.example.json.
Modes
| Mode | Rewrite commands | Compact output | Requires RTK binary for value |
|---|---:|---:|---:|
| rewrite | Yes | Yes | Yes |
| suggest | No | Yes | No |
| compact-only | No | Yes | No |
Event hooks used
This extension uses Pi extension events directly:
tool_call— inspect and optionally rewritebashcommandstool_result— compactbash,read, andgrepoutputsbefore_agent_start— add troubleshooting guidance to the promptsession_start/session_switch— refresh config and runtime state
Development
Install dependencies to set up Husky and the commit-msg commitlint hook:
npm installValidation commands:
bunx tsc -p tsconfig.json
bun ./src/output-compactor-test.ts
bun ./src/command-rewriter-test.ts
bun ./src/runtime-guard-test.ts
bun ./src/additional-coverage-test.ts
bun ./src/config-modal-test.ts
bun ./src/index-test.ts
bun run build:checkRelease automation
This repository uses:
semantic-releasefor versioning, tags, GitHub releases, and npm publishing- npm trusted publishing from GitHub Actions
- commitlint plus Husky to enforce Conventional Commits locally
Release workflow summary:
- merge Conventional Commit-based changes to
main - GitHub Actions runs
semantic-release semantic-releasedetermines the next version from commit history- GitHub release and npm publish happen from the release workflow
Documentation
Credits and prior art
This project builds on ideas explored in earlier public work.
References:
mcowger/pi-rtkMasuRii/pi-rtk-optimizersherif-fanous/pi-rtkrtk-ai/rtk
These projects informed the command rewriting, output compaction, and RTK integration approaches used here.
