← Catalog

@sreetej510/pi-usage

Pi extension that reports provider usage/rate-limit budgets (Codex, Anthropic OAuth, etc.) via /usage, with a live statusline widget.

Extension

Install

Install with PiG

pig install npm:@sreetej510/pi-usage

Install with Pi

pi install npm:@sreetej510/pi-usage
Review before installing

Packages run code with your permissions and influence agent behavior. Catalog inclusion is not a security audit. Review the source before installing a third-party package.

Pi manifest JSON

The pi field of package.json.

{
  "extensions": [
    "./dist/index.js"
  ]
}

README

Written by the package's publisher, shown as published in version 0.15.6 (README.md). PiG does not review it.

@sreetej510/pi-usage

A pi coding agent extension that reports provider usage / rate-limit budgets — OpenAI Codex, Anthropic OAuth, and pi-auth-backed providers — via /usage, with a live statusline widget.

What it does

  • Queries the active model's provider usage endpoint (Codex app-server usage/rate-limit-reset APIs, or Anthropic's OAuth usage API) and renders remaining budget/reset windows.
  • Caches results on disk (~/.pi/agent/usage-cache.json) for a few minutes so multiple concurrent pi sessions don't hammer the provider APIs.
  • Pushes a compact usage summary into the statusline, refreshed automatically with retry/backoff on rate limits (429).
  • Shows the next Codex banked-reset expiry and supports confirmed, interactive consumption.

Commands

CommandEffect
/usageShow cached usage (fetches fresh data if the cache is stale)
/usage --refreshForce a fresh fetch, bypassing the cache
/usage --timeout <seconds>Set the query timeout
/usage --rawShow raw usage API responses (debugging)
/usage --consume-banked-resetSelect and consume a Codex banked reset after confirmation

Banked reset consumption sends one POST with credit_id and redeem_request_id, without the list-only OpenAI-Beta / originator headers. It only reports success when Codex returns code: "reset". Failed or unclear requests are not automatically retried; run /usage --refresh before deciding whether to try again.

Install

npm install -g @sreetej510/pi-usage

Then add it to your pi settings.json:

{
  "packages": ["npm:@sreetej510/pi-usage"]
}

Or, for local development, point at the file directly:

{
  "extensions": ["/absolute/path/to/pi-extensions/extensions/pi-usage/src/index.ts"]
}

File layout

FileResponsibility
src/index.tsExtension entry point + session event wiring
src/command.ts/usage command handler
src/statusline.tsStatusline state, timers, background refresh
src/footer.tsCustom footer with right-aligned usage status
src/query.tsTop-level usage query orchestration
src/codex-query.tsCodex pi-auth + app-server fallback queries
src/anthropic-query.tsAnthropic OAuth usage queries
src/codex-auth.tsCodex auth header resolution
src/anthropic-auth.tsAnthropic auth header resolution
src/codex-app-server.tscodex app-server RPC client
src/codex-reset-credits.tsBanked reset list/consume/format
src/normalize-codex.tsCodex backend + app-server payload normalization
src/normalize-anthropic.tsAnthropic usage payload normalization
src/format.tsReport/statusline formatting and display
src/shared-cache.tsOn-disk shared usage cache
src/models.tsProvider/model matching helpers
src/args.ts/usage argument parsing and completions
src/constants.tsShared constants
src/types.tsShared TypeScript types
src/utils.tsSmall parsing/formatting helpers
src/errors.tsHTTP/rate-limit error helpers
src/http.tsfetchWithTimeout wrapper

Development

npm install
npm run --workspace @sreetej510/pi-usage check     # biome + typecheck
npm run --workspace @sreetej510/pi-usage test      # mocked requests; never spends real resets
npm run --workspace @sreetej510/pi-usage format