Cuts tool outputs, logs and documents to about half before an LLM reads them, without mangling IDs.
Real run of ctxprune log.txt --keep 0.5 --protect (ctxprune 0.5.0, this model, CPU): 704 characters in, 323 out; 4821, db-07.internal and 3 survive. One log, not a benchmark; the numbers are below.
At 50% of tokens kept, a reader LLM answers 51.5% of SQuAD v2 + HotpotQA questions exactly from this model's output
vs 36.5% from headroom's Kompress-v2-base (400 questions, gap CI +10.5 to +19.5; reader Qwen3.8-27B, which also
labeled this model's training data), and 68.8% vs 53.4% for LLMLingua-2-large on our agent-text set with an
independent reader (DeepSeek V4 Flash). Try it in your browser
(runs locally, nothing is uploaded).
pip install ctxprune
ctxprune build.log --keep 0.5 # or pipe: cmd | ctxprune --keep 0.33 --protect
The same package also ships lossless hooks for coding agents (Claude Code, Codex, Hermes, Pi, OpenCode, dsh) that
use no model: uvx ctxprune wrap claude (one line; ctxprune install --all for every agent), see riceharvest/ctxprune. From
ctxprune 0.3 this model is used only by the token-pruning API below. In 0.4, 0.2-style calls (prune(text, keep), Compressor, the CLI) still give
the same output as in 0.2.1; the new v0.4 engine (query-aware pruning, protect="auto", compress_many) is opt-in on those calls and the default on the new entry points.
ctxprune 0.5 adds opt-in integrations and tools (MCP server and wrapper, see the changelog); default output is byte-identical to 0.4.1.
By @imdariotoo · code, Claude Code plugin, LangChain/LlamaIndex integrations: riceharvest/ctxprune
A 140M-parameter token classifier that shortens text before it reaches an LLM by deleting the words that matter least. It is a successor to Microsoft's LLMLingua-2, trained for what agents actually read: tool outputs (JSON, logs, stack traces, diffs, directory listings), code, documents and chat, in many languages.
ord_8f3a2c91 into ord _ 8f3a2c91 and
0.21 into 0. 21). Optional force_protected=True (protect=True in ctxprune.prune) guarantees no
identifier is dropped. Turn it on for tool output and logs: without it the model may delete identifiers.
On 30 held-out agent tool outputs at 50% kept, 99.6% of IDs, paths, versions, URLs and numbers survived verbatim
with it, 45.8% without it, 72.9% with LLMLingua-2-base and 94.6% with LLMLingua-2-large
(all types and rates).pip install ctxprune # CPU: onnxruntime + tokenizers, no torch
pip install "ctxprune[torch]" # PyTorch backend (GPU/CPU)
import ctxprune
ctxprune.prune(tool_output, keep=0.5) # int8 ONNX on CPU, model downloads once (143 MB)
ctxprune.prune(tool_output, keep=0.33, protect=True) # never drop IDs, numbers, paths
ctxprune.prune(tool_output, keep=0.33, protect="auto", query="why did it fail?") # 0.4: query-aware, keeps technical text intact
from ctxprune import Compressor # more control: batching, fp32, torch, thresholds
c = Compressor("darioooooo0o/ctxprune-small", backend="onnx", onnx_file="onnx/model.onnx")
c.compress(tool_output, rate=0.5)["text"]
| Where | How |
|---|---|
| Coding agents | lossless hooks, no model: ctxprune install --all (details) |
| Shell | ctxprune FILE --keep 0.5 --stats, reads stdin |
| Other languages | ctxprune serve then POST localhost:8719/compress {"text": ...} |
| LangChain / LlamaIndex | ctxprune.integrations.CtxpruneDocumentCompressor / CtxpruneNodePostprocessor |
| Browser (transformers.js) | see the demo source |
With LLMLingua (drop-in, needs the tokenizer-detection fix proposed upstream in microsoft/LLMLingua#261):
from llmlingua import PromptCompressor
pc = PromptCompressor(model_name="darioooooo0o/ctxprune-small", use_llmlingua2=True)
pc.compress_prompt(text, rate=0.5, force_tokens=["\n", "?"])
Tokenizer: loading this model's tokenizer with transformers needs transformers>=5.
Raw transformers / ONNX: label 1 = keep (same convention as LLMLingua-2). Score each token with
softmax(logits)[..., 1], average per word, and keep the highest-scoring words. onnx/model.onnx is
exact fp32. onnx/model_quantized.onnx is int8 (143 MB): its keep decisions match fp32 on ~96% of tokens, and QA
accuracy at 50% kept is 68.2 vs 68.8 for fp32 (same eval as below).
Held-out evaluation: 378 questions over 196 chunks from repos, MCP servers and sites never seen in training. Each method compresses the chunk to the same share of the reader's tokens; the reader then answers from the compressed text and is scored by exact match on the gold span.
QA exact match, independent reader (DeepSeek V4 Flash):
| Method | 50% of tokens kept | 33% of tokens kept |
|---|---|---|
| Original (no compression) | 91.8 | |
| ctxprune-small | 68.8 | 53.4 |
ctxprune-small + force_protected |
63.5 | 52.9 |
| LLMLingua-2 large | 53.4 | 32.5 |
| LLMLingua-2 base | 41.0 | 24.9 |
Per source, at 50%:
| Source | fineweb2 | fineweb edu | github code | oasst2 | swe rebench assistant | swe rebench tool | swe smith tool | toucan mcp |
|---|---|---|---|---|---|---|---|---|
| ctxprune-small @50% | 56 | 73 | 72 | 75 | 70 | 60 | 84 | 59 |
| LLMLingua-2 large @50% | 83 | 73 | 62 | 62 | 49 | 48 | 29 | 43 |
Teacher as reader. An earlier checkpoint (conservative labels only, ~2k chunks) was also scored with Qwen3.8-27B, the labeling teacher, as reader: 65.9 / 51.1 vs LLMLingua-2 large 55.0 / 32.5. That is the same ranking as with the independent reader, so the gain is not an artifact of the teacher grading itself.
Identifiers lost (IDs, numbers, paths, versions that no longer appear intact), at 50%:
| Method | IDs lost | LLM-token ratio |
|---|---|---|
| ctxprune-small | 41% | 0.49 |
| ctxprune-small + force_protected | 0% | 0.54 |
| LLMLingua-2 large | 34% | 0.48 |
| LLMLingua-2 base | 47% | 0.59 |
Reasoning on vs off for the reader made no difference on a 40-question check, so readers ran without it.
Code, data pipeline and evals: https://github.com/riceharvest/ctxprune.
passage_retrieval_en. The query mode
sees the question and LLMLingua-2 does not; 21 of the 270 items share a source document with our dev set. A zero-model
BM25 selector at the same budget is level with the query mode (+0.71 [−1.77, +3.40]), so the model's added value over
lexical query matching is not shown. Without a question (query-blind) it is level on 9 tasks and worse without
passage_retrieval_en (−3.73 [−6.52, −1.14]). On our dev set it also loses triviaqa and lcc. Tables, controls and
the dev-set numbers (which the 0.4 code was tuned on):
BENCHMARKS §9.force_protected=True guarantees no identifier is dropped, but at 50% it spends budget on IDs the
question did not need and scores a few points lower overall. Use it when exact IDs matter more than
everything else (e.g. you will act on them).Training data includes content under CC BY 4.0 (nebius/SWE-rebench-openhands-trajectories) and ODC-BY (FineWeb-Edu, FineWeb-2). The deletion-only teacher prompt adapts LLMLingua-2's (MIT, Microsoft). Base model: jhu-clsp/mmBERT-small (MIT).
onnx/model.onnx 537 MiBmodel.safetensors 537 MiBonnx/model_quantized.onnx 136 MiBjhu-clsp/mmBERT-small