> headless and scripting

Pass -p (--prompt) to run a single prompt and exit without the UI — the mode for scripts, CI, and benchmarks. --max-tool-rounds bounds how much work Grok does (default 400), and grok git commit-and-push wraps the AI commit workflow as a one-shot subcommand.

// headless and scripting

4 commands

// faq

How do I run Grok non-interactively?

Use grok -p "your prompt" (long form --prompt). It processes the prompt, prints the result, and exits. Combine it with -d to set the project directory and --max-tool-rounds to cap the work for predictable cost.

What is --max-tool-rounds and what is the default?

It limits how many tool-execution cycles Grok runs before stopping; the default is 400. Lower it to 10–50 for simple queries to keep runs fast and cheap, and raise it only for large multi-step refactors.

Will headless mode edit my files without asking?

Yes. Headless mode still runs the write, edit, and bash tools with no confirmation prompt, so a prompt like "fix the failing test" changes your working tree unattended. Scope prompts tightly and run on a branch, especially in CI.

Can Grok write and push a git commit for me?

grok git commit-and-push stages changes, generates a commit message from the diff, and pushes; /commit-and-push does the same from inside a session. It accepts -d, -m, and --max-tool-rounds, and it pushes without confirmation, so use a feature branch.