Skip to content

Grok Build CLI — advanced ​

Advanced Permissions, headless automation, plugins, MCP, worktrees, sandbox. Easy to misuse.

Verified against Grok Build 0.2.112 (grok --help). Re-check flags on your build. Starter guide: Grok Build.

Not a daily default

Do not make --always-approve or --permission-mode bypassPermissions your everyday host workflow. Prefer interactive approval, allow/deny rules, acceptEdits / auto / plan, and sandbox profiles first.

Safer alternatives first ​

GoalPreferAvoid as default
Fewer edit prompts while you watch--permission-mode acceptEditsFull bypass / always-approve
Explore before edits--permission-mode plan or interactive plan modeSilent write access
CI / locked scriptsdontAsk + --allow / --tools allowlistsOpen --always-approve on shared runners with secrets
Isolation--sandbox <profile> (GROK_SANDBOX)Unrestricted shell on host with prod keys
One-shot analysisgrok -p "…" + narrow toolsBroad tools + always-approve
Parallel feature workgrok -w name / grok worktreeDirty main + auto-approve

Permission modes ​

bash
grok --permission-mode default
grok --permission-mode acceptEdits
grok --permission-mode plan
grok --permission-mode auto
grok --permission-mode dontAsk
grok --permission-mode bypassPermissions
ModeRough intent
defaultAsk when needed (baseline)
acceptEditsFewer prompts for file edits
planPlan / explore-oriented
autoMore autonomous (still respect deny rules)
dontAskNo prompts — only pre-approved / allowed surface
bypassPermissionsNear-full auto (high risk)

Always-approve ​

bash
grok --always-approve -p "run tests and fix failures"

Treat like Claude’s dangerously-skip / bypass: throwaway environments, not daily on a machine with client secrets.

Allow / deny / tools ​

bash
# Permission rules (compat aliases exist for Claude-style names)
grok --allow <RULE>
grok --deny <RULE>
grok --allow '…' --deny '…'

# Built-in tool inventory
grok --tools <comma-separated>              # allow only these
grok --disallowed-tools <comma-separated>   # remove built-ins

Compat aliases from --help: --allowedTools ≈ allow path; --disallowedTools ≈ deny path — confirm with your version’s help text.

Headless & scripting ​

bash
# Single turn
grok -p "Summarize public modules"
grok --prompt-file ./prompts/task.md
grok --prompt-json '…'                      # content blocks as JSON

# Output for automation
grok -p "…" --output-format plain           # default
grok -p "…" --output-format json
grok -p "…" --output-format streaming-json

# Structured JSON (implies json output)
grok -p "…" --json-schema '{"type":"object","properties":{"ok":{"type":"boolean"}}}'

# Limits / control
grok -p "…" --max-turns 20
grok -p "…" --no-subagents
grok -p "…" --no-plan
grok -p "…" --verbatim                      # send prompt exactly
grok -p "…" --rules "Never touch prod secrets"
grok -p "…" --system-prompt-override "You are a code reviewer…"

# Subcommand without TUI
grok agent -p "…"

Env / cwd:

bash
grok --cwd /path/to/repo -p "…"
export GROK_SANDBOX=…                       # see sandbox below

Official: Headless & scripting.

Sandbox ​

bash
grok --sandbox <PROFILE>
# or
export GROK_SANDBOX=<PROFILE>
grok

Profiles gate filesystem/network access depending on version. Prefer sandbox for untrusted tasks and CI. Confirm available profiles with grok --help / docs for your build.

Sessions ​

bash
grok -c                                     # continue most recent for cwd
grok -r                                     # resume latest
grok -r <session-id-or-title>
grok --fork-session -r <id>                 # fork on resume
grok -s <uuid>                              # new session with fixed UUID
grok --restore-code -r <id>                 # checkout original session commit when resuming

grok sessions                               # list / search / restore
grok export                                 # transcript → Markdown
grok trace                                  # export/upload trace data

Worktrees ​

bash
# New worktree session
grok -w                                     # auto-named
grok -w feat/login "implement login"
grok -w feat/login --worktree-ref main "…"

# Manage worktrees
grok worktree --help

Pairs well with Git worktrees.

Subagents ​

bash
grok --agent <name-or-definition-path>
grok --agents '<json>'                      # inline subagent definitions
grok --no-subagents                         # disable spawning

TUI also exposes agent config (e.g. /config-agents on recent builds — verify in your TUI).

Plugins & marketplaces ​

bash
grok plugin --help
# manage plugins and marketplace sources (install/list/update — see help)

Skills / plugins docs: docs.x.ai — Skills, Plugins & Marketplaces.

Cross-agent skills you author: apsolut-skills.

MCP ​

bash
grok mcp --help
# configure / list / manage MCP servers for Grok Build

Memory ​

bash
grok --experimental-memory                  # enable cross-session memory
grok --no-memory                            # force off for this session
grok memory --help

Models & reasoning ​

bash
grok models
grok -m <model-id> -p "…"
grok --reasoning-effort <level> -p "…"      # alias: --effort

Custom OpenAI-compatible endpoints: ~/.grok/config.toml [model.*] blocks — then grok inspect / -m.

Inspect & doctor ​

bash
grok inspect                                # config, instructions, skills, plugins, hooks, MCP for cwd
grok doctor                                 # terminal, clipboard, color, input
grok doctor --json
grok doctor fix                             # apply automatic fixes when available

Inside TUI, /doctor consolidates diagnostics on recent versions.

UI modes ​

bash
grok --fullscreen                           # force fullscreen TUI this session
grok --minimal                              # scrollback-native experimental UI
grok --no-alt-screen                        # inline instead of alt-screen
grok dashboard                              # Agent Dashboard view

Persist UI prefs in ~/.grok/config.toml under [ui] (e.g. screen_mode = "minimal") — session flags do not always write config.

bash
grok --disable-web-search -p "…"            # no web search / fetch tools

Completions & leader ​

bash
grok completions bash
grok completions powershell
grok leader --help                          # manage leader processes / socket
# custom leader socket:
grok --leader-socket ~/.grok/leader.sock …

Debug ​

bash
grok --debug
grok --debug-file ./grok-debug.log

CI-shaped example ​

bash
cd "$REPO"
git switch -c "ci/agent-$(date +%s)"

grok -p "Run unit tests; fix only failing assertions; do not change CI config" \
  --permission-mode dontAsk \
  --max-turns 30 \
  --no-subagents \
  --output-format json \
  --deny '…' \
  --tools '…'   # narrow if your version supports an allowlist

Still: no prod secrets in the tree, prefer ephemeral runners, review the diff before merge.

Privacy & trust ​

Coding agents may send file contents and prompts to the vendor to run the model. Treat that as a trust decision:

  1. Prefer clean worktrees without .env secrets (direnv / secret managers).
  2. Review product privacy / data-use toggles in account settings when available.
  3. For highly sensitive client code, use offline policy / sandbox / approved enterprise paths only.
  4. Re-read current xAI / Grok Build docs — upload and retention behavior can change by version.

Community reports have discussed whole-repo upload behavior on some CLI versions; verify on your build rather than assuming. When in doubt, isolate repos and credentials.

Cheat sheet (high signal) ​

Flag / commandRole
-p / --singleHeadless one-shot
--output-formatplain | json | streaming-json
--permission-modedefault → bypass
--always-approveAuto-approve tools (⚠)
--allow / --denyPermission rules
--tools / --disallowed-toolsBuilt-in tool inventory
-w / --worktreeSession in new git worktree
-c / -rContinue / resume sessions
--sandbox / GROK_SANDBOXFS/network profile
--max-turnsCap agent turns
--no-subagentsNo child agents
grok inspectDiscovery dump for cwd
grok doctorEnvironment diagnostics
grok plugin / grok mcpExtensibility
grok modelsList models

Official docs ​