Discover and explore top open-source AI tools and projects—updated daily.
ojuschugh1Compress LLM context to save tokens and reduce costs
Top 88.3% on SourcePulse
Compress LLM context to save tokens and reduce costs.
sqz addresses the challenge of limited LLM context windows and associated token costs by compressing and deduplicating command output before it reaches AI models. Targeting developers and AI-powered tool users, it significantly reduces token consumption, leading to cost savings and improved efficiency in agentic workflows.
How It Works
The core mechanism involves a PreToolUse hook that intercepts shell command outputs. sqz applies content-aware compression, reducing verbose logs, JSON, and shell outputs. Its key innovation is session-level deduplication: repeated content, such as file reads, is sent once and subsequent occurrences are replaced by a compact 13-token reference, yielding substantial savings in repetitive tasks.
Quick Start & Requirements
Installation is streamlined via prebuilt binaries (macOS/Linux curl, Windows irm), npm (npm install -g sqz-cli), or Homebrew (brew install sqz). Building from source via cargo install sqz-cli requires a C toolchain. Initialization involves sqz init --global for system-wide hooks or sqz init for project-specific configuration, supporting numerous AI tools like Claude Code, Cursor, and Gemini CLI.
Highlighted Details
Real-world usage reports over 3,003 compressions show an average reduction of 24.7%, with up to 92% savings on repeated file reads. Benchmarks demonstrate per-command compression ranging from 2% (prose) to 58% (repeated log lines). A persistent dedup cache stores content hashes, enabling 13-token references for subsequent identical inputs. Safe mode transparently handles sensitive data like stack traces with zero compression.
Maintenance & Community
The project provides a Discord server for community interaction and a changelog for tracking updates. Development is managed via standard Rust practices, with a public GitHub repository.
Licensing & Compatibility
sqz is licensed under the Elastic License 2.0 (ELv2). This permits free use, forking, and modification, with two primary restrictions: prohibiting the offering of a competing hosted service and mandating the retention of license notices. Commercial use is generally compatible, provided these terms are met.
Limitations & Caveats
Certain LLMs may exhibit looping behavior with deduplicated references; workarounds include explicit expansion (sqz expand), disabling dedup (--no-cache, SQZ_NO_DEDUP=1), or using the MCP passthrough tool. Preserving comments in JSON configuration files requires manual installation steps, as the automated sqz init process uses a JSON parser that strips comments. Building from source via Cargo necessitates a C toolchain, which may be an adoption hurdle for some users.
2 weeks ago
Inactive
microsoft
rtk-ai