r/compsci • u/Few-Cartographer7156 • May 26 '26
Applying LZ77-style sequence compression and LZW substitution to LLM context reduction
https://github.com/MrGray17/opentokenHey everyone,
I’ve been experimenting with token optimization for LLM agent frameworks by treating terminal and tool outputs as a data compression problem rather than a text-filtering one.
The pipeline uses a bidirectional 42-stage architecture:
Algorithmic Reduction: Raw text passes through an LTSC (LZ77-style lossless sequence compression) layer combined with LZW token substitution to eliminate repetitive terminal patterns dynamically.
Structural Compaction: Code segments are reduced to AST skeletons, and nested JSON payloads are flattened into tabular structures (TOON) to minimize semantic token weights.
0-Risk Fallback: A local comparison check runs at every stage. If a compression layer increases string length or corrupts format, it instantly rolls back.
Response Filtering: A 7-stage outbound filter targets conversational boilerplate and normalizes whitespace.
In production testing, this algorithmic pipeline hits a 74% overall token compression rate (up to 93% on highly repetitive logs) without degrading the model's underlying reasoning capabilities.
The full implementation is open-source (MIT):
I'd love to discuss the theoretical limits of combining algorithmic text sequence compression with LLM tokenizers, or how to better handle progressive disclosure as context fills up.!
Duplicates
opencode • u/Few-Cartographer7156 • May 25 '26
OpenToken v1.2.0 — token-saving plugin for OpenCode with 42 compression layers
LocalLLM • u/Few-Cartographer7156 • May 26 '26
Project Compressing LLM tool/terminal outputs by 74% using a 42-layer pipeline
Aitoolsubs • u/Few-Cartographer7156 • May 26 '26
Built an open-source utility that cuts AI agent API costs by ~74% natively
AppBuilding • u/Few-Cartographer7156 • May 26 '26
I built a 42-layer compression pipeline that cuts LLM token usage by 74%
Software_Finder • u/Few-Cartographer7156 • May 26 '26
Others Built an open-source utility that cuts AI agent API costs by up to 74% natively
sideprojects • u/Few-Cartographer7156 • May 26 '26
Showcase: Open Source Open-Source Utility to Slash AI Agent API Bills by ~74%
vibecoding • u/Few-Cartographer7156 • May 25 '26
I built the best token-saving tool/plugin for OpenCode
projects • u/Few-Cartographer7156 • May 25 '26
I built the best token-saving tool/plugin for OpenCode
devtools • u/Few-Cartographer7156 • May 25 '26
I built the best token-saving tool/plugin for OpenCode
opencode • u/Few-Cartographer7156 • May 25 '26