← Catalog

pi-usage-limits

[![npm](https://img.shields.io/npm/v/pi-usage-limits)](https://www.npmjs.com/package/pi-usage-limits)

Extension

Install

Install with PiG

pig install npm:pi-usage-limits

Install with Pi

pi install npm:pi-usage-limits
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": [
    "./index.ts"
  ]
}

README

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

pi-usage-limits

npm

A pi extension that shows your Claude and Codex subscription limits in pi's status line and updates them after every prompt.

5h: 12%, 7d: 25%

Why use it

  • Works with Claude through the Claude Agent SDK. It reads limits with your existing Claude Code login, so it works when pi runs Claude models through the SDK, including pi-claude-bridge. You don't need a separate Anthropic login or API key in pi.
  • Codex support, no CLI needed. Reads 5-hour and weekly Codex limits over HTTPS with pi's own openai-codex login. pi refreshes the token; ~/.codex/auth.json is never read or touched.
  • Never slows pi down. Usage is fetched in the background, and pi doesn't wait for it.
  • Updates after each prompt. It refreshes when a session starts, when you switch models, and once each prompt finishes, instead of on every turn or tool call.
  • Fewer calls with several sessions. Results are cached on disk for 60 seconds, and the cache is shared between all running pi sessions. A cached value is marked with 󰃨.
  • Doesn't replace your footer. It adds one status entry, so pi's built-in footer and other extensions keep working.
  • No tokens used. Reading limits sends no prompt and doesn't touch your quota.
  • Clear errors. If a lookup fails, the status line shows the reason in red, such as the Claude CLI's own error.
  • Small and readable. A few hundred lines of plain TypeScript, with no build step.

Supported models

Active modelSourceShows
openai provider, including gpt-6.1-solNo quota lookupOpenAI usage unavailable; check usage dashboard
openai-codex provider, or a non-openai model id containing codexChatGPT usage endpoint (pi's openai-codex login)5-hour and weekly usage
Model id contains claudeClaude Agent SDK (Claude Code login)5-hour and 7-day utilization

The openai provider's Sign in with ChatGPT flow has no documented quota endpoint. Check ChatGPT → Settings → Usage, as OpenAI recommends. For API-key authentication, check the OpenAI API usage dashboard instead. This extension never substitutes openai-codex credentials or cached limits for openai, even when the model id contains codex.

Other models show <model> not supported yet.

Requirements

  • pi
  • For Claude: @anthropic-ai/claude-agent-sdk installed alongside pi (for example as a pi-claude-bridge dependency), signed in to a Claude subscription. API-key logins have no subscription limits to show.
  • For Codex: signed in to pi's openai-codex provider (/login in pi) with a ChatGPT subscription.

Install

pi install npm:pi-usage-limits

Try it for a single session without installing:

pi -e npm:pi-usage-limits

How it works

EventAction
session_startShow current usage
model_selectShow usage for the new model
agent_settledRefresh after a prompt completes

The cache lives at ~/.pi/agent/cache/pi-usage-limits.json. Entries pair each source's limits with a fetch timestamp and expire after 60 seconds. Codex entries also record the account ID and are used only after checking the current login. Limits are shared across models using the same usage source, never between openai and openai-codex.

Writes use atomic replacement and a lockfile for read-modify-write updates. The lock does not deduplicate concurrent API refreshes. Malformed or incompatible entries are treated as cache misses; the old cache format is discarded on the next save. Cache I/O failures produce console diagnostics but do not prevent displaying freshly fetched limits. Refresh failures still surface as errors rather than silently serving stale limits.

Caveats

  • Claude limits come from an experimental Claude Agent SDK API, which may change in a future SDK release. The cache assumes one Claude Code login per agent directory; switching Claude accounts may show the previous account's limits for up to 60 seconds.
  • Codex limits come from an undocumented ChatGPT endpoint (chatgpt.com/backend-api/wham/usage, the same one the Codex CLI uses), which may change without notice.
  • Each uncached Claude lookup starts a short-lived claude process, which takes about a second. It runs in the background.

Development

Run the cache regression tests with npm test. Tests use a temporary agent directory and mocked HTTP responses; they do not access your real cache or subscription endpoints.

License

MIT