A terminal UI for xAI's Grok models. Interactive chat, streaming responses, live web search, slash commands, and full CLI options — all from your terminal.
Built with Python, talking directly to the xAI API (no OpenAI compatibility wrapper).
- Streaming responses with live-updating Markdown rendering
- xAI Live Search — toggle real-time web data in responses (
/search) - Reasoning display — see Grok's thinking process on mini models (
/reasoning) - Slash commands — 16 built-in commands for controlling the session
- One-shot mode — pipe prompts or pass them inline
- Conversation management — history, export, compact (AI-summarized)
- Rich terminal output — syntax highlighting, markdown, panels
- Tab completion — slash commands auto-complete
- Input history — arrow keys recall previous prompts (persisted across sessions)
- Configurable — model, temperature, max tokens, system prompt, all adjustable at runtime
- Python 3.10+
- xAI API key — get one at console.x.ai
Note: This uses the xAI API, which is separate from a SuperGrok subscription. API usage is billed per-token at x.ai/api/pricing.
git clone https://github.com/Norlem/grok-cli.git
cd grok-cli
python3 -m venv .venv
source .venv/bin/activate
pip install -e .pip install git+https://github.com/Norlem/grok-cli.gitgrok --initThis walks you through:
- Entering your xAI API key
- Choosing a default model
- Enabling/disabling live web search
Settings are saved to ~/.grok-cli/config.json.
Alternatively, set your API key as an environment variable:
export XAI_API_KEY="xai-your-key-here"Add this to your ~/.zshrc or ~/.bashrc to persist it.
grokThis opens the interactive TUI. Type messages, use slash commands, and chat with Grok.
Pass a prompt directly — Grok responds and exits:
# Inline argument
grok "what is the mass of the sun?"
# With the -p flag
grok -p "explain quantum entanglement in simple terms"
# With options
grok -m grok-3-mini --search "latest SpaceX launch news"
# Pipe from stdin
echo "summarize this error log" | grok
cat error.log | grok -p "what went wrong?"| Option | Short | Description |
|---|---|---|
--model TEXT |
-m |
Model to use (default: grok-3) |
--system TEXT |
-s |
Set the system prompt |
--temperature FLOAT |
-t |
Temperature 0.0–2.0 (default: 0.7) |
--max-tokens INT |
Max response tokens (default: 4096) | |
--search / --no-search |
Enable/disable live web search | |
--stream / --no-stream |
Enable/disable streaming | |
--tokens / --no-tokens |
Show token usage after responses | |
--reasoning [low|medium|high] |
Reasoning effort for mini models | |
--prompt TEXT |
-p |
One-shot prompt (non-interactive) |
--api-key TEXT |
xAI API key (overrides config/env) | |
--init |
Run interactive setup | |
--models |
List available models and exit | |
--help |
-h |
Show help |
All commands work in interactive mode. Type /help to see them at any time.
| Command | Aliases | Description |
|---|---|---|
/help |
/h, /? |
Show all available commands |
/model [name] |
/m |
Switch model or list available models |
/system [prompt] |
/sys |
Get or set the system prompt |
/temperature [val] |
/temp, /t |
Get or set temperature (0.0–2.0) |
/search |
/live |
Toggle xAI live web search |
/reasoning [level] |
/reason, /think |
Set reasoning effort: low, medium, high, off |
/tokens |
/usage |
Toggle token usage display |
/stream |
Toggle streaming on/off | |
/maxtokens [n] |
/max |
Get or set max response tokens |
/history |
/hist |
Show conversation message count and previews |
/compact |
AI-summarize the conversation to save context | |
/export [file] |
/save |
Export conversation to a JSON file |
/config |
/settings |
Show all current settings |
/save-config |
/sc |
Save current settings to ~/.grok-cli/config.json |
/clear |
/c |
Clear conversation history |
/exit |
/quit, /q |
Exit grok-cli |
| Model | Best for |
|---|---|
grok-3 |
Most capable, complex tasks |
grok-3-fast |
Faster grok-3 responses |
grok-3-mini |
Lightweight, supports reasoning effort |
grok-3-mini-fast |
Fastest mini responses |
grok-2 |
Previous generation |
Switch models at any time:
/model grok-3-mini
Or list what's available from xAI:
/model
Grok can search the web in real-time — unique to xAI's API. Toggle it:
/search
Or enable from the command line:
grok --search "who won the game last night?"When enabled, Grok will pull live data from the web to inform its responses.
For mini models, you can control how much "thinking" Grok does before responding:
/reasoning high
Options: low, medium, high, off
When reasoning is active during streaming, you'll see a "thinking" indicator before the response appears.
Long conversations eat context. The /compact command asks a fast model to summarize the entire conversation, replacing it with a 2-message summary:
/compact
This keeps the essential context while freeing up token budget.
Settings are stored in ~/.grok-cli/config.json:
{
"api_key": "xai-...",
"model": "grok-3",
"temperature": 0.7,
"max_tokens": 4096,
"system_prompt": "You are Grok, a helpful AI assistant built by xAI.",
"stream": true,
"live_search": false,
"show_tokens": false,
"theme": "monokai",
"save_conversations": true,
"max_history_messages": 100,
"reasoning_effort": ""
}Edit directly or use /save-config to persist runtime changes.
Prompt history (arrow key recall) is saved to ~/.grok-cli/prompt_history.
# Quick question
grok "how do I reverse a linked list in Rust?"
# Use the mini model for fast answers
grok -m grok-3-mini-fast "what's 2+2?"
# Research with live search
grok --search "summarize today's tech news"
# Code review from a file
cat main.py | grok -s "You are a senior code reviewer." -p "review this code"
# Low temperature for deterministic output
grok -t 0.1 -p "translate 'hello world' to Japanese, Korean, and Mandarin"
# Interactive with custom system prompt
grok -s "You are a Socratic tutor. Answer questions with questions."| Key | Action |
|---|---|
Enter |
Send message |
Up/Down |
Navigate prompt history |
Tab |
Auto-complete slash commands |
Ctrl-C |
Cancel current response / interrupt |
Ctrl-D |
Exit |
MIT