@magpie-community/opencode-grok-auth
Grok with a SuperGrok or X Premium+ subscription, through the sign-in of
xAI's Grok Build CLI. Provider id: grok.
It needs Grok Build installed:
curl -fsSL https://x.ai/cli/install.sh | bash # macOS, Linux
irm https://x.ai/cli/install.ps1 | iex # Windows
Sign in
- Sign in with Grok Build (device code) runs
grok login --device-authand opens the page it prints. Approve the sign-in there, and the CLI finishes it.- If the CLI isn't signed in yet, the sign-in goes to the CLI's own home
(
GROK_HOME, else~/.grok), as if you had rungrok login. - If it is signed in, the sign-in goes to a home of this plugin's,
$XDG_CONFIG_HOME/opencode-grok-auth/<random>(else under~/.config). Grok Build's own sign-in stays as it is.
- If the CLI isn't signed in yet, the sign-in goes to the CLI's own home
(
- Use Grok Build's current sign-in takes the account the CLI is signed in to, with nothing to approve.
Where the sign-in is kept
The CLI keeps the sign-in in its home, as auth.json. OpenCode (or
magpie) keeps where that home is, the token and its expiry.
The plugin only reads auth.json: the CLI's refresh gives a new token
each time. When the token is 5 minutes from expiring, or a request is
refused with 401, the plugin runs grok models in that home, so the CLI
renews it, then reads it again.
Requests
Requests go to https://cli-chat-proxy.grok.com/v1, OpenAI's Responses
API (@ai-sdk/openai), signed as the CLI signs them:
Authorization: Bearer <token>x-xai-token-auth: xai-grok-clix-grok-client-identifier: grok-shellx-grok-client-mode: headlessx-grok-client-versionandUser-Agent: grok-shell/<version> (<os>; <arch>). The version is 1.0.41, or the installed CLI's if it is newer.x-grok-model-override: the request's model.x-grok-conv-id: the request'sprompt_cache_key.
The backend turns away some of what a request may carry, so the plugin leaves these out:
- tools of types it doesn't take (a freeform
apply_patch, namespaces) external_web_accesson web search- a
tool_choicenaming a dropped type - a reasoning item's
"content": null
Models
Grok 4.7 until signed in. Signed in, the models are the ones the account
lists at /v1/models (Responses models only), each with its context
window and its reasoning efforts as variants.