@prjct.app/pi-self-compact

Pi extension: Pi's compaction summary, written by extending the session's cached request. Adds nothing to the context.

Packages

Package details

extension

Install @prjct.app/pi-self-compact from npm and Pi will load the resources declared by the package manifest.

$ pi install npm:@prjct.app/pi-self-compact
Package
@prjct.app/pi-self-compact
Version
0.4.0
Published
Oct 6, 2026
Downloads
446/mo · 446/wk
Author
jlopezlira
License
MIT
Types
extension
Size
1.5 MB
Dependencies
0 dependencies · 2 peers
Pi manifest JSON
{
  "image": "https://raw.githubusercontent.com/prjct-app/pi-self-compact/main/docs/cover.png",
  "extensions": [
    "./index.ts"
  ]
}

Security note

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

README

@prjct.app/pi-self-compact

pi-self-compact — for PI Agent

Pi decides when to compact and how much recent history stays verbatim. This extension only writes the summary, and writes it from the session's own cached request instead of replaying the history as text:

  • Cheaper. The provider bills the shared prefix as cached input. Measured on Codex: about 10.7k uncached input tokens per compaction, against about 72k for Pi's replayed summary.
  • Better input. The summarizer reads every tool result whole; Pi's replay cuts each one to 2,000 characters.

It adds nothing to the context: no tool, no guidance messages, no notes, no locks, no commands. When the cached summary cannot run (overflow recovery, a model change since the last request, a stale snapshot, a provider error), Pi writes its own summary.

Adapted from disler/self-compact-pi-agent (MIT); see THIRD_PARTY_NOTICES.md.

Install

pi install npm:@prjct.app/pi-self-compact

List pi-self-compact last in packages, so it reuses the provider body after other extensions rewrite it.

Settings

Compaction is configured in Pi's settings.json (see Pi's docs/compaction.md):

{
  "compaction": {
    "reserveTokens": 40000,
    "keepRecentTokens": 60000
  }
}

reserveTokens sets when Pi compacts (contextWindow - reserveTokens: about 232k on a 272k window). keepRecentTokens is the recent history kept verbatim; everything before it is replaced by the summary.

Each compaction entry records details.selfCompact with summary: "cache-shared", input and cacheRead. Entries without it are Pi's own summary.

Development

npm run check
npm test
npm run check:package