Skip to content

Norlem/grok-cli

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

grok-cli

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).


Features

  • 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

Prerequisites

Note: This uses the xAI API, which is separate from a SuperGrok subscription. API usage is billed per-token at x.ai/api/pricing.


Installation

From source (recommended)

git clone https://github.com/Norlem/grok-cli.git
cd grok-cli
python3 -m venv .venv
source .venv/bin/activate
pip install -e .

Quick install

pip install git+https://github.com/Norlem/grok-cli.git

Setup

Interactive setup

grok --init

This walks you through:

  1. Entering your xAI API key
  2. Choosing a default model
  3. Enabling/disabling live web search

Settings are saved to ~/.grok-cli/config.json.

Environment variable

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.


Usage

Interactive mode

grok

This opens the interactive TUI. Type messages, use slash commands, and chat with Grok.

One-shot mode

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?"

CLI Options

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

Slash Commands

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

Available Models

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

xAI-Specific Features

Live Web Search

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.

Reasoning (Extended Thinking)

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.

Conversation Compaction

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.


Configuration

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.


Examples

# 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."

Keyboard Shortcuts

Key Action
Enter Send message
Up/Down Navigate prompt history
Tab Auto-complete slash commands
Ctrl-C Cancel current response / interrupt
Ctrl-D Exit

License

MIT

About

A terminal UI for xAI's Grok models — streaming, live search, slash commands, one-shot mode

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages