Compression Pipeline
Every request from your AI CLI passes through Squeezr on localhost:8080. The proxy applies three compression layers before forwarding to the upstream API.
Pipeline overview
Request from coding tool
|
v
+------------------------+
| Layer 1: System Prompt | Compress once, cache, reuse every turn
+------------------------+
|
v
+------------------------+
| Layer 2: Deterministic | Zero-latency rule-based transforms
| Preprocessing | (ANSI, dedup, JSON, noise removal)
+------------------------+
|
v
+------------------------+
| Layer 3: Tool-Specific | 30+ patterns for git, tests, builds,
| Patterns | infra, package managers, and more
+------------------------+
|
v
Forward to upstream API (streaming, unmodified response)Layer 1: System prompt compression
Claude Code's system prompt is typically 13–20 KB and is sent with every single request. Squeezr runs two passes before forwarding it:
- Skill/plugin block dedup — Identical blocks (e.g. duplicated plugin skill registrations, a known Claude Code issue) are collapsed byte-a-byte using MD5 matching. Free, zero-latency, typically saves 5–20% of the system prompt.
- AI compression (Haiku) — The deduped prompt is compressed once using Haiku and the result is cached. Every subsequent request reuses the cached version.
Savings: ~3,000–6,000 tokens per request after the first.
Layer 2: Deterministic preprocessing
Zero-latency rule-based transforms applied to every tool result. No API calls, no latency:
- Noise removal — ANSI escape codes, progress bars, timestamps, spinner output stripped
- Deduplication — repeated stack frames, duplicate lines, redundant git hunks removed
- Minification — JSON whitespace collapsed, blank lines consolidated
Layer 3: Tool-specific patterns
Each tool result is matched against 30+ specialized compression rules. Errors, warnings, and actionable information are always preserved.
| Category | Tools | What it does |
|---|---|---|
| Git | diff, log, status, branch | 1-line diff context, capped log, compact status |
| JS/TS | vitest, jest, playwright, tsc, eslint, biome, prettier | Failures/errors only, grouped by file |
| Package managers | pnpm, npm | Install summary, list capped at 30, outdated only |
| Build | next build, cargo build | Errors only |
| Test | cargo test, pytest, go test | FAIL blocks + tracebacks only |
| Infra | terraform, docker, kubectl | Resource changes, compact tables, last 50 log lines |
| Other | prisma, gh CLI, curl/wget | Strip ASCII art, cap output, remove verbose headers |
Exclusive patterns
Applied to specific content types regardless of which tool produced them:
- Lockfiles (package-lock.json, Cargo.lock, etc.) → dependency count summary
- Large code files (>500 lines) → imports + function/class signatures only
- Long output (>200 lines) → head + tail + omission note
- Grep results → grouped by file, matches capped
- Glob results (>30 files) → directory tree summary
- Noisy output (>50% non-essential) → auto-extract errors/warnings
Deterministic crushers
Beyond the tool-specific patterns, Squeezr ships a set of structure-aware transforms (added in v1.84–v1.95). They are all deterministic, cache-safe, and fully reversible: the complete original is stored and every compressed block carries a squeezr_expand("<id>") callback.
JSON array crush (SmartCrusher)
When a tool result contains an array of homogeneous objects — e.g. gh api, a curl to a REST endpoint, MCP tools returning record lists, or kubectl get -o json — Squeezr reshapes it into a compact table: column names appear once in a header, then one row of values per element, with no per-row key repetition. It works whether the array is the whole tool result or embedded inside a larger one.
For large arrays (>50 rows) it also drops near-duplicate rows using SimHash while always keeping anomaly/error rows. The transform is deterministic and cache-safe, and the full original JSON stays recoverable via expand.
TextCrusher
Extractive compression for large log or prose tool output. It collapses near-duplicate lines — including reworded ones, matched via word-shingle similarity (Jaccard), not only lines that differ by a number or timestamp — while always keeping error/warning lines plus the head and tail anchor lines. Deterministic and recoverable via expand.
Relevance (BM25)
A shared relevance scorer lets the crushers keep what is relevant to the current task — the user's latest message — rather than pruning by position alone. It is applied cache-safely: relevance is only used where it does not change the cached prefix, so Claude Code's prompt cache is never busted.
Code structure extraction (AST-lite)
Structure extraction now covers more languages: TypeScript/JavaScript, Python, Go, Rust, Java, C, and C++. Large source files are reduced to their structure (imports + signatures) with function bodies elided, and each body is recoverable individually via squeezr_expand.
Note: output-side reduction (verbosity steering + effort routing) is a separate lever documented on its own page — it shrinks what the model writes back, not the input.
Adaptive pressure
Compression aggressiveness scales automatically with context window usage:
| Context usage | Threshold | Behavior |
|---|---|---|
| < 50% | 1,500 chars | Light — only compress large results |
| 50–75% | 800 chars | Normal — standard compression |
| 75–90% | 400 chars | Aggressive — compress most results |
| > 90% | 150 chars | Critical — compress everything, 0 git diff context |
Session optimizations
- Diff-based repeated Read — if the same file is read multiple times, earlier reads are replaced with a Myers unified diff vs the latest version. Typical savings: 60–85% on files that change slightly between reads.
- Image dedup — repeated image blocks (screenshots) are hashed and deduplicated; only the most recent occurrence is kept at full fidelity. Typical savings: 80–95% on repeated screenshots.
- Attachment/artifact dedup — large repeated text blocks (≥500 chars) are hashed and collapsed. Catches Desktop file uploads and generated artifacts that get re-sent every turn.
- Stale turns summarization — when a session exceeds the configured threshold, old assistant/user turns are replaced with a compact placeholder. The last N turns are always kept at full fidelity.
- Cache barrier — operations that could invalidate Anthropic's prompt cache (dedup, diff, AI compression) are restricted to messages afterthe last cache_control marker. The cached prefix is never mutated.
- KV cache warming — deterministic MD5-based IDs keep compressed content prefix-stable across requests, maximising Anthropic cache hit rate.
- Expand on demand — compressed blocks include a
squeezr_expand(id)callback to retrieve full content.
Compression backends
| Backend | Model | Used for | Cost |
|---|---|---|---|
| Anthropic | Haiku | System prompt, session cache | ~$0.0001/call |
| OpenAI | GPT-4o-mini | Fallback compression | ~$0.0001/call |
| Gemini | Flash-8B | Fallback compression | Free |
| Local | qwen2.5-coder:1.5b | Compression when using Ollama | Free |