Lm Resizer
Rust-native context compression for Claude Code, Codex & MCP agents: filters & compresses noisy tool output (tests, diffs, logs, JSON, provider traffic) before

Установка Lm Resizer
У сервера нет опубликованного npm/PyPI-пакета — склонируй репозиторий и собери по его README, затем добавь получившуюся команду в свой клиент.
Открыть репозиторийОписание
Rust-native context compression for Claude Code, Codex & MCP agents: filters & compresses noisy tool output (tests, diffs, logs, JSON, provider traffic) before it reaches the LLM — fewer wasted tokens, full evidence recoverable. Local-first, Apache-2.0. Pairs with Code Explorer.
README
LM Resizer is a local Rust CLI that reduces noisy command output before it enters an AI agent's context. It runs commands, builds compact views of supported output and stores the original bytes for later retrieval. It also offers MCP tools and an HTTP proxy. The CLI works without an account or a language model. On the bundled synthetic JSON demonstration, it reduced 36751 bytes to 2700 and 12735 tokens to 1340 (o200k_base, exact count), with byte-for-byte recovery. These measurements describe this fixture only; reproduce them with python3 scripts/demo.py (see below).
Release candidate 0.2.7, unpublished. The prebuilt installation below becomes usable after the maintainer configures the signing key and publishes the signed artifacts. The fresh-install target is under five minutes with a prebuilt binary; this duration has not been verified on a clean machine. Source compilation needs the prerequisites listed below and can take longer. The full Linux suite with local sockets and the Windows build, targeted tests and source installation have passed. Signed prebuilt installation and macOS validation remain pending.
Français · CLI reference · Publication gates
Install
Before the signed release is published, the versioned download URLs are unavailable. For this candidate, use the Install from source section in an existing checkout.
Prebuilt binary for Linux and macOS (after publication):
curl -fsSL https://raw.githubusercontent.com/phuetz/lm-resizer/v0.2.7/install.sh -o install.sh && sh install.sh
export PATH="$HOME/.local/bin:$PATH"
lm-resizer --version
Windows PowerShell:
irm https://raw.githubusercontent.com/phuetz/lm-resizer/v0.2.7/install.ps1 | iex
The installer verifies the archive's signature with the maintainer's key written in the installer (openssl is needed on Linux and macOS), then its SHA-256 checksum and binary version, before placing lm-resizer in ~/.local/bin by default. The checksum alone, served by the same release as the archive, would not detect a replaced archive. Prepared platforms are Linux x86_64, macOS x86_64/arm64 and Windows x86_64.
On Linux and macOS the installer prints the line to add when ~/.local/bin is not on your PATH; to make it permanent in Bash, run echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.bashrc (use ~/.zshrc for zsh) and open a new terminal. The Windows installer updates the user PATH. LM_RESIZER_INSTALL_DIR selects another destination. To uninstall a prebuilt binary, remove it from that destination. Windows: TLS fallback, PowerShell 5.1 and byte-exact recovery.
Reproduce a measured example
From this checkout, with Python available for the demonstration only:
python3 scripts/demo.py
For a locally built CLI:
cargo build --locked
python3 scripts/demo.py target/debug/lm-resizer
On Windows, use python and target/debug/lm-resizer.exe. The script uses an isolated temporary state directory and removes it afterward. It processes the synthetic fixtures/json-synthetic/json-jobs.txt, retrieves the original using tee read, compares every byte and verifies that a failing command retains its diagnostic and exit code.
Measured with the command above: 36751 → 2700 bytes, 12735 → 1340 tokens, tiktoken-rs/o200k_base, token_count_method: exact. Recovery is byte-for-byte identical; the failure returns 7. These numbers apply only to this fixture, not to arbitrary projects or API bills.
See it work
tool-output processes output that a host already captured (exec runs the command and applies the same view). A JSON array of objects becomes a table, and the exact original stays one command away. From a clone of this repository, replay this bundled capture, the last eight tags of serde-rs/json from the public GitHub API (3731 bytes):
$ lm-resizer tool-output --command 'curl -s https://api.github.com/repos/serde-rs/json/tags?per_page=8' --input fixtures/json-real/github-tags.json
[lm-resizer compact JSON v1: same data as the JSON output (3731 bytes), not its bytes; exact original: lm-resizer tee read e66f04e5ad57. Tables: each row gives the "# rows" cells, then key=value where it differs from "# default"; ~ = key absent. a.b = key b inside object a. "# prefix" columns omit that prefix.]
# columns: name zipball_url tarball_url commit.sha commit.url node_id
# objects: commit
# prefix: zipball_url=https://api.github.com/repos/serde-rs/json/zipball/refs/tags/ tarball_url=https://api.github.com/repos/serde-rs/json/tarball/refs/tags/ commit.url=https://api.github.com/repos/serde-rs/json/commits/
# rows: name zipball_url tarball_url commit.sha commit.url node_id
v1.0.154 v1.0.154 v1.0.154 20572a6d066958542d79cdd6cf1a7cd9f0c8e1f8 20572a6d066958542d79cdd6cf1a7cd9f0c8e1f8 MDM6UmVmMzU4OTQ1MTE6cmVmcy90YWdzL3YxLjAuMTU0
v1.0.153 v1.0.153 v1.0.153 4b2d7264cef72ef297058ef7d731e7d77574cf3e 4b2d7264cef72ef297058ef7d731e7d77574cf3e MDM6UmVmMzU4OTQ1MTE6cmVmcy90YWdzL3YxLjAuMTUz
v1.0.152 v1.0.152 v1.0.152 c9f1e3b0216328591262889d9a1c2771f3dd5fff c9f1e3b0216328591262889d9a1c2771f3dd5fff MDM6UmVmMzU4OTQ1MTE6cmVmcy90YWdzL3YxLjAuMTUy
v1.0.151 v1.0.151 v1.0.151 de8500740cdcabffb9734f503e4889def823cf10 de8500740cdcabffb9734f503e4889def823cf10 MDM6UmVmMzU4OTQ1MTE6cmVmcy90YWdzL3YxLjAuMTUx
v1.0.150 v1.0.150 v1.0.150 a1ae73ac6a6940a4a57c673aebaa13ed4dfe3e8c a1ae73ac6a6940a4a57c673aebaa13ed4dfe3e8c MDM6UmVmMzU4OTQ1MTE6cmVmcy90YWdzL3YxLjAuMTUw
v1.0.149 v1.0.149 v1.0.149 4f6dbfac79647d032b0997b5ab73022340c6dab7 4f6dbfac79647d032b0997b5ab73022340c6dab7 MDM6UmVmMzU4OTQ1MTE6cmVmcy90YWdzL3YxLjAuMTQ5
v1.0.148 v1.0.148 v1.0.148 8b291c4c5620476d6834c69fbfb24d13a24d4596 8b291c4c5620476d6834c69fbfb24d13a24d4596 MDM6UmVmMzU4OTQ1MTE6cmVmcy90YWdzL3YxLjAuMTQ4
v1.0.147 v1.0.147 v1.0.147 62d6e8d6158ccc1608fb57d9a8a73cc8d15f5b2a 62d6e8d6158ccc1608fb57d9a8a73cc8d15f5b2a MDM6UmVmMzU4OTQ1MTE6cmVmcy90YWdzL3YxLjAuMTQ3
The JSON reports 1585 original tokens and 967 in the view, header included. The view holds the same data, not the same bytes: lm-resizer tee read e66f04e5ad57 returns the original byte for byte (lm-resizer tee read e66f04e5ad57 | cmp - fixtures/json-real/github-tags.json prints nothing).
Test runners are the opposite case. Since 0.2.7 they come back raw, on success and on failure, because a test can print anything (a relayed git log, a security warning) that a summary would hide. Bundled captures, replayed with the 0.2.7 binary and o200k_base:
| Capture | --command, --exit-code |
Original | Output | Why |
|---|---|---|---|---|
fixtures/json-real/github-tags.json |
curl -s https://api.github.com/repos/serde-rs/json/tags?per_page=8, 0 |
1585 | 967 | JSON table, original in tee |
fixtures/json-real/cargo-metadata.json |
cargo metadata --format-version 1 --no-deps, 0 |
9075 | 3322 | JSON table, original in tee |
bench/corpus/cargo_fail.txt |
cargo test, 101 |
792 | 792 | test runner: raw, even when it fails |
bench/corpus/cargo_ok.txt |
cargo test, 0 |
837 | 837 | test runner: raw |
bench/corpus/pytest_ok.txt |
pytest, 0 |
937 | 937 | test runner: raw |
bench/corpus/git_log.txt |
git log, 0 |
2320 | 2320 | git log is shortened only by exec in a simple direct call |
Reproduce any row with lm-resizer tool-output --command '<command>' --exit-code <code> --input <file> --json: the JSON reports original_tokens, compressed_tokens and tokens_saved with token_count_method: "exact". --exit-code N declares the producer's actual status; the text is never used to guess it. tests/readme_example.rs replays the example and every row of this table.
Use it
lm-resizer exec -- echo hello
lm-resizer exec -- git log -20
lm-resizer stats --json
lm-resizer tee list
On Windows, the first command is lm-resizer exec -- cmd.exe /d /c echo hello. Wrapped programs must be installed. An absent program returns 127. exec runs a command; tool-output --command describes an already captured output and does not run that command.
Recover the exact output
Read an identifier from the output, the JSON tee_hint, or tee list, then run lm-resizer tee read <id>. A JSON hint looks like [raw: 5891b5b522d5]; archives use .log. lm-resizer --version reports lm-resizer 0.2.7.
Default capture uses a shared pipe. Separate-stream modes (--stream, --raw-on-failure) preserve each stream's bytes and order but cannot guarantee chronology between streams. For a short failure, the displayed body stays raw and the process exit code remains unchanged. JSON carries provenance in streams; streaming mode does not repeat output already displayed. The archive contains only producer bytes.
CCR means Compress-Cache-Retrieve: a separate content store addressed by keys, with a default lifetime of 30 minutes. Tee archives have their own retention policy; see recovery.
Integrations and limits
Start with the CLI. MCP exposes tools to a compatible client; install-hooks writes agent guidance; init-native-hooks installs optional automatic hooks. See agent integrations and security, including permission rules for wrapped commands. These integrations write configuration only when requested.
Recognized test runners return their complete body on success and failure. Explicit err, test and summary views can omit lines; inspect the archive when complete evidence matters. Diagnostic recognition is heuristic and cannot recognize every possible failure message. Short or irregular output may not shrink. bytes_saved and tokens_saved are signed, so growth is visible.
Counts over 2 MiB, or an unbroken sequence longer than 64 KiB, may use a declared estimate instead of BPE counting. The reference tokenizer does not measure another provider's tokenizer or billing. HTTP proxy transformations, optional model downloads and configurable filters require separate review for your use case. Known limits · metric definitions.
Historical benchmark results remain in the repository as dated evidence. Some original corpora are excluded from the public tree; they are not a current reproducible performance claim.
Install from source
The CLI requires Rust 1.91 or newer; rust-toolchain.toml pins 1.95.0 with rustfmt and clippy. Use official rustup when the distribution compiler is older.
Install these system prerequisites before Rust:
- Debian 13 / Ubuntu:
curl, HTTPS certificates, Git, a C compiler (cc/gcc), a C++ compiler (c++/g++), libc headers and a linker (binutils, pulled in by GCC). In a terminal with sudo (or as root withoutsudo):
sudo apt-get update
sudo apt-get install -y --no-install-recommends ca-certificates curl git gcc g++ libc6-dev
- macOS: install Xcode Command Line Tools (
xcode-select --install), which provide Git, Clang/Clang++, headers and the SDK. Finish the installation dialog before continuing. - Windows x86_64: install Git for Windows and Visual Studio Build Tools with Desktop development with C++, MSVC C++ x64/x86 tools and the Windows SDK. Keep existing installations if these components are already available. Run the source block in Developer PowerShell with the x64 MSVC and Windows SDK environment loaded. A
kernel32.liblinker error means the Windows SDK library path is missing; checkLIBas well as the compiler onPATH.
The build and source installation were checked on Linux x86_64 and Windows x86_64 with Rust 1.95.0. Other platforms have not been reverified.
Download the public tagged sources (Bash or PowerShell). lm-resizer keeps its state in ~/lm-resizer, so clone from another directory (for example mkdir -p ~/src && cd ~/src in Bash, or New-Item -ItemType Directory -Force "$HOME\src" | Set-Location in PowerShell) rather than from your home folder:
git clone --branch v0.2.7 https://github.com/phuetz/lm-resizer.git
cd lm-resizer
Run the Rust blocks below from this checkout's root. If you already have a checkout, do not clone it a second time.
Linux/macOS (Bash):
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --no-modify-path --profile minimal --default-toolchain 1.95.0
. "$HOME/.cargo/env"
cargo --version
cargo install --quiet --path . --locked --root "$HOME/.local"
export PATH="$HOME/.local/bin:$PATH"
lm-resizer --version
Windows x86_64 (PowerShell):
$rustupInstaller = Join-Path $env:TEMP 'rustup-init.exe'
Invoke-WebRequest -Uri 'https://static.rust-lang.org/rustup/dist/x86_64-pc-windows-msvc/rustup-init.exe' -OutFile $rustupInstaller
& $rustupInstaller -y --no-modify-path --profile minimal --default-toolchain 1.95.0
$env:Path = "$(Join-Path $env:USERPROFILE '.cargo\bin');$env:Path"
cargo --version
$installRoot = Join-Path $env:USERPROFILE '.local'
cargo install --quiet --path . --locked --root "$installRoot"
$env:Path = "$installRoot\bin;$env:Path"
lm-resizer --version
If Rust is missing or too old, the rustup steps at the start of your platform block install the repository's selected toolchain. If rustup is already installed and its bin directory is on PATH, you can skip those steps. --no-modify-path leaves your profile files and permanent PATH intact; subsequent commands set PATH for the current terminal only. When distribution Rust is already installed, rustup may print cannot install while Rust is installed, followed by continuing (because the -y flag is set and the error is ignorable). rustup reports the error as ignorable and continues because of -y: check the exit code and cargo --version after sourcing .cargo/env; it should report 1.95.0. The distribution Rust remains installed. Official Rust installation instructions.
Cargo downloads dependencies into ~/.cargo (%USERPROFILE%\.cargo on Windows) even when a build fails; rustup stores compilers in .rustup. These caches are separate from the .local install prefix. If Cargo is not 1.95.0 in this checkout, check PATH (command -v cargo in Bash, Get-Command cargo in PowerShell), rustup show active-toolchain and any RUSTUP_TOOLCHAIN override. Stop if cargo install fails: the examples and uninstall command below require a successfully installed binary. If ~/.local/bin/lm-resizer already exists (for example after a prebuilt install), Cargo refuses with binary lm-resizer already exists in destination; remove that file or rerun with --force.
To remove a binary installed with Cargo:
cargo uninstall --root "$HOME/.local" lm-resizer
Windows (PowerShell):
cargo uninstall --root "$installRoot" lm-resizer
Uninstall
Undo what you installed, in this order.
- Hooks, per project:
lm-resizer uninstall-hooks --client all --project-dir .
This removes the guidance blocks, the generated helpers and the native hook files of the five clients (Codex, Claude, Gemini, Copilot, Cursor) when they are still exactly as generated, for the current binary or for the binary path written in the file; a hand-edited native hook file is left alone. Instruction files created by a current installation are removed if still empty after removing the block; pre-existing instruction content is restored.
- MCP servers, with the same client and scope as
install:
lm-resizer uninstall --client all --scope all --project-dir .
--scope all covers the project and the global configurations (project or global alone also work). This removes only the lm-resizer entry from .mcp.json and .cursor/mcp.json (key mcpServers), from .vscode/mcp.json (key servers) and the [mcp_servers.lm_resizer] table of ~/.codex/config.toml (Codex uses the global scope); other servers stay, and JSON files and ~/.codex/config.toml remain even when empty because their origin is unknown. Codex global configuration is untouched by --scope project.
- Recorded data. Raw-output archives, command history and the CCR database live in the state directory, printed as
state_directorybylm-resizer config. It isLM_RESIZER_STATE_DIRwhen that variable is set; otherwise it is alm-resizersubdirectory of the first variable set amongLOCALAPPDATA,XDG_STATE_HOME,HOMEandUSERPROFILE:~/lm-resizeron Linux and macOS withoutXDG_STATE_HOME,$XDG_STATE_HOME/lm-resizerwith it,%LOCALAPPDATA%\lm-resizeron Windows. Delete the archives, check the directory, then remove it:
lm-resizer tee purge --all
lm-resizer config
rm -rf "$HOME/lm-resizer"
The last line removes the default directory only. If lm-resizer config prints another state_directory, remove exactly that path, never its parent (XDG_STATE_HOME or LOCALAPPDATA hold other programs' data). If LM_RESIZER_STORE is set, the CCR database is that file: remove it too.
- The binary:
cargo uninstallas shown in "Install from source", or delete~/.local/bin/lm-resizer.
When not to use it
- Do not treat a shortened view as a complete audit trail: inspect the saved original for security, compliance or subtle failures.
- Do not expect savings on every input. Short commands and text with little repetition may stay unchanged.
- Token reductions on command outputs do not guarantee proportional API invoice savings or benchmark task success: real-world agent costs also depend on multi-turn context caching and prompt structure. Neither agent tasks nor billing were tested here.
LM Resizer is Apache-2.0 licensed. Contributing · Security
Credits and inspiration licenses.
HuggingFace tokenizers are optional: build with --features hf-tokenizer to
load local tokenizer JSON or call from_pretrained_verified(repo, commit, sha256).
Unpinned Hub downloads are rejected. The default build excludes tokenizers,
hf-hub and their maintenance advisories; the optional feature uses fancy-regex
and does not compile Oniguruma or C++ esaxx. SQLite and ring still compile C.
See THIRD-PARTY-NOTICES for optional dependency advisories and ONNX downloads.
Resource bound for token metrics: above 2 MiB, or with a non-whitespace span
longer than 64 KiB, BPE counting falls back to bytes/4, explicitly marked
token_count_method: approximate. These records are excluded from exact
historical token totals. Compression and original-byte retrieval remain available.
Adaptive diversity sizing clusters at most 512 uniformly sampled items on large transcripts. Selection still covers all lines, and CCR retains the full original. This bounds quadratic heuristic work without sampling the evidence store.
FAQ
Lm Resizer MCP бесплатный?
Да, Lm Resizer MCP бесплатный — установка в пару кликов через Unyly без оплаты.
Нужен ли API-ключ для Lm Resizer?
Нет, Lm Resizer работает без API-ключей и переменных окружения.
Lm Resizer — hosted или self-hosted?
Self-hosted: сервер запускается локально на твоей машине командой из раздела установки.
Как установить Lm Resizer в Claude Desktop, Claude Code или Cursor?
Открой Lm Resizer на unyly.org, выбери вкладку своего клиента (Claude Desktop, Claude Code, Cursor) и нажми Install — конфиг сгенерируется автоматически, без правки JSON.
Похожие MCP
GitHub
GitHubPRs, issues, code search, CI status
Filesystem
Secure file operations with configurable access controls.
Memory
Knowledge graph-based persistent memory system.
Unyly Deploy
UnylyDeploy sites and MCP servers to Unyly straight from your AI agent
Template MCP Server
mcpdotdirectA CLI tool to create a new Model Context Protocol server project with TypeScript support, dual transport options, and an extensible structure
Server Sequential Thinking
GitHub ActionsMCP server for sequential thinking and problem solving
gnomancer
com.gnomancerLocal raw DNA analysis: haplogroups, traits, ClinVar, pharmacogenomics. Nothing is uploaded.
Amap Maps Mcp Server
duxiaohuiMCP server for using the AMap Maps API
PayMCP
blustAILightweight payments layer for MCP servers: turn tools into paid endpoints with a two-line decorator. [PyPI](https://pypi.org/project/paymcp/) · [npm](https://w
demo
yoojoohans-jpgdemo — MCP server via Smithery
Сравнить Lm Resizer с
Не уверен что выбрать?
Найди свой стек за 60 секунд
Автор?
Embed-бейдж для README
Похожее
Все в категории development
