Skip to content

cli(feat): add a usage command for remaining Codex quota - #82

Merged
Ducksss merged 6 commits into
mainfrom
claude/cli-usage-command
Oct 11, 2026
Merged

Ducksss merged 6 commits into
mainfrom
claude/cli-usage-command

Conversation

@Ducksss

@Ducksss Ducksss commented Oct 10, 2026

Copy link
Copy Markdown
Owner

Summary

Adds codex-profile usage [--json] [profile...]: remaining Codex CLI quota per profile, in the terminal, on macOS and Linux. The menu-bar app already shows this; terminal-only and AUR/Linux users had no way to see it.

  • Same read as the menu-bar app: the official app-server's account/rateLimits/read request. No account files are read, no inference requests are sent, and CODEX_ACCESS_TOKEN/CODEX_API_KEY/OPENAI_API_KEY are removed from the server's environment. Each read runs in a private empty directory, so project config doesn't apply.
  • Still dependency-free on macOS's Bash 3.2: a FIFO keeps the server's stdin open, replies are read line by line (partial writes are buffered), and a small awk JSON reader classifies each reply. Only the window fields are printed; account IDs and plan names in the reply are dropped.
  • Up to 4 profiles are read at once, each waiting up to CODEX_PROFILE_USAGE_TIMEOUT seconds (default 10). On exit, Ctrl-C or timeout the server is stopped: stdin closes first, then TERM, then KILL.
  • Output shows each window's duration, % left, low (≤25%) / critical (≤10%) / limit reached, and reset time. Signed-out profiles name the login command to run.
  • JSON states mirror status --json: ok, not_logged_in, unavailable, not_initialized, error. Named profiles that can't be read exit 1; the overview exits 0 unless the Codex CLI is missing.
  • It only reports quota. It never switches profiles.

Help, usage(), bash/zsh/fish completions, README, USAGE.md, docs/llms.txt and CHANGELOG are updated together.

⚠️ Merge after the 1.3.0 tag exists

test/packaging/aur-test.mjs and test/packaging/metadata-test.sh compare bin/codex-profile with the 1.3.0 PKGBUILD checksum. They fall back to the working tree only because v1.3.0 hasn't been tagged yet, so any CLI change fails them until 1.3.0 is released. With a temporary local v1.3.0 tag (not pushed) both pass. The 1.3.0 release is currently blocked: the release dry run fails preflight with NPM_TOKEN could not authenticate with the npm registry.

Testing

  • New test/cli/usage-test.sh (13 cases) runs against a fake app-server covering: normal replies, signed-out errors, rateLimitsByLimitId preferring the codex limit, non-codex-only limits, a reply split across writes, malformed JSON, a server that hangs (timeout, then process stopped), a server that exits early, uninitialized and missing profiles, a missing Codex CLI, argument validation, and no update notice in --json output. It also checks that CODEX_HOME is passed, credential variables are removed, and the private directory is cleaned up.
  • Completion and help suites extended.
  • scripts/check syntax, scripts/check lint (ShellCheck clean) and all 40 suites pass locally. The two packaging suites pass only with the temporary local tag, as explained above.
  • Live, against 8 real profiles on codex-cli 0.152.1: signed-in profiles show their windows (7d and 30d), signed-out ones report not_logged_in, and one shows its limit reached. About 3–5s once warm.
  • Only macOS awk (BWK) was available locally. CI's Ubuntu job will exercise the parser under mawk.

Scope and compatibility

  • Affected scope: Codex CLI / CODEX_HOME
  • Compatibility impact: new command and new optional environment variable; no existing behavior changes.

Checklist

  • I ran make check; if the environment lacks ShellCheck, I ran make test and documented the missing lint result instead. (Full gate passes except the two tag-dependent packaging suites described above.)
  • I did not add code that reads, copies, prints, parses, uploads, compares, or migrates auth tokens or ChatGPT cookies.
  • Desktop changes preserve the stock app default session and use the original signed app bundle. (No Desktop changes.)
  • I did not claim that CLI and Desktop account equality can be inspected or verified.
  • I updated documentation for user-facing behavior changes.

🤖 Generated with Claude Code

`codex-profile usage [--json] [profile...]` reads each initialized
profile's Codex CLI quota through the official app-server's
account/rateLimits/read request, the same read the menu-bar companion
makes, so terminal-only and Linux users get the numbers too.

The reader stays dependency-free on Bash 3.2: a FIFO keeps app-server's
stdin open, replies are framed line by line with partial-write handling,
and a small awk JSON reader classifies them. Each read runs in a private
temporary directory with credential environment variables removed, waits
up to CODEX_PROFILE_USAGE_TIMEOUT seconds, and stops the server on exit.
Up to four profiles are read at once. No account files are read and no
inference requests are sent; the command never switches profiles.

JSON states mirror status --json (ok, not_logged_in, unavailable,
not_initialized, error). Named profiles that cannot be read return 1;
the overview exits 0 unless the Codex CLI is missing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings October 10, 2026 17:20

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@coderabbitai

coderabbitai Bot commented Oct 10, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 8 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 2 included reviews currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 8a8b6022-304b-409e-8c9d-149f41641a4c

📥 Commits

Reviewing files that changed from the base of the PR and between 56d72d1 and 719ce8b.


📒 Files selected for processing (10)
  • CHANGELOG.md
  • README.md
  • USAGE.md
  • bin/codex-profile
  • docs/llms.txt
  • packaging/aur/.SRCINFO
  • packaging/aur/PKGBUILD
  • test/cli/completions-test.sh
  • test/cli/shell-test.sh
  • test/cli/usage-test.sh

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Ducksss and others added 5 commits October 11, 2026 02:01
Main replaced the README command table with a short pointer; mention
usage there instead of in the removed table.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Summary:
- Separate reader fields with "|" instead of a tab, so a window without
  windowDurationMins keeps its resetsAt instead of shifting it into
  duration_mins.
- Run each reader as one tracked subshell, and have the INT/TERM traps wait
  for it. SIGINT or SIGTERM no longer leaves app-server processes and
  temporary directories running until the per-profile deadline.
- Classify sign-in errors by the app-server's own messages. A missing
  sign-in and an expired or invalid one both report not_logged_in with the
  login command. An API-key sign-in reports unavailable and says quota needs
  a ChatGPT sign-in. JSON state names and fields are unchanged.
- Check the deadline on every loop iteration so a steady stream of other
  messages cannot outlast the timeout, and skip notification lines before
  parsing them.
- Read each named profile once, and accept "--" before profile names.
  Help stays limited to the position straight after the command name,
  as for other commands.

Tests:
- test/cli/usage-test.sh under Bash 3.2 with BWK awk and with mawk
- New cases fail on the previous head: null duration, sign-in errors,
  duplicate names, "--", SIGTERM cleanup, timeout during a message stream
- make check, with a temporary local v1.3.0 tag for the packaging checks

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Point the 1.3.0 PKGBUILD and .SRCINFO checksums at the CLI that now
includes usage, and list it in the 1.3.0 changelog section.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Ducksss
Ducksss merged commit a00e4b4 into main Oct 11, 2026
4 checks passed
@Ducksss
Ducksss deleted the claude/cli-usage-command branch October 11, 2026 07:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants