tokenade
Log inenfr
Start free

How to Reduce Grok CLI Token Usage

xAI's Grok Build gives you /context, /compact, a compaction threshold and token budgets on goals. Here's which settings cut the bill, and why its hooks can't trim tool output.

TL;DR — Watch /context, compact earlier with auto_compact_threshold_percent in ~/.grok/config.toml, lower reasoning with /effort, cap long goals with /goal --budget, and start fresh with /new when the task changes. Grok Build's hooks can't rewrite tool output, so trimming files and logs takes an LLM proxy: that's how Tokenade covers it.

Profile photo of Paul Irolla

By Paul Irolla

Founder · AI & developer tools · Tokenade

Ph.D. in AI · builds token-optimization tooling for AI agents

View author page
7 min read
Cite this page

Part of the reduce AI agent token usage pillar. Comparing terminal agents? The Qwen Code and Droid pages cover the same ground. This one is about xAI's Grok Build, the grok command.

How do you reduce Grok CLI token usage?

Check /context as you work, lower auto_compact_threshold_percent so compaction fires earlier, drop reasoning effort with /effort for routine work, cap long autonomous runs with /goal --budget, and start a new session when the task changes. Then deal with tool output, which Grok Build's own hooks cannot shrink.

That last point is the one most guides miss. Grok Build supports hooks, but its PreToolUse hook can only allow or deny a call, and the output of PostToolUse is ignored. Nothing plugged in through hooks can fold a test log before the model reads it. That shapes everything below.

Sources: settings and commands were read in the Grok Build docs and the grok-build user guide on 14 October 2026. Tokenade's figure comes from the open token optimizer benchmark.

Which "Grok CLI" is this page about?

xAI's official Grok Build, installed as grok and configured in ~/.grok/config.toml.

There's also a separate community project, superagent-ai/grok-cli, an open-source agent for the Grok API. It's a different program with different settings. If a tip mentions environment variables that the xAI docs don't list, it was probably written for that one.

Grok Build reads ~/.grok/config.toml (%USERPROFILE%\.grok\config.toml on Windows), or $GROK_HOME/config.toml if you set GROK_HOME. A project's .grok/config.toml only contributes MCP servers, plugins and permission rules. Run grok inspect to see which configs are actually picked up.

Why does Grok Build burn tokens?

Same reason as every agent: each turn re-sends the conversation, and everything the agent read is part of it.

Turn 25 carries turns 1 to 24, every file opened, every shell result, every web page fetched. A big log read early is paid again on each turn until compaction drops it. Grok Build also runs reasoning models, and reasoning tokens are counted too: its OpenTelemetry stream reports reasoning as a token type next to input, output and cache_read.

So the bill has three parts you can act on: what enters the history, how long it stays, and how much the model thinks per turn.

How do you see where Grok Build's tokens go?

/context for the current window, /usage for credits, and OpenTelemetry if you want history.

  • /context shows current context usage. /session-info shows it too, alongside the session details.
  • /usage shows credit usage or manages billing.
  • /goal status shows a running goal's tokens used and time elapsed.
  • OpenTelemetry export sends a grok_code.token.usage metric split by type and model, and a grok_code.compaction event with tokens_before and tokens_after. The monitoring guide notes there's no cost metric: you join tokens with your own price table.

The compaction event is the useful one. It tells you how much each compaction actually reclaimed, which is the number that says whether your threshold is right.

Which built-in settings actually cut the bill?

Four controls, plus one habit.

  1. auto_compact_threshold_percent under [session]. Grok auto-compacts when context usage reaches this percent; the default is 85. Lower it and less history rides along on every turn.
  2. context_window per model. The settings reference says it drives auto-compact timing. On a custom model, set it to the real window, or the threshold is computed against the wrong number.
  3. Reasoning effort. /effort sets it for the current model, and default_reasoning_effort under [models] sets the default. Routine edits rarely need the deepest level.
  4. /goal --budget <tokens>. Goals let Grok work toward an objective on its own. The budget caps the tokens a goal may spend, which is the right guard for anything unattended.

The habit is session hygiene. /compact [context] compresses the history on demand, with optional instructions about what to keep. /new (alias /clear) starts a fresh session. /rewind truncates the conversation back to an earlier prompt, but it also restores files on disk, so commit first.

max_completion_tokens exists too, globally or per model. It caps each response, which guards against a runaway generation but barely moves an agent bill: most of it is input.

Which Grok settings look like savings but aren't?

The ones with "compact" in the name under [ui].

compact_mode gives denser message padding, and tool_call_density (also /density) decides how much of each tool call the transcript shows. Both change what you see in the terminal. Neither changes what the model receives. A folded tool call in your TUI is still sent in full.

Hiding thinking blocks with show_thinking_blocks = false is the same story: it's a display choice. To spend fewer reasoning tokens, lower the effort instead.

What do Grok's settings leave untouched?

Tool output: files, shell results, web pages and documents, at the moment they enter the conversation.

Compaction acts after the fact. By the time it fires, a 3,000-line log has already been re-sent on every turn since it arrived. And because hooks can't rewrite output on Grok Build, a hook-based optimizer can't step in at that moment either.

Tokenade works around it with a local LLM proxy. tokenade install offers it for Grok and points [endpoints] models_base_url in ~/.grok/config.toml at it. The proxy runs on loopback only and folds tool results inside each request before they go to the model API.

Tokenade still uses the hooks Grok honours, SessionStart and PreCompact, writes its rules to ~/.grok/rules/tokenade.md, and wraps your MCP servers. In the compatibility matrix, command output, web search and documents read Partial+ for Grok: full once the LLM proxy is set up. MCP results, code search, context, re-read dedup and secret redaction are covered either way.

Without the proxy, you can still call Tokenade yourself: tokenade wrap '<cmd>', tokenade web <url>, tokenade read <file>. The full brief is at tokenade.net/agents/grok.md.

On the open token optimizer benchmark it cuts session cost by 39% on long sessions against running no tool at all. That campaign ran on Claude Code, not Grok Build: the mechanism is the same, the measurement isn't.

How to apply this today

  1. Run grok inspect to confirm which config.toml is live.
  2. Set auto_compact_threshold_percent under [session] below the default 85, and check context_window on any custom model.
  3. Use /effort to drop reasoning for routine work; keep the high levels for design and debugging.
  4. Give every unattended /goal a --budget.
  5. Watch /context, use /compact with a note on what to keep, and /new when the task changes.
  6. Then fix what enters the chat: install Tokenade and accept the LLM proxy for Grok.

What goes wrong (anti-patterns)

Treating /density as a token setting. It folds the transcript on your screen, not in the request. The bill doesn't move.

Running goals without a budget. An autonomous loop with no ceiling is the fastest way to spend a day's tokens on a task that stalled at step three.

Max effort by default. Reasoning tokens are billed tokens. Paying for deep thought on a rename is a habit, not a requirement.

Rewinding instead of starting over. /rewind restores files too. If you only wanted a clean context, /new is safer.

FAQ

How do I check token usage in Grok CLI?

In Grok Build, /context shows current context usage and /usage shows credit usage. For a goal, /goal status reports tokens used. For history across sessions, enable the OpenTelemetry export: it emits a grok_code.token.usage metric split by input, output, reasoning and cache reads, per model.

How do I make Grok Build compact earlier?

Set auto_compact_threshold_percent under [session] in ~/.grok/config.toml. Grok auto-compacts when context usage reaches that percent; the default is 85. On a custom model, also set context_window correctly, since it drives auto-compact timing. You can compact by hand at any point with /compact, optionally saying what to preserve.

Can Grok Build hooks reduce token usage?

Not on tool output. Grok's PreToolUse hook can only allow or deny a call, and PostToolUse output is ignored, so no hook can rewrite what a tool returns. Hooks can still act at session start and before compaction. Trimming output itself needs something in the request path, such as a local LLM proxy.

Does /compact-mode save tokens?

No. /compact-mode and the compact_mode setting only make the TUI layout denser, and /density only changes how much of each tool call you see. The model still receives every tool result in full. To reduce what's sent, compact the history with /compact or trim tool output before it enters.

Is Tokenade fully compatible with Grok?

Mostly. MCP results, code search, context, re-read dedup and secret redaction work out of the box. Command output, web search and documents are Partial+: they need Tokenade's local LLM proxy, which tokenade install offers for Grok, because Grok's hooks can't rewrite output. Without the proxy, call tokenade wrap, web or read yourself.


See also:

FAQ

Cut your AI agent's token bill.

Ranked #1 on the Token-Harness Optimizer Leaderboard. Zero config.

Tokenade cuts the token bill of AI agents: one install, zero config, and it trims what your agent sends to the model.