Headless & Agent Mode

Run Grok from scripts (headless) or inside editors (ACP)—after you can already ship in the normal screen.

Required: finish a game or app walkthrough first
When you need this

Finish a ship walkthrough in the normal Grok screen first. Headless and ACP build on that skill—they do not replace learning chat + tools + verify.

Two modes outside the normal screen

1

Headless

grok -p "…" — one prompt (or a script). Tools may run. Grok prints text/JSON and exits.

2

Agent mode (ACP)

A long-running process your editor talks to. Example: grok agent stdio.

Headless flags (ideas that stay useful)

Grok Build is still Beta—flag names can change. Check grok --help or /docs before you rely on one. These ideas stay useful even if a name shifts:

NeedTypical flag / idea
One-shot prompt-p / --single
Machine-readable output--output-format json or streaming-json
Skip prompts (trusted CI)--always-approve / --yolo
Cap runaway loops--max-turns N
Limit tools--tools allowlist / --disallowed-tools denylist
Working directory--cwd
Extra rules text--rules "…"
Sandbox profile--sandbox workspace|read-only|strict
Session continuity-c continue / -r resume
CI hygiene--no-auto-update
Feature offsoptional “turn off subagents / memory” flags when your version lists them
cd ~/projects/my-app
grok -p "Summarize what this repo does in 5 bullets" --output-format plain

# CI-shaped sketch (tighten deny + sandbox in real pipelines)
grok -p "Review git diff for security issues" \\
  --output-format json \\
  --always-approve \\
  --max-turns 12 \\
  --no-auto-update

Agent mode (ACP)

grok agent --always-approve stdio
# or serve over a local port when your client needs it

Your IDE extension starts this process. Daily product building still uses interactive grok unless you live in an ACP client.

Automation safety stack

  • API key auth for non-browser environments
  • Always-approve only with deny rules + sandbox + max-turns
  • Never log secrets in prompts that CI archives
  • Prefer read-only tool sets for review jobs

Lab

  1. From a throwaway folder, run a headless summarize prompt (no YOLO required if read-only).
  2. Re-run with --output-format json and open the JSON in a text editor—find the main text field.
  3. Write which three flags you’d lock for a real CI review job.
Done when

You can run grok -p successfully and name max-turns, output format, and always-approve as intentional choices—not defaults you ignore.

Quick check

1. Headless mode is for…
2. For trusted automation, always-approve should come with…