Limit how many tool rounds Grok runs
headless and scripting
// what it does
--max-tool-rounds caps how many tool-execution cycles Grok performs before stopping; the default is 400. Lower it to 10–50 for simple, fast queries and raise it for large multi-step refactors. It applies to interactive, headless, and git subcommands alike.
// shell
$ grok --max-tool-rounds 10 -p "show me the current directory"$ grok --max-tool-rounds 1000 -p "comprehensive refactor of the api layer"// gotcha
The 400 default is generous — an underspecified prompt can loop through many rounds and burn tokens before hitting the cap. In automation, set a low explicit limit as a cost guardrail.