# 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.

Source: https://tokenade.net/en/articles/reduce-grok-cli-token-usage · Updated: 2026-10-14

Part of the [reduce AI agent token usage](https://tokenade.net/en/articles/reduce-ai-coding-agent-token-usage) pillar. Comparing terminal agents? The [Qwen Code](https://tokenade.net/en/articles/reduce-qwen-code-token-usage) and [Droid](https://tokenade.net/en/articles/reduce-droid-token-usage) 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](https://docs.x.ai/build/settings) and the [grok-build user guide](https://github.com/xai-org/grok-build/tree/main/crates/codegen/xai-grok-pager/docs/user-guide) on 14 October 2026. Tokenade's figure comes from the open [token optimizer benchmark](https://tokenade.net/en/stats/token-optimizer-benchmark).

> Grok's hooks can't trim tool output. Tokenade's local proxy can: files and logs reach the model folded.
>
> Install: `npm install -g @tokenade/cli && tokenade install` — or let your agent do it: https://tokenade.net/install.md

## 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](https://github.com/xai-org/grok-build/blob/main/crates/codegen/xai-grok-pager/docs/user-guide/24-monitoring-usage.md) 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](https://docs.x.ai/build/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](https://tokenade.net/en) 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](https://tokenade.net/en/docs/compatibility), command output, web search and documents read Partial+ for Grok: full once the [LLM proxy](https://tokenade.net/en/docs/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](https://tokenade.net/agents/grok.md).

On the open [token optimizer benchmark](https://tokenade.net/en/stats/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](https://tokenade.net/en/docs/install) 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:**

- [How to reduce AI agent token usage](https://tokenade.net/en/articles/reduce-ai-coding-agent-token-usage) — the tool-agnostic pillar
- [How to reduce Qwen Code token usage](https://tokenade.net/en/articles/reduce-qwen-code-token-usage) — another terminal agent, other knobs
- [How to reduce opencode token usage](https://tokenade.net/en/articles/reduce-opencode-token-usage) — the BYO-key case
- [Measure agent token usage](https://tokenade.net/en/articles/measure-agent-token-usage) — reading the numbers you collect
