Cut Token Use by Compressing Terminal Output for AI Coding Assistants
Long terminal logs from commits, tests, and builds consume tokens and crowd out useful context. This article explains a two-layer approach—noise filtering plus templated results—and how to apply it with reusable config packs or a single prompt.
When using an AI coding assistant, one often-overlooked cost is raw terminal output. A single commit, test run, or build can produce hundreds or thousands of log lines. Those lines are fed into the model’s context window, burning tokens and crowding out space that should be used for reasoning. This article covers a general problem: how to make an AI coding assistant say less and report only what matters in terminal workflows, with a complete configuration approach and a practical plan.
1. Why terminal output dominates token use
A typical loop is: receive an instruction, run a command, read the output, then analyze and reply. The problem is the “read the output” step.
Raw logs have very low information density. A dependency install may print dozens of download-progress lines. A test run may print a full stack for every case. What the model usually needs is only success or failure, plus a short reason for failure.
The context window is scarce. Once long output enters the context, it keeps occupying space. After several turns, earlier goals can be diluted or truncated, and the assistant “forgets” the task.
Cost and stability both suffer. Where tokens are billed by volume, redundant output becomes a direct cost. Very long context also slows responses and raises the chance of mistakes.
The direction is clear: slim the information down before it reaches the model.
2. Core approach: filter, then template
A widely accepted way to optimize terminal output has two stages.
Noise filtering
This layer identifies and drops low-value output. Common tactics include:
- Compress progress output: Keep only the final result of download bars, percentage refreshes, and similar noise.
- Deduplicate repeated lines: Collapse consecutive identical warnings or log lines into one line and note the count.
- Trim redundant fields: For example, shorten full hashes in version-control output to short hashes.
- Drop non-critical levels: Discard DEBUG and INFO by default; keep WARN, ERROR, and the final conclusion.
Result templating
After filtering, format what remains with a fixed template so the model always reads a familiar shape and spends less effort parsing it. A typical template looks like this:
[Command] test[Status] Failed (2/48 cases failed)[Key details]- test_login: assertion timed out, expected 200, got 401- test_cache: connection refused[Suggestion] Check the auth service and the cache port configuration
Templating makes length predictable and structure stable. The model does not have to hunt for the point in messy text, so replies are faster and more accurate.
3. Ready to use: presets and config packs
Writing filter rules and output templates from scratch is expensive. A more practical approach is a “config pack” that bundles:
- Filter rules for common commands, covering frequent work such as commits, test runs, builds and packaging, and code checks;
- Standard output templates, one each for success, failure, and warning;
- Scenario skills, such as automation scripts for notes, schedules and data cleanup, and common office and collaboration workflows.
These packs are an add-on. They do not change the assistant itself; they only enhance the terminal interaction layer. Install them and use them—no line-by-line tuning. The gain is especially clear for people who develop, read logs, and check repository status from the command line.
They do not automatically do every task for you. After you give an instruction, the assistant is more likely to work in a short, accurate, and economical way.
4. One prompt template across entry points
If you are not using a CLI but a chat bot (workplace collaboration, messaging, and similar channels), a general prompt can produce a similar effect. You can use this template directly:
From now on, after running a command, compress the output before you reply:1. Report only whether the command succeeded and the key conclusion;2. On failure, list the core errors (at most 5) and omit stacks and progress logs;3. Reply in four sections: Command / Status / Key details / Suggestion;4. Merge repeated or undifferentiated content.
In plain language, this prompt implements the same two layers—filtering plus templating—and works with any AI assistant entry point that can remember instructions.
5. Practical advice and how to judge results
When you roll this out, focus on three points:
Measure before you tune. Record token use and response time for typical tasks before and after the change. Use the numbers to judge the effect instead of adjusting by feel.
Keep an escape hatch. Some debugging sessions need the full raw output. Add a line such as: when I say “show full output,” return the uncompressed original log.
Grade compression by scenario. Use strong compression for everyday automation and switch to a detailed mode for deep troubleshooting, trading cost against how much information you need.
Summary
Wasted tokens from terminal output are one of the highest-leverage optimizations in AI coding workflows. Noise filtering plus templated results—through a ready-made rule pack or a single general prompt—can sharply shrink context use without dropping critical information, so the assistant is cheaper, faster, and more stable. Start with the prompt template in this article, then gradually build filter rules and output templates for your own team.
