Grok CLI Cheatsheet - xAI Grok Build Terminal Coding Agent
Grok CLI is xAI's terminal coding agent. Its shape matches the other terminal agents, and the honest reason to reach for it is usually not a feature difference but that you already hold xAI quota or want its retrieval augmentation. This sheet covers installation and authentication, interactive sessions, headless mode for scripts, and subcommands with MCP. Only three things need doing, and order matters: solve authentication first, because the binary is a single Rust executable whose first launch goes through a browser flow, so CI and headless boxes need XAI_API_KEY instead; then pick the run shape, interactive for exploration and -p when you want capturable output in a pipeline; and only then configure models, in the user-level config file rather than on the command line, so the same setup copies across machines. What sets this tool apart from the other terminal agents in this batch is its configuration inspection: the built-in inspect command enumerates the config, skills, hooks and MCP servers discovered for the current directory, which removes most of the guesswork when it appears to be ignoring your setup.
Install & Auth 4
curl -fsSL https://x.ai/cli/install.sh | bashirm https://x.ai/cli/install.ps1 | iexgrok --versionexport XAI_API_KEY="xai-..."Interactive & Sessions 4
grok/modelgrok inspectcat ~/.grok/config.tomlHeadless Mode & Scripts 3
grok -p "Explain this codebase"grok -p "Explain the architecture" --output-format streaming-jsongrok -p "Hello" -m my-modelSubcommands & MCP 16
grok -k <key> / --api-keygrok -u <url> / --base-urlgrok -d <dir> / --directorygrok -s <id> / --sessiongrok --max-tool-rounds <n>grok --sandboxgrok --batch-apigrok --format jsongrok --output-format jsongrok modelsgrok git commit-and-pushgrok mcp add <name>grok mcp add-json <name> <json>grok mcp remove <name>grok mcp listgrok mcp test <name>Tips
- Grok CLI is a single Rust binary; first launch opens a browser to authorize. In browser-less/CI environments, the
XAI_API_KEYenv var runs headless tasks. grok inspectlists the config, skills, hooks, and MCP servers Grok discovered in the cwd — handy when debugging why your config is not picked up.- Custom models live under
[model.my-model]in~/.grok/config.toml; select them in the TUI with/modelor via-m.
FAQ
Is the Grok CLI the same as the community grok-cli (npm) package?
No. This sheet covers xAI official Grok Build CLI (command grok, distributed via the x.ai/cli install script). The npm grok-cli (e.g. airplne/grok-cli) is a third-party community implementation with different commands and config — do not mix them.
How do I use Grok CLI without a graphical browser?
Set the XAI_API_KEY env var and run grok -p "..." for headless tasks — no browser auth needed. Only the interactive TUI requires the first browser OAuth.
Official References
Each command links to its official documentation below, so you can verify the latest usage and read deeper.
Maintained by LaoHand
Publicly updated on Aug 26, 2026, continuously proofread against official docs.
Contact Us
Wrong command or description? Send us corrections, business inquiries or product feedback by email.
Contact Us