Grok CLI Cheatsheet - xAI Grok Build Terminal Coding Agent
Grok CLI is the xAI Grok Build terminal AI coding agent, for developers who want to code, analyze projects, and run scripts with xAI Grok models in the terminal. It authenticates with XAI_API_KEY, offers grok inspect to review context/config, and its -p headless mode plugs into scripts. This sheet covers install, sessions, headless execution, and project analysis.
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-modelTips
- 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