Repository navigation
cli(feat): add a usage command for remaining Codex quota - #82
Merged
Merged
Conversation
`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>
|
Warning Review limit reachedYou'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. View limit details
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. Comment |
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>
5 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.account/rateLimits/readrequest. No account files are read, no inference requests are sent, andCODEX_ACCESS_TOKEN/CODEX_API_KEY/OPENAI_API_KEYare removed from the server's environment. Each read runs in a private empty directory, so project config doesn't apply.CODEX_PROFILE_USAGE_TIMEOUTseconds (default 10). On exit, Ctrl-C or timeout the server is stopped: stdin closes first, then TERM, then KILL.logincommand to run.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.Help,
usage(), bash/zsh/fish completions, README, USAGE.md,docs/llms.txtand CHANGELOG are updated together.test/packaging/aur-test.mjsandtest/packaging/metadata-test.shcomparebin/codex-profilewith the 1.3.0 PKGBUILD checksum. They fall back to the working tree only becausev1.3.0hasn't been tagged yet, so any CLI change fails them until 1.3.0 is released. With a temporary localv1.3.0tag (not pushed) both pass. The 1.3.0 release is currently blocked: the release dry run fails preflight withNPM_TOKEN could not authenticate with the npm registry.Testing
test/cli/usage-test.sh(13 cases) runs against a fake app-server covering: normal replies, signed-out errors,rateLimitsByLimitIdpreferring 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--jsonoutput. It also checks thatCODEX_HOMEis passed, credential variables are removed, and the private directory is cleaned up.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.not_logged_in, and one shows its limit reached. About 3–5s once warm.Scope and compatibility
Checklist
make check; if the environment lacks ShellCheck, I ranmake testand documented the missing lint result instead. (Full gate passes except the two tag-dependent packaging suites described above.)app defaultsession and use the original signed app bundle. (No Desktop changes.)🤖 Generated with Claude Code