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

v2.1.0

Published

Pi extension that shows context window usage visualization

Readme

pi-context-usage

npm version npm downloads

A pi extension package that adds:

  • /context — a dot-grid visualization of current context usage
  • /context details — a deeper breakdown of system prompt, active tools, and conversation turns

DEMO:

demo

Install

As a pi package

pi install pi-context-usage

Manual (project-local)

Copy or symlink this directory into .pi/extensions/pi-context-usage/.

Check out my other Pi extensions

  • pi-auto-theme — Auto-syncs Pi theme with OS dark/light mode.
  • pi-cache-graph — Real-time prompt cache hit rates and token metrics.
  • pi-checklist — Session task checklist with dependencies and a TUI renderer.
  • pi-context-prune — Prunes verbose tool outputs from context while preserving history.
  • pi-context-usage — Dot-grid visualization of context window token usage.
  • pi-gauge — Live tokens/sec and TTFT in the status bar.
  • pi-subscription-meter — Tracks subscription quotas and rate limits across AI providers.

Usage

Context summary

/context

Shows a dot-grid summary with five breakdown categories:

Context Usage

◍ ⚙ ● ● ● ● ● ● ● ● ●
● ● ● ● · · · · · · ·
· · · · · · · · · · ·
· · · · · · · · · · ·
· · · · · · · · · · ·
· · · · · · · · · · ·
· · · · · · · · · · ·
· · · · · · ○ ○ ○ ○ ○

claude-sonnet-4-5   31.4k / 200.0k tokens (16%)

◍ System Prompt:    1.7k (1%)
⚙ Tools:              275 (0%)
● Messages:        29.4k (15%)
· Empty:           152.2k (76%)
○ Buffer:           16.4k (8%)

Context details

/context details

When UI is available, this opens a keyboard-driven overlay that keeps the grid summary at the top and adds expandable sections for:

  • System Prompt — visible estimate from ctx.getSystemPrompt(), split into independently expandable introduction and Pi's <tools>, <rules>, <docs>, <project_context>, <skills>, <cwd>, and other named sections. Each part shows its own estimated tokens and characters; expanding it reveals its text. Available Skills expands into one row per advertised skill; each row shows its estimated prompt tokens, total serialized characters (including markup and location), and the separate character counts for its name and description. Expand a skill to read its description. These counts reflect the escaped text in the prompt, not the contents of skill files.
  • Tools — active tool schema breakdown from pi.getAllTools() filtered by pi.getActiveTools() (separate from the <tools> prompt instructions)
  • Conversation — one line per user turn, plus inline compaction summaries and per-message drill-down

Keyboard shortcuts in the overlay:

  • ↑/↓ move focus
  • Enter or → expand a section/row
  • ← collapse a section/row
  • Tab jump between top-level sections
  • PageUp/PageDown, Home/End scroll faster
  • Esc or q close

When UI is not available, /context details falls back to a plain-text dump.

Example plain-text output:

System / Tools Details

Item                Tokens  Chars
System prompt         6.2k  24,800
read                    70     279
bash                    61     244
edit                   142     567
Total visible parts    6.5k  25,890

Note: visible parts sum to 2.2k tokens, while the top summary uses 14.3k cached prompt tokens from the last assistant cache. That cache number includes provider-side scaffolding and cached context that extensions cannot inspect.

Conversation (6 turns)
Per-turn and cumulative values are visible-entry estimates from estimateTokens(message); they will not match the summary's provider/cache totals.

 #1  10:00  U  Can you inspect the repo and summarize how /context currently works?      55      55 cum est
 #2  10:01  U  Now sketch a plan for a /context details mode with a deeper breakdown.      36      91 cum est
  Σ  10:06  Σ  Earlier discussion established the design…      38     197 cum est
 #3  10:10  U  Add the system prompt and active-tools breakdown next.      65     262 cum est

Development

# Load extension directly into a live pi session
pi -e ./src/index.ts

# After sending at least one message
/context
/context details

# Standalone mock tests
bun run test:mock
bun run test:mock-details

How it works

Summary buckets

| Category | Symbol | Theme color | Token source | |--------------|--------|-------------|--------------| | System Prompt | ◍ | accent | Math.ceil(systemPrompt.length / 4) — estimated from visible system prompt text | | Tools | ⚙ | muted | Sum of Math.ceil((name + description + JSON.stringify(parameters)).length / 4) over active tools | | Messages | ● | success | usedTokens - systemPromptTokens - toolTokens — conversation entries | | Empty | · | dim | contextWindow - usedTokens - bufferTokens — unused space | | Buffer | ○ | warning | model.maxTokens — reserved for model output |

All visible estimates use a chars / 4 heuristic. The grid distributes cells proportionally across the five categories.

Details view estimates

  • System prompt tokens: Math.ceil(systemPrompt.length / 4)
  • Per-tool tokens: Math.ceil((name + description).length / 4) + Math.ceil(JSON.stringify(parameters).length / 4)
  • Turn tokens: summed via pi's exported estimateTokens(message) heuristic

Because pi does not expose the exact provider-serialized request payload, the visible system prompt + tools total is intentionally labeled as an approximation. The cache-provided number in details remains the authoritative cached-prompt value, and it is not directly comparable to the visible estimates.