← Catalog

@adeildo/pi-compact

Keeps a long pi session's context small: hides old tool output, keeping each call so the agent can run it again, and writes pi's compaction summary on a small model.

Extension

Install

Install with PiG

pig install npm:@adeildo/pi-compact

Install with Pi

pi install npm:@adeildo/pi-compact
Review before installing

Packages run code with your permissions and influence agent behavior. Catalog inclusion is not a security audit. Review the source before installing a third-party package.

Pi manifest JSON

The pi field of package.json.

{
  "extensions": [
    "./src/index.ts"
  ]
}

README

Written by the package's publisher, shown as published in version 7.1.0 (README.md). PiG does not review it.

@adeildo/pi-compact

npm pi SDK

In a long session, every request sends the whole context again, and most of it is old tool output that the agent no longer needs. This package hides that old output and keeps what matters: your words, the agent's words and the decisions. On a week of real sessions, it cut the cost by about a third.

pi install npm:@adeildo/pi-compact

What it does

When a run ends with more than 150k tokens of context, each tool output older than the last 10 turns becomes one line that names its call:

Output hidden to save context, about 4.2k tokens. It came from: read src/view.ts. Run it again if you need it.
  • Your messages, the agent's words, errors and the last 10 turns stay whole.
  • When pi compacts anyway, a small model writes the summary, with your last words on top unchanged.

Each prune leaves a line in the chat with what it saved, and Ctrl+O lists the calls it hid.

After a tool call, the prune's line: 181 old tool outputs hidden, 705k to 250k tokens, and below it what the next request pays to rewrite the cache and in how many requests that pays back. Then pi's cache miss notice for that rewrite.
A prune's line, and the one cache rewrite it costs on the next request.

Commands and settings

/prune hides old output when the run ends, whatever the size of the context.

These are on the Compact tab of Alt+S, and stored under compact in ~/.pi/agent/extensions/pi-harness/settings.json.

SettingDefaultWhat it does
Hide old tool outputonTurns the prune on
On Anthropic's sideoffOn Anthropic models, Anthropic clears old output instead of the prune, and the agent keeps its thinking
Above150000How many tokens of context a run must end with to prune
Write it on the side modelonPi's summary is written on the model below, with your last words on top. When off, pi uses the session's model
ModelautoThe model that writes the summary. auto picks the cheapest one of the session's provider

The tab also shows what this session's prunes freed, and how many hidden outputs the agent had to run again. A high share means the prune hides output that the agent still needs.

How it works explains when a prune runs, why it works this way, Anthropic's own clearing, and how it was measured.

adeildo.dev
pi-harness is made by adeildo.dev