原始内容
Context Inspector
This extension adds the /context command which displays a map of the current session context. Gives a rough break up of what is taking up the context.

What it shows
The inspector is a read-only snapshot of the current Pi session. It groups the current state into sections:
- Overview — cwd, session file, session id, model, thinking level, usage
- System prompt & resources — custom prompt, appended prompt, context files, skills, tool snippets, fallback prompt
- Slash commands — registered commands
- Tool registry & active tools — all tools and which ones are active
- Session branch (raw entries) — the session branch history
- Resolved model context — the final message list after session resolution
- Request preview — a compact summary of the request that would be sent
Linting
Install dev dependencies in the package directory, then run:
npm run lint
npm run lint:watch
npm run check
These use TypeScript's compiler to surface type and syntax errors without emitting files.
Usage view
At the top, the inspector shows estimated context usage:
- a usage bar
- a colored 10×10 usage grid
- a category legend
Reserved blocksat the end when compaction reserves tokens
The category colors are just visual helpers. They do not change behavior.
How it works
Cache prompt info
- On
before_agent_start, the extension stores the latest system prompt and prompt options.
- On
Build a snapshot
buildSnapshot()gathers everything into one immutable object.- This keeps the UI stable while you move around inside it.
Estimate usage
estimateUsageCategories()approximates token usage from prompt resources, resolved messages, and compaction settings.- These numbers are estimates, not exact accounting.
Render lines
buildInspectorLines()turns the snapshot into plain text lines.styleInspectorLines()adds the border and colors.
Interact
- Arrow keys move between sections/items.
- Enter or → expands a section.
- ← or Esc collapses.
eexports the snapshot to.pi/context-snapshot.json.qcloses the inspector.
Notes
- The inspector only opens in an interactive UI session.
- It refuses to open while the current turn is still running.
- Export is also only available from an idle interactive session.