npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

opencode-codex-usage

v0.3.0

Published

Codex quota probe and OpenCode toast plugin

Readme

opencode-codex-usage

Small OpenCode plugin for Codex quota visibility.

Instead of checking the web dashboard, you get quota toasts directly in OpenCode.

What it does

  • Shows Codex quota status as OpenCode toasts.
  • Runs a background check on startup and every 10 minutes.
  • Keeps noise low: background checks only notify when quota reaches the configured threshold (warn by default, so warn/critical/error).
  • Includes JSON output mode for scripts and debugging.

Quick start

Option A: install from npm (recommended)

npm install -g opencode-codex-usage
opencode-codex-usage --setup

Then restart OpenCode.

Option B: run with npx (no global install)

npx opencode-codex-usage --setup

Then restart OpenCode.

Option C: local repo (development)

  1. Build:
npm install
npm run build
  1. Link and auto-configure OpenCode:
npm link
opencode-codex-usage --setup
  1. Restart OpenCode.

Manual plugin path (if you prefer editing config directly):

"<repo>/dist/index.js"

Screenshot

CLI commands

The plugin registers a /codex-usage slash command and handles it in plugin hooks. This means quota checks run locally and the command is handled silently without an assistant turn.

You can still run opencode-codex-usage directly when you want an immediate quota refresh from a shell.

After setup verify end-to-end:

OPENCODE_CODEX_QUOTA_TOAST_THRESHOLD=always opencode
/codex-usage

Use /codex-usage or opencode-codex-usage to verify the end-to-end toast flow immediately (no agent invocation).

Flags for opencode-codex-usage:

  • -h or --help - show CLI usage and available flags.
  • --json or --verbose - print JSON snapshot to stdout on success.
  • --pretty - show a human-friendly quota view with ASCII usage bars.
  • --no-notify - skip the refresh notification step.
  • --retry <count> - retry transient probe failures (0-2). Overrides env for current run.
  • --setup - update OpenCode config with plugin path only.
  • --config <path> - with --setup, use a non-default OpenCode config path.
  • On error, JSON is written to stderr and the process exits non-zero.

Remove global install:

npm uninstall -g opencode-codex-usage

Remove local link:

npm unlink -g opencode-codex-usage

Behavior

  • Background checks run on startup and on interval.
  • Background checks trigger a toast only when status meets the configured threshold and gets worse than the previous background state.
  • Manual runs can trigger an immediate refresh from any folder.
  • Window labels use API-provided window minutes when available (for example 5h window, 7d window), otherwise fallback to window A / window B.

Configuration

Auth file is auto-detected by OS:

  • Linux: ~/.local/share/opencode/auth.json (or $XDG_DATA_HOME/opencode/auth.json)
  • macOS: ~/Library/Application Support/opencode/auth.json
  • Windows: %LOCALAPPDATA%\\opencode\\auth.json

Override auth path:

OPENCODE_AUTH_PATH=/custom/path/auth.json

Set polling interval (milliseconds):

OPENCODE_CODEX_QUOTA_POLL_MS=120000

Default is 600000 (10 minutes). Invalid or non-positive values fall back to default.

Set transient retry count for probe failures:

OPENCODE_CODEX_QUOTA_RETRY_COUNT=1

Allowed values: 0, 1 (default), 2. Values above 2 clamp to 2; invalid values fall back to default.

Advanced: override the internal refresh path (optional):

OPENCODE_CODEX_USAGE_SIGNAL_PATH=/tmp/opencode-codex-usage.refresh

Set background toast threshold:

OPENCODE_CODEX_QUOTA_TOAST_THRESHOLD=critical

Allowed values: warn (default), critical, error, always, never.

Set toast duration (milliseconds):

OPENCODE_CODEX_QUOTA_TOAST_DURATION_MS=5000

Default is 5000. Invalid or non-positive values fall back to default.

Probe output

The probe prints one JSON object (ProbeSnapshot) per run.

Common keys:

  • status (for example ok, warn, error)
  • statusCode (for example 200, 500, auth, network, timeout)
  • used (primary/secondary percent)
  • reset (primary/secondary reset duration)
  • windowMinutes (primary/secondary window length in minutes, when available)
  • plan, profile, probeTokens, error

Error statusCode values:

  • auth for auth-path/token issues
  • network for transport failures
  • timeout for request timeout
  • numeric HTTP status codes for server responses

Example:

{
  "status": "warn",
  "statusCode": 200,
  "plan": "plus",
  "profile": "default",
  "used": { "primary": 81, "secondary": 9 },
  "reset": { "primary": "1h0m", "secondary": "7d0h" },
  "windowMinutes": { "primary": 300, "secondary": 10080 },
  "probeTokens": 10
}

Development

npm run build
npm test
npm run format

Auto-configure OpenCode with local plugin path:

opencode-codex-usage --setup