Grok Agent
Integrate xAI's Grok CLI with Ralph TUI for AI-assisted coding.
Grok Agent
The Grok agent plugin integrates with xAI's official grok CLI (Grok Build TUI) to execute AI coding tasks. It supports streaming JSONL output for subagent tracing and uses single-turn mode for non-interactive operation.
Grok supports subagent tracing via streaming-json output — Ralph TUI can show tool calls in real-time as Grok works.
Prerequisites
Install the official Grok CLI from xAI and ensure it is on your PATH (typically ~/.grok/bin or ~/.local/bin):
Authenticate via OAuth (SuperGrok / xAI account) — no API key is required:
Basic Usage
Run with Grok
Use the --agent grok flag:
Select a Model
Override the model with --model or agent options:
List available models:
Verify with Doctor
Configuration
Shorthand Config
The simplest configuration:
Full Config
For advanced control:
Options Reference
| Option | Type | Default | Description |
|---|---|---|---|
model | string | - | Grok model ID (e.g., grok-4.5). Leave empty for default. |
timeout | number | 0 | Execution timeout in ms (0 = no timeout) |
command | string | "grok" | Path to Grok CLI executable |
Subagent Tracing
Grok emits structured NDJSON via --output-format streaming-json (always enabled). Ralph TUI parses this to display:
- Text response deltas from the model
- Tool invocations (
tool_callwith name and input) - Tool completions (
tool_call_updatewith status completed/failed) - Error messages from failed operations
Enabling Tracing
Or toggle in TUI:
- Press
tto cycle through detail levels - Press
T(Shift+T) to toggle the subagent tree panel
How It Works
When Ralph TUI executes a task with Grok:
- Build command: Constructs
grok --always-approve --output-format streaming-json --prompt-file /dev/stdin [options] - Pass prompt via stdin: Uses
--prompt-file /dev/stdin(Grok does not read bare stdin) so the prompt is not shell-escaped - Stream output: Captures stdout/stderr in real-time
- Parse JSONL: Extracts structured tool call data and text deltas
- Detect completion: Watches for process exit
- Handle exit: Reports success, failure, or timeout
CLI Arguments
Ralph TUI builds these arguments:
--always-approve— auto-approve tool executions--output-format streaming-json— structured NDJSON for parsing--prompt-file /dev/stdin— read the prompt from stdin (Unix)--model— only present when a model is configured
On Windows, the prompt is passed with -p instead of --prompt-file /dev/stdin.
--always-approve is required for Ralph TUI's autonomous workflow. Do not confuse this with other CLIs' --dangerously-skip-permissions flag — Grok uses its own flag name.
Troubleshooting
| Issue | Fix |
|---|---|
Grok CLI not found in PATH | Install the official CLI and add ~/.grok/bin to PATH |
| Preflight fails / no output | Run grok -p "hello" --always-approve and check auth with grok login |
| Auth errors | Ensure ~/.grok/auth.json exists; re-run grok login |
| Wrong output format errors | Must use streaming-json (not stream-json) |
| Model not found | Run grok models and set a listed model ID |
Next Steps
- Plugins Overview — How agent plugins work
- Configuration — Full config reference
- Running Ralph — Start an agent loop