Select Your Operating System
Commands and environment variables update instantly to match your target shell.
Verify Python Runtime & Package Installer
Grok Build CLI requires Python 3.10 or higher with pip package management.
Check Installed Python Version
Open your terminal and confirm your Python version and pip availability:
brew install python@3.11 on macOS).
Paste the exact output of your Python version command below (e.g. Python 3.11.4):
Install Grok Build CLI Package
Install the xAI Grok CLI package and verify that the executable is located in your system PATH.
Install via Package Manager
Install the official Grok CLI package and inspect its version:
grok, ensure your Python Scripts or ~/.local/bin directory is included in your system PATH variable.
Paste the output of grok --version to verify binary installation:
Configure xAI API Authentication
Generate an API key in the xAI Console and store it in your environment variables.
Set Persistent XAI_API_KEY
Generate a key starting with xai- at console.x.ai and save it in your shell environment:
console.x.ai and require prepaid credits separate from X social media subscriptions.
Paste your API key prefix (e.g. xai-...) or the confirmation text showing key is active:
Interactive Terminal Session & Repo Context
Launch an interactive Grok session inside your repository and explore codebase context indexing.
Start Interactive Grok Session
Launch Grok interactive mode inside your project workspace:
/help inside the session to view commands, /model grok-2-mini to switch to low-latency mode, and /exit to quit.
Paste the interactive session banner or prompt confirming active connection:
Non-Interactive Execution & STDIN Piping
Execute single-shot prompt queries and pipe repository files directly into Grok for automated code quality reviews.
Run Single Query & Pipe File Content
Pass queries directly or stream file contents through standard input:
Paste the response generated by your grok prompt command:
Default Configuration & Run It Later Card
Lock in persistent model defaults and save the quick reference card for daily terminal development.
Set Default Model Preferences
Configure your preferred default model and inspect configuration settings:
Paste the output of grok config list showing your saved preferences:
⚡ Run It Later — Quick Reference
grok chat --model grok-2
Starts interactive conversation with deep codebase reasoning
grok prompt --model grok-2-mini "lint"
Low-latency model for rapid audits and cost savings
cat src/main.py | grok prompt "Refactor"
Streams code directly into Grok prompt for terminal reviews
grok --context . "Find memory leaks"
Scans entire repository structure respecting .gitignore