npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

pi-compact-context

v1.0.2

Published

Let the AI trigger context compaction in pi via a compact_context tool and /compact-context command

Readme

pi-compact-context

Let the AI compact your context — just ask in plain English.

pi's built-in /compact command can only be typed by you. If you ask the model to "compact the conversation", it can't: compaction isn't a tool it can call. This package fixes that. It gives the model a compact_context tool, so natural-language requests like these just work:

"compact context"

"compact context after pushing the docs"

"summarize what we've done and compact the session"

"we're done with the debugging phase — compact, then start fresh on the API"

The model calls the tool itself, the current turn finishes, and pi compacts the conversation exactly as if you'd typed /compact.

Install

pi install npm:pi-compact-context

or straight from git:

pi install git:github.com/aerialcombat/[email protected]

Then restart pi (or run /reload). That's it — no configuration.

What it adds

| Interface | Name | Description | |-----------|------|-------------| | AI tool | compact_context | Callable by the model. Optional instructions parameter shapes the compaction summary. | | Slash command | /compact-context [instructions] | Same behavior, typed by you. Handy alias if you don't like pi's built-in /compact spelling. |

Both queue the same compaction; results appear via a toast notification (Compacted: N → M est. tokens).

How it works (and why it returns immediately)

Compaction in pi must not run mid-turn: AgentSession.compact() aborts the running agent turn before it starts. If a tool called it synchronously from inside that very turn, the run and the compaction would kill each other — the tool deadlocks, and you get a stuck "No result provided".

So this extension is deliberately fire-and-forget:

  1. You say "compact context".
  2. The model calls compact_context.
  3. The tool queues the compaction and returns instantly ("Compaction queued — it will run as soon as this turn ends").
  4. The turn finishes normally.
  5. pi compacts the now-idle session and shows the token counts.

You keep one full turn of headroom for the model to wrap up whatever it was doing — like pushing the docs — before the history gets summarized.

Requirements

  • pi coding agent
  • Any model — compaction uses pi's normal summarization path

FAQ

Does this replace /compact? No. /compact still works exactly as before. This adds an AI-triggerable path on top.

What about auto-compaction? Unaffected. pi still compacts automatically near the context-window threshold; this package only adds manual, conversational control.

Can the model compact itself mid-task and keep going? Not in the same turn — compaction needs an idle agent. The model should finish its current work, then call the tool. This is a safety property of pi's compaction, not a limitation of this package.

Where does the summary come from? pi's built-in compaction: an LLM summarizes the older history, recent messages are kept verbatim. Pass instructions (or type /compact-context focus on the API migration) to steer what the summary emphasizes.

License

MIT