Grok CLI Cheatsheet - xAI Grok Build Terminal Coding Agent

All Grok CLI terminal coding-agent commands in one place — from install & auth to interactive/headless mode, project analysis to model switching — organized by scenario. Copy and go.

AI CLI·11 commands·Last updated 2026-08-26

Install & Auth 4

curl -fsSL https://x.ai/cli/install.sh | bash
One-line install for macOS/Linux/WSL
irm https://x.ai/cli/install.ps1 | iex
Install on Windows via PowerShell
grok --version
Print the installed version
export XAI_API_KEY="xai-..."
Authenticate with an API key in browser-less envs

Interactive & Sessions 4

grok
Start an interactive session in the project dir (browser auth on first run)
/model
Switch the model inside the TUI
grok inspect
Discover config, instructions, skills, hooks, MCP in the cwd
cat ~/.grok/config.toml
View/edit user-level model and endpoint config

Headless Mode & Scripts 3

grok -p "Explain this codebase"
Run headless, print, then exit
grok -p "Explain the architecture" --output-format streaming-json
Stream JSON output for parsing
grok -p "Hello" -m my-model
Run with a custom model

Tips

  • Grok CLI is a single Rust binary; first launch opens a browser to authorize. In browser-less/CI environments, the `XAI_API_KEY` env var runs headless tasks.
  • `grok inspect` lists 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 `/model` or 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

Edit this page on GitHub

Edit the source file directly and open a PR to improve this cheatsheet.