Token-Aware Formatting
Remove unnecessary whitespace, comments, or metadata. Use shorter variable names in code contexts. Avoid repeating system instructions on every turn if the provider supports prompt caching.
How It Works
The prompt is formatted to minimize token count without changing semantic meaning. Techniques include stripping redundant whitespace, abbreviating identifiers, removing boilerplate comments, and deduplicating repeated instructions.
Techniques
- Whitespace minimization: collapse multiple newlines and spaces.
- Identifier shortening: use short variable names in code sent to the model.
- Comment stripping: remove explanatory comments the model does not need.
- Instruction deduplication: cache system prompts instead of repeating them.
- Tool-output artifact removal: strip formatting that the harness adds to tool results but nothing downstream consumes — line-number prefixes on file reads, ANSI color codes, progress bars, box-drawing tables, repeated headers.
Tool-Output Artifacts
Tool results are formatted once by the harness and then re-sent on every later turn, so any decoration in them is paid for repeatedly. Some of it was once load-bearing and outlived its purpose: GitHub Copilot's agent prefixed every line of a file read with its line number, a convention from an older edit tool that addressed lines by number. The current edit tools match on text, so the prefixes were pure overhead. Removing them cut model-inference cost by about 5% offline and 3% online, with no change in edit success rate (GitHub blog, 2026).
The audit question for every piece of tool-output formatting: which tool or instruction reads this? If the answer is none, drop it. Keep only what the model uses to act — a line number is worth its tokens if the edit tool takes line numbers, not otherwise.
Command-line tools have the same problem at the source: git, ls, test runners, and package managers print for humans. A proxy that rewrites their output into a compact form before it reaches the model applies this technique without changing the agent — see rtk below.
Trade-offs
- Pros: fast; deterministic; no extra model calls.
- Cons: can hurt readability for humans; may remove contextual cues the model uses.
When to Use
Best for code-heavy prompts where the model needs the logic, not the presentation. Less useful for natural-language tasks where tone and structure matter.
See Also
- Prompt Caching — caching is the preferred way to avoid repeating instructions.
- Signal-per-Token Optimization — token-aware formatting improves signal density.
- Model-Migration Prompt Pruning — a different kind of waste: stale instructions, not whitespace/boilerplate.
- Meta-prompting — removes semantic redundancy in instructions, which needs a model and tests rather than a deterministic rewrite.
- Output Spooling to Disk — when a command cannot be told to say less, redirect it and read a slice.
Tools
- tiktoken — tokenizer for measuring the impact of formatting changes.
- rtk — CLI proxy that filters and compresses output of common dev commands (git, ls, test runners) before it reaches the model; claims 60–90% reduction of raw command output.
- OpenAI prompt caching — avoids repeating stable instructions on every turn.