Introduction
l0-compressor is a lightweight CLI proxy that sits between your AI coding assistant and shell commands. It filters, truncates, and compresses command output to reduce token consumption by 50-80%.
Why
AI coding assistants (Claude Code, Gemini CLI, Cursor) read the full output of every shell command they execute. Most of this output is noise:
- Hundreds of passing test lines when only the failures matter
- ANSI color codes that consume tokens but carry no semantic value
- Repeated identical lines from build tools
- Blank lines that waste token budget
The useful information is almost always concentrated in the first few lines (headers, command echo) and the last few lines (errors, summary, exit status).
How
Instead of running:
cargo testRun:
l0-compressor cargo testThe output is filtered through a streaming pipeline:
- ANSI stripping -- removes color codes, cursor movement, etc.
- Line normalization -- progress bars collapsed to their final state (interior
\r), backspace/bell resolved, giant single-line JSON payloads truncated - Line collapsing -- identical and same-prefix runs become one line with a
(×N)count - Diff context collapsing -- inside unified diffs, long runs of unchanged context lines are collapsed; changed lines are always kept
- Blank line squeezing -- consecutive blanks reduced to one
- Head/tail buffering -- keeps first 30 and last 30 lines, discards the middle
- Clean-success squelch -- on a zero exit with no error signal, the tail is trimmed further (the summary line always survives)
On top of the pipeline, adaptive auto-tuning adjusts the head/tail budgets per command from your execution history, and persists what it learns between runs.
The result is a compact output that preserves the information an LLM needs to understand what happened.
Design Principles
- Universal: works with any command, no per-tool parsers
- Unintrusive: the binary never rewrites your shell, aliases, or
$PATH-- you invoke it explicitly. An optional, off-by-default Claude Code hook can do the prefixing for you, and is just as conservative about what it touches. - Safe: never modifies the child command's behavior. The one deliberate exception is the safety guard, which refuses to run a small set of clearly destructive commands (exit 126) when an AI-assistant terminal is detected;
--no-guardopts out. - Lightweight: single Rust binary, zero runtime dependencies
- Observable: every invocation logs metrics for analysis