/grok-cli:grok-clifrom grok-cli
Provides a local CLI wrapper for Grok/xAI using browser OAuth (no API key needed). Supports chat, image/video generation via Grok Imagine, and X/Twitter search with persistent SQLite session history.
Ships in grok-cli. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Use this skill when the user or an agent needs a local CLI wrapper around Grok/xAI with:
XAI_API_KEY fallback./v1/responses chat calls.x_search Responses tool.Never ask the user to paste their xAI password. Use grok-cli login to open the xAI authorization URL in a browser. Do not scrape browser cookies, automate grok.com, or capture interactive login credentials. OAuth tokens are stored locally under ~/.grok-cli/auth.json with owner-only file permissions when supported by the OS.
Prefer OAuth for SuperGrok users. API keys are supported only as fallback through XAI_API_KEY or grok-cli key set.
Do not print access tokens, refresh tokens, API keys, or ID tokens. grok-cli status sanitizes credential output.
Image and video generation are paid xAI operations (≈ $0.02 / image,
≈ $0.40 / 8s video — video is ~20x an image). The CLI refuses paid generation
in non-interactive mode unless --yes is passed; never auto-pass --yes for an
agent without the user's intent. No credentials are bundled in this package —
each user logs in with their own SuperGrok / X Premium account via
grok-cli login.
From the skill folder:
python -m venv .venv
source .venv/bin/activate
pip install -e .
Smoke test without network:
grok-cli --help
grok-cli status
Local machine with browser:
grok-cli login
Remote SSH/container session:
# On your local machine, in a separate terminal:
ssh -N -L 56121:127.0.0.1:56121 user@remote-host
# On the remote host:
grok-cli login --no-browser
# Open the printed URL locally.
Alternative API key fallback:
export XAI_API_KEY="..."
# or store locally:
grok-cli key set
# Single-turn chat, saved to current/default session
grok-cli ask "What is the meaning of life?"
# Interactive chat
grok-cli chat -s research
# Image generation (Grok Imagine, sync) — paid, needs --yes
grok-cli image "a neon cyberpunk fox, sticker art" --yes -o fox.jpg -n 2
# Video generation (Grok Imagine, async poll) — paid ~20x an image, needs --yes
grok-cli video "a paper plane gliding over a city at sunset" --yes -o plane.mp4
grok-cli video --fetch <request_id> --json # check an existing job
# X Search via Grok server-side x_search
grok-cli search "What are people on X saying about the latest xAI algorithm update?" --save
# Limit search to handles
grok-cli search "Grok image feature reactions" --allowed xai elonmusk --from 2026-05-01
# Enable image/video understanding for matching posts
grok-cli search "Show visual reactions to Grok features" --images --videos
# Sessions
grok-cli session new ai-market --use
grok-cli session list
grok-cli session use thesis
grok-cli session export ai-market -o ai-market.md
# Summarize long session for future compact context
grok-cli summarize -s ai-market
For Codex or another agent, call the CLI rather than importing internals unless you need a custom integration.
Preferred machine-readable calls:
grok-cli ask "<prompt>" --session "<session>" --json
grok-cli search "<query>" --allowed xai --from 2026-05-01 --json --save
grok-cli status
JSON responses include the response id, model, answer, citations, inline citations, status, and usage where available.
Default local state:
~/.grok-cli/
auth.json # OAuth/API-key credential state, sanitized by status output
config.json # base_url, default_model, search_model, current_session
sessions.sqlite3 # sessions, messages, citations, summaries
Set GROK_CLI_HOME=/path/to/state to isolate state for tests or a specific agent workspace.
grok-cli login uses the xAI OIDC discovery document and Authorization Code + PKCE.xai-oauth.tools: [{"type":"x_search"}] to /v1/responses, matching Hermes' documented behavior./v1/responses, response ids, retrieval, deletion, and server-side response storage. This skill defaults to store:false for data-sovereignty reasons.x_search returns a provider/model error, switch search_model to grok-4.20-reasoning or another model with x_search entitlement.No xAI credentials available: run grok-cli login, set XAI_API_KEY, or use grok-cli key set.state_mismatch: rerun login; do not reuse old authorization URLs.invalid_grant or refresh failure: run grok-cli login again.x_search not enabled for this model/account: verify that your SuperGrok account has access and try grok-cli config set search_model grok-4.20-reasoning.This package is based on public behavior documented by Hermes Agent and xAI docs, not on private credentials or browser-cookie scraping. See docs/sources.md for references.
CHANGELOG.md (opens in a new tab)LICENSE (opens in a new tab)README.md (opens in a new tab)docs/architecture.md (opens in a new tab)docs/oauth_notes.md (opens in a new tab)docs/sources.md (opens in a new tab)docs/troubleshooting.md (opens in a new tab)examples/agent_usage.md (opens in a new tab)examples/codex_prompt.md (opens in a new tab)grok_cli/__init__.py (opens in a new tab)grok_cli/__main__.py (opens in a new tab)grok_cli/auth.py (opens in a new tab)grok_cli/cli.py (opens in a new tab)grok_cli/client.py (opens in a new tab)grok_cli/config.py (opens in a new tab)grok_cli/constants.py (opens in a new tab)grok_cli/paths.py (opens in a new tab)grok_cli/sessions.py (opens in a new tab)grok_cli_tool_manifest.json (opens in a new tab)pyproject.toml (opens in a new tab)What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
grok-cli, xai, oauth-login, image-generation, twitter-search
npx claudepluginhub yrzhe/claude-skills --plugin grok-cliOther plugins' skills for the same job