pi-compact-ex

Configure Pi auto-compaction using a context-window percentage threshold.

Packages

Package details

extension

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

$ pi install npm:pi-compact-ex
Package
pi-compact-ex
Version
0.1.1
Published
Jul 16, 2026
Downloads
271/mo · 271/wk
Author
evan-choi
License
MIT
Types
extension
Size
6.9 KB
Dependencies
0 dependencies · 1 peer
Pi manifest JSON
{
  "extensions": [
    "./index.ts"
  ]
}

Security note

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

README

pi-compact-ex

A Pi extension that triggers automatic context compaction at a configurable percentage of the model's context window.

The default threshold is 90%. The active value appears in Pi's extension status slot:

compact 90%

Installation

Install from npm:

pi install npm:pi-compact-ex

Or install directly from GitHub:

pi install git:github.com/evan-choi/pi-compact-ex

If Pi is already running, reload its resources:

/reload

Usage

Show the current threshold:

/compact-threshold

Set a new threshold:

/compact-threshold 85

The command accepts integers from 1 through 99. Changes are persisted globally in ~/.pi/agent/pi-compact-ex.json and reflected in the extension status immediately.

Behavior

After every turn_end, the extension checks the current context-window usage. When usage reaches the configured threshold, it calls Pi's ctx.compact() API. Compaction starts after the current turn finishes, not while a response is streaming.

The extension replaces only Pi's built-in threshold-based trigger. It preserves:

  • context-overflow recovery and retry
  • manual /compact
  • Pi's existing summary generation

A compaction-in-progress guard prevents duplicate requests from the same agent run.

Development

Requirements:

  • Node.js 22.19 or newer
  • Pi (tested with 0.80.7)

Run the test suite:

npm test

Test the extension from a local checkout:

pi -e ./index.ts

License

MIT