---
slug: "pi-context-preview"
source_type: "readme"
source_url: "https://cdn.jsdelivr.net/gh/offbynan/pi-context-preview@main/README.md"
repo: "https://github.com/offbynan/pi-context-preview"
source_file: "README.md"
branch: "main"
---
# pi-context-preview

A Pi extension that gives a visual preview of how the context window is utilized, inspired by Claude Code's `/context` command. Model-agnostic, works with any provider Pi supports.

![pi-context-preview](https://raw.githubusercontent.com/offbynan/pi-context-preview/main/docs/screenshot.png)

## Install

```bash
pi install npm:pi-context-preview
```

Or add to `~/.pi/agent/settings.json`:

```json
{
  "packages": ["npm:pi-context-preview@latest"]
}
```

For development:

```bash
pi -e ./extensions/index.ts
```

## Usage

```
/context           # default: grid + legend + message breakdown
/context verbose   # expand tool calls and results per tool name
```

## How it works

Token counts are **estimated** using a character-ratio heuristic (`chars / 4`) applied to each part of the last provider request payload. The **total** token count is always sourced from Pi's own API-accurate tracking; the per-category breakdown is then scaled proportionally to match that total.

### Categories

| Symbol | Meaning |
|--------|---------|
| `⛁` | Used — segment ≥ 70% of its grid allocation |
| `⛀` | Used — segment < 70% of its grid allocation |
| `⛝` | Autocompact buffer reserve |
| `⛶` | Free space |

Grid dimensions: **10 × 10** for ≤ 200k models · **20 × 10** for 1M+ models.

## Update

```bash
pi update npm:pi-context-preview
```

## License

MIT
