squeez β€” hook-based token compressor for AI CLIs

# squeez [![CI](https://github.com/claudioemmanuel/squeez/actions/workflows/ci.yml/badge.svg)](https://github.com/claudioemmanuel/squeez/actions/workflows/ci.yml) [![npm](https://img.shields.io/npm/v/squeez.svg)](https://www.npmjs.com/package/squeez) [![Crates.io](https://img.shields.io/crates/v/squeez.svg)](https://crates.io/crates/squeez) [![License: Apache 2.0](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](LICENSE) [![DCO](https://img.shields.io/badge/contributions-DCO_signed--off-green.svg)](CONTRIBUTING.md#license--contributor-sign-off) [![Changelog](https://img.shields.io/badge/changelog-πŸ“‹-blue.svg)](CHANGELOG.md) End-to-end token optimizer for seven AI CLI hosts β€” Claude Code, GitHub Copilot CLI, OpenCode, Gemini CLI, OpenAI Codex CLI, Pi, and Hermes. Compresses bash output up to **95%**, collapses redundant calls, preserves exact identifiers through every summary, refuses net-loss compressions, and injects a terse prompt persona β€” automatically, with zero new runtime dependencies. --- ## πŸ“° What's new > Latest first. Full history in [CHANGELOG.md](CHANGELOG.md). ### v1.46.0 β€” shipped filter pack + native `git status` The filter DSL could always cover the long tail `GenericHandler` can't compress β€” it just shipped empty, so every user started from a blank `filters.ini`. This release fills it, adds a native `git status` path, and makes two guards that were only ever measured in benchmarks run for real. - **41 built-in filter rules** (`assets/filters_builtin.ini`) β€” `pip`/`uv`/`poetry`, `bundle`/`composer`/`rubocop`/`phpstan`, `dotnet`/`swift`/`gcc`, `mypy`/`basedpyright`/`golangci-lint`, `shellcheck`/`hadolint`/`yamllint`/`markdownlint`/`pre-commit`, `systemctl`/`journalctl`/`rsync`/`ping`/`ansible-playbook` and more. Every rule ships an inline self-test that CI gates on. Project and user rules still shadow any built-in; `builtin_filters = false` turns the pack off. - **`git status` reads as porcelain** β€” re-run as `git status --porcelain=v1 -b` and rendered as a working-tree summary. Exact paths are never collapsed to counts, raw porcelain codes never reach the model, and in-progress rebase/merge/bisect (which porcelain omits) is read from `.git/` markers instead of a second `git status`. - **The preservation guard actually runs.** `economy::preservation` used to execute only in `benchmark`. It now scores anchor survival at wrap time on β‰₯90%-reduction calls; below the floor the verbatim original is stashed and the header carries `[anchors: N%]`. - **The net-win gate counts its own marker.** The ~40-token retrieve marker was appended *after* the gate decided the call was a win, so a call saving 25 tokens could ship a 40-token marker and still claim a win. It is now inside the arithmetic. - **Dispatch blind spots closed** β€” `TF_LOG=debug terraform plan` and `npx terraform plan` reach the terraform branch; wrappers peel in a loop (`sudo npx vitest`); a pipeline ending in a transforming stage (`cargo build | grep error`) dispatches on that stage. - **Benchmarks grew to 46 scenarios**, six of them covering the new rule pack, so the pack's contribution is measured rather than asserted. --- ## Install Three methods β€” all produce the same result (binary at `~/.claude/squeez/bin/squeez`, hooks registered). ### curl (recommended) ```bash curl -fsSL https://raw.githubusercontent.com/claudioemmanuel/squeez/main/install.sh | sh ``` > **Windows:** requires [Git Bash](https://git-scm.com/downloads). Run the command above inside Git Bash β€” PowerShell/CMD are not supported. ### npm / npx ```bash # Install globally npm install -g squeez # Or run once without installing npx squeez ``` Downloads the correct pre-built binary for your platform (macOS universal, Linux x86_64/aarch64, Windows x86_64). Requires Node β‰₯ 16. ### cargo (build from source) ```bash cargo install squeez ``` Builds from [crates.io](https://crates.io/crates/squeez). Requires Rust stable. On Windows you also need [MSVC C++ Build Tools](https://visualstudio.microsoft.com/visual-cpp-build-tools/). --- ### Supported hosts `squeez setup` auto-detects every CLI present on disk and registers the hooks. `squeez uninstall` removes them. Session data and `config.ini` are preserved so reinstall is lossless. | Host | Memory file | Bash wrap | Session memory | Budget inject (Read/Grep) | Notes | |---|---|---|---|---|---| | **Claude Code** | `~/.claude/CLAUDE.md` | βœ… native | βœ… native | βœ… native | Restart Claude Code to pick up hooks | | **Copilot CLI** | `~/.copilot/copilot-instructions.md` | βœ… native | βœ… native | βœ… native | Restart Copilot CLI after setup | | **OpenCode** | `~/.config/opencode/AGENTS.md` | βœ… native | βœ… native | βœ… native | Plugin at `~/.config/opencode/plugins/squeez.js`; MCP tool calls skip hooks (upstream sst/opencode#2319) | | **Gemini CLI** | `~/.gemini/GEMINI.md` | βœ… native | βœ… native | 🟑 soft via `GEMINI.md` | `BeforeTool` rewrite schema pending upstream docs ([google-gemini/gemini-cli#25629](https://github.com/google-gemini/gemini-cli/issues/25629)) | | **Codex CLI** | `~/.codex/AGENTS.md` | βœ… native | βœ… native | 🟑 soft via `AGENTS.md` | `apply_patch` hooks landed in 0.123.0 ([#18391](https://github.com/openai/codex/pull/18391)); `updatedInput` + `read_file`/`grep` hook surface still pending ([openai/codex#18491](https://github.com/openai/codex/issues/18491)) | | **Pi** | `~/.pi/agent/skills/squeez/SKILL.md` | βœ… native | βœ… via skill | βœ… native | TypeScript extension at `~/.pi/agent/extensions/squeez/index.ts`; restart Pi after setup | | **Hermes** | `~/.hermes/profiles/default/SOUL.md` | βœ… native | βœ… native | ❌ no budget surface | Python plugin (`__init__.py` + `plugin.yaml`) auto-discovered by Hermes; detected via `~/.hermes/` | ### Manage ```bash squeez setup # register into every detected host squeez setup --host= # register into one host squeez uninstall # remove squeez entries from every detected host squeez uninstall --host= ``` Slugs: `claude-code` / `copilot` / `opencode` / `gemini` / `codex` / `pi` / `hermes`. After install, restart the CLI you use to pick up the new hooks. ### Uninstall ```bash squeez uninstall # preserves session data + config.ini bash ~/.claude/squeez/uninstall.sh # (legacy) full wipe, if the script exists ``` ### Self-update ```bash squeez update # download latest binary + verify SHA256 squeez update --check # check for update without installing squeez update --insecure # skip checksum (not recommended) ``` --- ## What it does | Feature | Description | |---------|-------------| | **Bash compression** | Intercepts every command via `PreToolUse` hook, applies smart filter β†’ dedup β†’ log-template β†’ relevance-truncation. Up to 95% reduction. (Per-dir grouping stays reserved for `git status`, where the path list is the payload.) | | **Reversible compression** | When a large output is compressed, the verbatim original is stashed in a content-addressed blob and a `[squeez: … call squeez_retrieve with key=""]` marker is emitted. The model recovers any dropped detail via the `squeez_retrieve` MCP tool β€” so compression can be aggressive without losing information. TTL-pruned, zero-dep. | | **Log-template compaction** | Collapses near-identical log lines that differ only by a timestamp, id, hex hash, or `1ms`-style value into one `[Γ—N]