Small OpenCode plugin for Codex quota visibility.
Instead of checking the web dashboard, you get quota toasts directly in OpenCode.
- 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 (
warnby default, sowarn/critical/error). - Includes JSON output mode for scripts and debugging.
- Build:
npm install
npm run build- Link and auto-configure OpenCode:
npm link
opencode-codex-usage --setup- Restart OpenCode.
Manual plugin path (if you prefer editing config directly):
"<repo>/dist/index.js"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-usageUse /codex-usage or opencode-codex-usage to verify the end-to-end toast flow immediately (no agent invocation).
Flags for opencode-codex-usage:
-hor--help- show CLI usage and available flags.--jsonor--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- 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-usageworks from any folder. - Window labels use API-provided window minutes when available (for example
5h window,7d window), otherwise fallback towindow A/window B.
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.jsonSet polling interval (milliseconds):
OPENCODE_CODEX_QUOTA_POLL_MS=120000Default 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.triggerSet background toast threshold:
OPENCODE_CODEX_QUOTA_TOAST_THRESHOLD=criticalAllowed values: warn (default), critical, error, always, never.
Set toast duration (milliseconds):
OPENCODE_CODEX_QUOTA_TOAST_DURATION_MS=5000Default is 5000. Invalid or non-positive values fall back to default.
The probe prints one JSON object (ProbeSnapshot) per run.
Common keys:
status(for exampleok,warn,error)statusCode(for example200,500,auth,network,timeout)used(primary/secondarypercent)reset(primary/secondaryreset duration)windowMinutes(primary/secondarywindow 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
}npm run build
npm test
npm run formatAuto-configure OpenCode with local plugin path:
opencode-codex-usage --setup