@tsaokoming/auto-compact
Background compaction for Pi using a dedicated model
Package details
Install @tsaokoming/auto-compact from npm and Pi will load the resources declared by the package manifest.
$ pi install npm:@tsaokoming/auto-compact- Package
@tsaokoming/auto-compact- Version
0.1.4- Published
- Oct 25, 2026
- Downloads
- 409/mo · 387/wk
- Author
- tsaokoming
- License
- MIT
- Types
- extension
- Size
- 15.5 KB
- Dependencies
- 0 dependencies · 2 peers
Pi manifest JSON
{
"extensions": [
"./extensions/compact.ts"
]
}Security note
Pi packages can execute code and influence agent behavior. Review the source before installing third-party packages.
README
auto-compact
A Pi package that prepares compaction in the background with a dedicated model. If Pi needs to compact and the prepared result still applies to the active branch, the extension uses it. Otherwise, it runs compaction with the configured model. After compaction succeeds, it reports the model, thinking level, token usage, cost, and elapsed compaction time.
Install
Install from npm:
pi install npm:@tsaokoming/auto-compact
To try it for one session without installing it:
pi -e npm:@tsaokoming/auto-compact
Remove or disable another copy of compact.ts before loading this package so
that only one extension handles compaction.
Configure
Add the extension-specific provider, model, and backgroundThreshold
fields to the existing compaction object in ~/.pi/agent/settings.json:
{
"compaction": {
"enabled": true,
"reserveTokens": 16384,
"keepRecentTokens": 16384,
"provider": "google-vertex",
"model": "gemini-3.7-flash",
"thinkingLevel": "high",
"backgroundThreshold": 80
}
}
providerandmodelidentify the model used for compaction.thinkingLevelcontrols reasoning effort and defaults tohigh. Supported values areoff,minimal,low,medium,high,xhigh, andmax.backgroundThresholdis the context-window percentage at which background compaction begins.enabledtoggles this extension. When it isfalse, the section is missing, or required fields are absent, the extension stays inactive — it notifies once on session start and Pi's standard compaction behavior applies.- The remaining fields use Pi's standard compaction behavior.
Pick a model from Pi's model registry. Reload Pi after changing the settings or extension.
Develop
npm install --ignore-scripts
npm run check