← Catalog

@yuzhi535/pi-idlecompact

Pi extension that auto-compacts after 30 minutes idle, at 500k for large-window models, and at 256k for 272k-window GPT/Codex models.

Package

Install

Install with PiG

pig install npm:@yuzhi535/pi-idlecompact

Install with Pi

pi install npm:@yuzhi535/pi-idlecompact
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": [
    "./index.ts"
  ]
}

README

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

pi-idlecompact

A Pi extension that compacts a session for you, so long chats cost less when you come back.

It does two things:

  • Idle compact. If a session sits idle for 30 minutes and the context is at least 200K tokens, it runs Pi's normal /compact. This is the same idea as Claude Code's idle compaction, with a shorter wait (Claude Code defaults to about 54 minutes).
  • Size compact. When a turn finishes, it also compacts early:
    • large-window models (over 500K, such as 1M-context Gemini or DeepSeek) at 500K
    • GPT / Codex models with a 272K window at 256K

Sessions below 200K are left alone while idle, so a short chat does not pay for a summary.

Install

pi install git:github.com/yuzhi535/pi-idlecompact

Then /reload or restart Pi. Once the package is on npm, this will also work:

pi install npm:@yuzhi535/pi-idlecompact

Requires Pi 1.5 or newer.

Settings

Optional environment variables:

VariableDefaultMeaning
PI_IDLE_COMPACTonSet to off to disable this extension
PI_IDLE_COMPACT_IDLE_MINUTES30Minutes of idle time before compacting
PI_IDLE_COMPACT_MIN_TOKENS200000Minimum context size for idle compact

The size thresholds (500K / 256K) are built into the extension. For Pi's own built-in autocompact to use the same cutoffs before the next prompt, you can also set compaction.modelOverrides in settings.json. Example for a 1M-window model, where reserveTokens is contextWindow - 500000:

{
  "compaction": {
    "enabled": true,
    "reserveTokens": 16384,
    "keepRecentTokens": 20000,
    "modelOverrides": {
      "vercel-ai-gateway/google/gemini-4-hydrogen": {
        "reserveTokens": 500000
      }
    }
  }
}

For a 272K-window GPT / Codex model, use reserveTokens of 16000 so compact starts at 256K.

License

MIT