pi-ctx-budget

extensionmaintained

Context window budget display for pi — /ctx-budget command + toggleable footer

by · v0.1.0 · published 2mo ago

$ pi install npm:pi-ctx-budget
downloads/mo
0
stars
0
last push
5d ago
open issues
8

Signals

license: MITtestspi manifest: missinginstall size: —deps: 0peer deps: 0

Download trend

233 downloads · last 12 weeks (weekly)

README

pi-ctx-budget

npm version License: MIT

Context window budget display for pi — track token usage across system prompts, skills, tools, and conversation with a /ctx-budget command and toggleable footer bar.

Features

  • Token estimation — estimates source token usage from system context, skills, and tool schemas
  • Runtime tracking — shows conversation token usage from live context data
  • Compact display — renders ASCII budget summary with percentage breakdown
  • Toggleable footer — optional persistent footer bar showing per-category token percentages
  • Persistent config — footer preference saved to ~/.pi/pi-ctx-budget.json
  • Environment overridesPI_CTX_BUDGET_FOOTER=1 to force-enable footer

Installation

For Humans

npm install -g pi-ctx-budget

For AI Agents

This is a pi extension package. Add it to your pi settings.json:

{
  "packages": [
    {
      "name": "pi-ctx-budget",
      "url": "https://github.com/buihongduc132/pi-ctx-budget.git"
    }
  ]
}

For pi git-sourced

Clone into your git-sourced extensions directory:

cd ~/.pi/agent/git/github.com/buihongduc132/
git clone https://github.com/buihongduc132/pi-ctx-budget.git

Then ensure settings.json includes the git-sourced path.

Usage

/ctx-budget command

CommandDescription
/ctx-budgetCompact budget summary
/ctx-budget allVerbose per-item breakdown
/ctx-budget --verboseSame as all
/ctx-budget detailSame as all
/ctx-budget footerShow footer toggle status
/ctx-budget footer onEnable footer (persisted)
/ctx-budget footer offDisable footer (persisted)
/ctx-budget footer <category>Toggle a footer category

Footer categories

The footer bar shows percentage of context window used per category:

  • Sys — System prompt (internal pi prompt + all context files)
  • A — AGENTS.md files
  • Sk — Skills
  • T — Extension + MCP tools

Example output

╭─ Context Budget ──────────────────────────────────────╮
│ System    12,450t  ██████████████░░░░░░░░░  8.3%     │
│ Skills     1,200t  ████░░░░░░░░░░░░░░░░░░░  0.8%     │
│ Tools      3,800t  █████░░░░░░░░░░░░░░░░░  2.5%     │
│ Conv       8,200t  ███████████░░░░░░░░░░░  5.5%     │
│ Free    134,350t  ░░░░░░░░░░░░░░░░░░░░  82.9%     │
│ Model: gpt-4o  Window: 150K                         │
╰──────────────────────────────────────────────────────╯

Development

npm install
npm run typecheck    # TypeScript type checking
npm test             # Run tests
npm run test:coverage # Tests with coverage
npm run smoke-test   # Quick smoke test
npm pack --dry-run   # Verify package contents

License

MIT © buihongduc132