ByteCosts
sqz-context-compression-review.mdx

AI Coding Agents

sqz Review: Dedup References and Tool-Output Compression for Coding Agents

sqz is a Rust binary that compresses coding-agent tool output before it enters the model’s context, using per-command formatters plus a session deduplication layer that swaps repeated output for roughly 13-token references. It targets billed input tokens on Claude Code, Gemini CLI, OpenCode, Copilot CLI, and advisory clients like Cursor, Codex, and Kiro. The README reports a 24.7% average reduction across 3,003 compressions from one developer’s week of local `sqz gain` measurements.

At a glance

QuestionAnswer
What is it?A Rust binary that formats tool output and replaces repeats with session references.
What cost does it target?Input from verbose or repeated shell, file, and MCP results.
Where does it act?Through supported client hooks, advisory rules, or a stdio MCP proxy.
How do you try it?Install with Homebrew and configure the integration for your client.
Can you recover originals?sqz_expand can return cached MCP originals byte for byte. Recovery depends on what the integration stored.
What license is stated?Apache-2.0.
What is its maturity signal?680 stars and 3 open issues as of November 30, 2026.
When is it a good fit?Sessions with repeated test output, Git status calls, or build logs.

What sqz is and which cost layer it targets

sqz works on the tool-output layer: the shell results, file reads, JSON responses, logs, and test runs that an agent re-sends as input tokens on every subsequent turn. It does not touch your prompts or the model’s replies, and it makes zero LLM calls of its own. It is written in Rust, ships as a single deterministic binary, and is Apache-2.0 licensed. As of November 30, 2026, the repository has 680 stars, 45 forks, and 3 open issues; the latest release is v2.2.0, published November 12, 2026.

Two mechanisms share the work. Per-command formatters keep what an agent acts on (the failing test, the assertion, the file:line) and drop spinner noise, passing-run filler, nulls, and empty values. Session deduplication keeps a local cache of everything the agent has already seen; when the same output, or a line range of a file already read, comes through again, sqz returns a §ref:HASH§ token of about 13 tokens instead of the content. Source code passes through in full on first read, and stack traces, SQL migrations, PEM blocks, and credential lines are routed to a safe mode that never compresses or caches them at any size.

How it works

Integration splits into two tiers, and the tier determines whether you get savings without convincing the agent to cooperate.

On transparent clients (Claude Code, Gemini CLI, Copilot CLI, OpenCode), sqz init installs a hook that rewrites shell commands so their output flows through sqz compress before reaching the agent. On Claude Code specifically it uses a PreToolUse hook to rewrite the command and a PostToolUse hook to compress output after a successful run; pipelines, loops, and heredocs are left as written to avoid changing which commands actually execute.

On advisory clients (Cursor, Windsurf, Cline, Codex, Kiro, Zed), sqz writes guidance files (.cursor/rules/sqz.mdc, AGENTS.md, Kiro steering) telling the agent to pipe output through sqz compress or call the sqz MCP tools. Savings then depend on the agent choosing to use them; the client’s built-in shell and file tools bypass sqz entirely. sqz doctor reports which tier each detected client sits on.

A third path, sqz-mcp proxy, wraps any stdio MCP server. Tool results pass through the full pipeline (dedup refs, safe mode, error results untouched), and a --lazy-tools flag shortens every tool description to one sentence with an sqz_tool_help escape hatch; the README notes some MCP servers spend 10,000 to 40,000 tokens on tools/list alone. An injected sqz_expand tool lets the agent recover any cached original byte-exact.

sqz recall searches retained local output in SQLite under ~/.sqz/, which can recover details after context compaction. Recovery depends on what the selected path stored. Safe-mode content such as credential lines and stack traces can pass through without being cached.

Install and first run

The README offers several install paths:

# macOS / Linux (read the script before piping it to sh)
curl -fsSL https://raw.githubusercontent.com/ojuschugh1/sqz/main/install.sh | sh

# Any platform via npm
npm install -g sqz-cli

# macOS / Linux via Homebrew
brew tap ojuschugh1/sqz
brew install sqz

# Build from source (needs a C toolchain)
cargo install sqz-cli sqz-mcp

Then initialize and verify:

sqz init --global     # hooks apply to every project on this machine
sqz init              # hooks apply to just this project
sqz doctor            # checks binary, database, hooks, and client routing

Before committing to hooks, sqz discover --replay replays your existing Claude Code or Kiro transcripts through the engine against a throwaway cache and prints a counterfactual estimate of avoidable tokens, labeled as an estimate. That is the right first run: it costs nothing and changes nothing.

To remove it, sqz uninstall removes sqz’s hooks, guidance, and MCP entries and lists the files it kept. Two closed issues are worth knowing before you run init twice: #21 reported sqz init was not idempotent and appended duplicate hooks, and #1 asked for a confirmation prompt. Both are closed; the current README describes merge-not-overwrite behavior, but checking sqz doctor output after init is still cheap insurance.

What it saves: claims versus evidence

The savings figures come from the project. The independent tokbench pilot (N=1 per arm) tested lean-ctx, RTK, and Headroom and did not include sqz.

The README reports a 24.7% average reduction across 3,003 compressions from one developer’s week of local sqz gain measurements. The same output shows 178,442 tokens saved. The README separately claims up to 92% reduction on output the model already has. Single-command fixtures measured via cargo test -p sqz-engine benchmarks: repeated log lines 74% saved, a large JSON array 57%, a JSON API response 17%, a git diff 11%, prose 2%, stack traces 0% by design. Session-level dedup on repeats: an unchanged git status 166 to 37 tokens (78%), a re-read of lines 41-80 260 to 35 (87%), an identical cargo test 366 to 39 (89%).

How often do repeats occur? The README cites a user who counted 92 of their own Claude Code sessions and found identical whole-file re-reads in only 1 of 542 reads, but line-range re-reads in 8.4% of them. The repeats that happen in practice, per the project, are unchanged command output, line ranges of files already read, and files re-read after small edits. Sessions with noisy command output and repeated commands see the biggest wins; a session dominated by fresh file reads sees little.

The demo arithmetic is also honest about scale: the README’s worked example compresses 2,092 tokens of mixed output to 1,557, a 26% saving with nothing dropped. Expect tens of percent on the tool-output slice, not an order of magnitude.

Prompt-cache and extra-turn risk

sqz compresses new tool output and leaves prior history intact. Compare provider-reported cache reads in your baseline and trial. The tradeoff it does carry is dedup: a §ref§ token is only useful while the model can resolve it. The README concedes some models (it names GLM 5.1) cannot parse the ref format and loop; escape hatches are sqz expand, sqz compress --no-cache, SQZ_NO_DEDUP=1, and SQZ_REF_TTL_SECS to shorten the reference freshness window (default 1,800 seconds).

The extra-turn risk is real in the other direction too: if compression drops something the model needed, the agent re-runs the command and pays twice. sqz exposes this through regret signals in sqz stats: quick re-runs (byte-identical output re-produced within 2 minutes) and ref expands, both proxies for compression that cost a turn. A 16-token net-win gate skips compressions that would not pay for their own markers.

What the GitHub issues show

The issue list reads like a young tool hardening fast. One open issue from November 28, 2026, #47, reports that on 2.2.0 the hook ignores rules in settings.json and sqz doctor reports “ok” while the hook is inert; verify actual savings with sqz stats rather than trusting the doctor output on the latest release. A closed issue, #46, reported an information-loss and credential-caching problem; current versions never cache credential lines, stack traces, or migrations, and sqz doctor --fix deletes output cached by 2.1.1 and earlier that current sqz would not cache.

Other closed issues trace the integration edges: #39 where the Claude Code hook masked command exit status without pipefail (sqz now adds set -o pipefail and an allow rule for it), #2 and #20 on Windows path escaping under Git Bash, #43 where OpenCode 2.x rejected the generated plugin shape, and #5 and #7 on OpenCode tool discovery and a Linux install script failure. Issue #35 literally asked “Is this project Dead?” in July; the release cadence since (v1.6 through v2.2 between August and November) answers it.

A cost example

Assume a Claude Code session on claude-sonnet-5-5 produces 50,000 tokens of tool output, and that output is re-sent as context for 10 subsequent turns. Using the committed rates at /tools/ai-provider-pricing/, input is $2 per million tokens and cache read is $0.10 per million.

  • Without prompt caching, worst case, those repeats bill as fresh input: 50,000 × 10 × $2/M = $1.00 (estimate).
  • With prompt caching, the same repeats bill at cache-read rates: 50,000 × 10 × $0.10/M = $0.05 (estimate).
  • Assume sqz shortens the fresh result by 40,000 tokens before it enters history and that the shorter result is carried for all 10 later turns. The repeats alone save an estimated 40,000 × 10 × $0.10 per million = $0.04 if all are cache reads. If all bill as fresh input, 40,000 × 10 × $2 per million = $0.80.

sqz stats --cost defaults to a cache-write multiplier of 1.25 and a cache-read multiplier of 0.10. For the Sonnet rate in this example, set the read multiplier to 0.05 because $0.10 ÷ $2 = 0.05. First-pass formatting and shorter --lazy-tools descriptions can reduce fresh input and later cache reads. Price both using the provider’s prompt caching rates.

Who should use it, who should skip it

Use it if:

  • You run Claude Code, Gemini CLI, Copilot CLI, or OpenCode, where the hook tier is transparent and needs no agent cooperation.
  • Your sessions are heavy on repeated command output: test runs, git status, build logs, MCP servers with verbose tool lists.
  • You want a local, deterministic tool with no LLM calls and an auditable sqz expand recovery path.

Skip it (or run it in --no-cache mode) if:

  • Your model struggles with reference tokens; test the §ref§ format on a small session first.
  • Your work is mostly first-pass file reads and fresh output, where dedup has nothing to deduplicate.
  • You are on an advisory-tier client and your agent ignores the guidance; check sqz stats after a week to confirm compressions actually happened.

How to trial it safely

  1. Run sqz discover --replay on your existing transcripts first; if the counterfactual saving is small, stop there.
  2. Install project-scoped (sqz init, not --global) in one repository for a week.
  3. Record baseline session cost before enabling; the companion guide how to measure coding agent token savings covers the A/B method.
  4. After the week, read sqz stats for the regret signals (re-runs, expands) alongside sqz stats --cost for the dollar figure under cached billing.
  5. If a specific command keeps appearing in the regret report, file an issue or exclude it rather than judging the whole tool by one formatter.

Alternatives and next reads

For wire-level compression of the whole request rather than per-output formatting, see the Tamp proxy review and the Headroom context compression review. For reversible, provider-neutral compression of structured payloads, see the Tokenfold review. For the measurement discipline behind all of these, start with how to measure coding agent token savings.

Sources

How this note was produced

Drafted with AI assistance from committed ByteCosts pricing snapshots and deterministic cost formulas. Figures are grounded in the linked sources (last updated 2026-11-30). Read our editorial & automation policy, inspect the methodology, or report a discrepancy.

sqz Review: Dedup References and Tool-Output Compression for Coding Agents. ByteCosts. Updated 2026-11-30. https://bytecosts.com/blog/sqz-context-compression-review/

Sources