docs/grok.md
Grok uses xAI's official Grok Build CLI (grok, released 2026-05-14). Usage data is
fetched via the ACP JSON-RPC x.ai/billing extension method over grok agent stdio
when available, then via grok.com's billing gRPC-web endpoint using the signed-in
browser session when the CLI surface does not expose billing.
~/.grok/auth.json (primary; always works for SuperGrok subscribers)
email, team_id, first_name/last_name, plan-hint (auth_mode)
for the identity row in the menu.grok agent stdio ACP JSON-RPC (best-effort, currently disabled in grok 0.1.210)
grok agent stdio and call initialize + x.ai/billing (no params).x.ai/billing extension method
is only wired in the interactive TUI; the agent-stdio surface returns
-32601 Method not found. The provider degrades silently to identity-only
when this happens. When xAI exposes billing on the agent protocol, no
code change is required.\/ in method
names. Foundation.JSONSerialization.data defaults to escaping forward
slashes, so payloads must be re-encoded with \/ → / before being
written to stdin or grok will silently drop them (12s client-side
timeout instead of the expected error response).https://grok.com/grok_api_v2.GrokBuildBilling/GetGrokCreditsConfig.CODEXBAR_ALLOW_BROWSER_COOKIE_IMPORT=1 is set.~/.grok/auth.json is still used for identity and as a last best-effort
bearer probe, but the production grok.com billing endpoint currently
authenticates browser sessions.grok agent stdio returns
Method not found.~/.grok/sessions/<encoded-cwd>/<session-id>/signals.json files (last 30 days).totalTokensBeforeCompaction, contextTokensUsed, modelsUsed,
and the most recent session timestamp.~/.grok/auth.json (path overridable via GROK_HOME).https://auth.x.ai::<client-id> (SuperGrok), falling back to
https://accounts.x.ai/sign-in (legacy session).key (bearer token), refresh_token, expires_at,
auth_mode, email, team_id, user_id, first_name/last_name.grok login and expire after ~7 days; refresh is handled by
the CLI itself (CodexBar does not refresh; it just reads the cached credential).initialize params:
{
"protocolVersion": "1",
"clientCapabilities": {
"fs": { "readTextFile": false, "writeTextFile": false },
"terminal": false
}
}
x.ai/billing result shape (all monetary values are { val: <cents> }):
{
"billingCycle": {
"billingPeriodStart": "2026-05-01T00:00:00Z",
"billingPeriodEnd": "2026-06-01T00:00:00Z"
},
"monthlyLimit": { "val": 99900 },
"onDemandCap": { "val": 0 },
"on_demand_enabled": false,
"disabledByConfig": false,
"usage": {
"includedUsed": { "val": 12345 },
"onDemandUsed": { "val": 0 },
"totalUsed": { "val": 12345 }
}
}
"Authentication required to fetch billing data. Run 'grok login' to authenticate.".initialize, 12s for x.ai/billing. CodexBar terminates the
child grok process on timeout to avoid leaking subprocesses.UsageSnapshotusedPercent = usage.totalUsed.val / monthlyLimit.val * 100;
resetsAt = billingCycle.billingPeriodEnd.usedPercent and resetsAt parsed from the gRPC-web
billing protobuf.accountEmail from credential email.accountOrganization from credential team_id.loginMethod = "SuperGrok" for OIDC, otherwise the raw auth_mode.~/.grok/sessions/)Each session directory contains signals.json with fields like:
{
"turnCount": 1,
"contextTokensUsed": 2968,
"contextWindowTokens": 512000,
"totalTokensBeforeCompaction": 0,
"modelsUsed": ["grok-build"],
"primaryModelId": "grok-build",
"sessionDurationSeconds": 47
}
CodexBar aggregates these into a GrokLocalSessionSummary (session count, total
tokens, last session time, primary model) and exposes it for diagnostics even when
the RPC path is unavailable.
xAI has not exposed a Statuspage-style status feed yet. The "View Status" link
points to https://status.x.ai.
Sources/CodexBarCore/Providers/Grok/GrokProviderDescriptor.swiftSources/CodexBarCore/Providers/Grok/GrokAuth.swiftSources/CodexBarCore/Providers/Grok/GrokRPCClient.swiftSources/CodexBarCore/Providers/Grok/GrokWebBillingFetcher.swiftSources/CodexBarCore/Providers/Grok/GrokStatusProbe.swiftSources/CodexBarCore/Providers/Grok/GrokLocalSessionScanner.swiftSources/CodexBar/Providers/Grok/GrokProviderImplementation.swift