How OpenToken compression works
mainOpenToken acts as a transparent filter between a tool's runtime and the LLM context window. It uses a pipeline architecture to reduce token usage by 50-80% without losing semantic meaning.
The Pipeline Process
- Secrets Redaction: Runs first to ensure sensitive data is removed.
- Binary Detection: Uses a NUL byte guard to prevent corruption of binary streams.
- ANSI Stripping: Removes terminal color codes and control sequences.
- Family Detection & Routing: The engine detects the command context (e.g.,
git,npm,cargo) and routes the output to a specialized pipeline of 10-20 stages. - Conservative Safety Filter: Every stage ends with a filter that estimates BPE token counts. If a stage increases the token count, the original output is returned. This ensures a 0-risk principle where compression never regresses quality.
Compression Techniques
- Noise Reduction: Pre-call rewrites (adding
--quietor-qto commands), JSON cleanup, and path shortening. - Structural Compression: Diff folding, log folding (collapsing identical lines), and line noise normalization (replacing timestamps/PIDs with placeholders).
- Advanced Compression: LTSC (Lossless Token Sequence Compression), LZW token substitution, and reversible compression.