Repository navigation
Conversation
Reads the Grok CLI's own local billing log for the SuperGrok weekly allowance and prepaid balance — the only source for the weekly allowance, since xAI's Management API only sees team pay-as-you-go billing, a different pool of money from a personal SuperGrok subscription. Falls back to that Management API before `grok` has ever been run locally, populating a balance only (its usage-analytics endpoint accepts a cost query but no token-count one, so no per-model breakdown is available there). Co-Authored-By: Claude Sonnet 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Webm6BX1U8ZBfzuwQhEyyS
2 of 3 tasks
3 of 4 tasks
Member
|
Automated duplication check: this pull request looks similar to #9498, which covers the same Grok usage collector. I keep that one open and close this one to consolidate review. If you feel this is the wrong decision, please open the PR again with a note on the difference. |
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
bin/omarchy-agent-usage-grok, a collector for theomarchy.agentsbar widget covering Grok/xAI, following the same display-ready JSON contract asclaude/codex/fireworks.~/.grok/logs/unified.jsonl), which already carries the SuperGrok weekly allowance and prepaid balance on everygrokrun — no credentials needed. This is the only source for the weekly allowance: xAI's Management API only sees team pay-as-you-go billing, a different pool of money from a personal SuperGrok subscription.grokhas ever been run locally. Getting a working key for it took three non-obvious steps (documented inshell/plugins/agents/README.md): a separate management key is required since the CLI's own OAuth token is inference-scoped only, that key is scoped to one team which need not be the CLI's default team, and its ACL must explicitly include billing read access. That fallback path has no per-model token breakdown available — the usage-analytics endpoint only accepts a cost/line-item query, not a token-count one — so it populates a balance only.grokto the widget'smanifest.jsonprovider defaults and description, and documents both paths in the plugin'sREADME.md.test/shell.d/agent-usage-grok-scanner-test.sh, covering: a valid record with neither a log nor a key, building the record from a fixture log (percent-fraction scaling, cents-to-dollars balance, on-demand limit, reset time), picking the newest log line by timestamp regardless of file order, a staleness note on an old snapshot vs. none on a fresh one, the configured-key-wins-with-CLI-team_id credential precedence, the Management API's plain-decimal-string balance parse, the cost-series summation, and the CLI-token hint on a 403.All findings above came from testing against a real xAI team and a real Grok CLI session, not from the docs alone (the docs don't mention the management-key/team-scoping/ACL requirements, and the usage-analytics endpoint's accepted field names aren't documented either — both were found by testing against the real API).
Test plan
./test/all— passing except 3 pre-existing failures unrelated to this change (config-test.sh,snapper-test.sh,unowned-system-paths-test.shall fail the same way on a clean checkout of this branch's base, needing anOMARCHY_PKGS_PATHcheckout not present in this environment)bash test/shell.d/agent-usage-grok-scanner-test.sh— all 8 assertions pass$OMARCHY_PATH/bin/) and confirmed it renders correctly in the live bar panel🤖 Generated with Claude Code
https://claude.ai/code/session_01Webm6BX1U8ZBfzuwQhEyyS