Skip to content

jasonmit/opencode-codex-usage

Repository files navigation

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

  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

Codex quota toast in OpenCode

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 toast trigger 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 writing the trigger file.
  • --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 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.
  • Manual triggers use a per-user signal file in the system temp directory, so opencode-codex-usage works 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.

Override trigger signal file path (optional):

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

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

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

About

Small OpenCode plugin for Codex quota visibility.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages