pi-jev-compaction
Automatic context clearing for Pi, without losing the conversation.
# pi-jev-compaction
**Keep the conversation. Clear stale tool output. Get the original back without running the command again.**
An automatic [Pi](https://pi.dev) extension powered by [TypeSafe Jev](https://typesafe.ai). Jev scores older tool outputs; Pi stops sending the ones you no longer need. Your original session messages stay intact.
No extra agent. No summary model. No runtime dependencies beyond Pi.
## Install
```sh
pi install git:github.com/nourhelmi/pi-jev-compaction
export TYPESAFE_API_KEY="your-typesafe-api-key"
pi
```
Get a key from [TypeSafe](https://typesafe.ai). Set it in the environment where you launch Pi. Already running Pi? `/reload` reloads the extension, but a newly exported shell variable requires restarting Pi from that shell.
That's it. Clearing runs automatically. `/jev-status` shows its configuration and last result.
```sh
pi remove git:github.com/nourhelmi/pi-jev-compaction
```
Requires Node.js **22.19+**. Tested against Pi **0.85.1**. Works with models running inside Pi, not with standalone Claude Code or Codex CLI sessions.
## How it works
1. After a tool turn reaches **65% of the model's context window**, inspect older successful text outputs.
2. Protect the latest **12k estimated tokens**, including complete parallel tool batches.
3. Ask Jev about up to **16 large outputs**, sending bounded conversation, argument, and result excerpts in one request.
4. Clear an output only when its estimated probability of still being needed is below **0.25**.
5. Replace its model-facing body with a stable marker. Keep the tool call, message order, metadata, and original evidence.
Example marker:
```text
[pi-jev: older tool output cleared from context; original retained in this session.
Retrieve with jev_read({"ref":"…"}). Do not rerun a side