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-max-context

v1.0.0

Published

Set a persistent maximum context length for pi. When reached, compacts the session and prompts the model to continue.

Readme

pi-max-context

A pi extension that limits how much context a conversation can use. It does three things:

  1. Set a limit. /max-context 100K sets the limit and saves it in .pi.
  2. Keep the limit. The limit is loaded again on every restart, new session, fork, and /reload.
  3. Act on the limit. When context usage reaches the limit, pi compacts the conversation. Then the model is asked to continue where it left off.

Install

pi install /path/to/pi-max-context

The extension is now listed with pi list. Restart pi or run /reload.

Usage

/max-context            show the current limit and context usage
/max-context 100K       limit = 100,000 tokens        (K = 1,000)
/max-context 1.5M       limit = 1,500,000 tokens      (M = 1,000,000)
/max-context 250000     limit = 250,000 tokens (plain number)
/max-context off        disable the limit (also: 0, none)

Rules:

  • Units are case-insensitive. 100k and 100K are the same.
  • Decimals are allowed, for example 1.5M.
  • Invalid values are rejected with a message.

While pi runs, the footer shows context usage: ctx <used>/<limit>.

Where the limit is saved

Project file (used when it exists):

<cwd>/.pi/max-context.json
{
  "maxContextTokens": 100000,
  "continuePrompt": "Continue the task. Use the compaction summary for earlier context."
}
  • maxContextTokens — the limit in tokens. 0 means disabled.
  • continuePrompt — the message sent to the model after compaction. Optional. The default is "continue where you left off".

If the project has no file, pi reads ~/.pi/agent/max-context.json instead. The project file always wins.

How it works

  • The limit is checked before each model call and after each turn. Large tool results are caught too.
  • When the limit is reached, pi compacts the conversation. After compaction, pi sends a follow-up message so the model continues the work.
  • Safety rules stop loops:
    • 15 seconds must pass between two compactions.
    • After 3 compactions in a row that do not lower usage below the limit, auto-compaction pauses with a warning. It starts again when usage drops or you set a new limit.
  • If the limit is higher than the model's real context window, pi warns you. The model's own window wins.

Files

pi-max-context/
├── index.ts          # the extension code
├── units.ts          # token parsing and formatting (K, M units)
├── package.json      # pi package manifest
└── README.md

License

MIT