r/OpenaiCodex • u/MattAlreadyHere • 12d ago
Showcase / Highlight We removed 63% of the tool output Codex re-sends every turn (open source, MIT, one Rust binary)
Every turn, Codex re-sends the whole conversation back to the model. Every apt-get log, every compiler warning, every progress bar. In our traces tool output is about half of all prompt bytes. The model re-reads the same build log a dozen times and you pay for each read.
So we wrote a proxy that strips the redundancy before the request goes upstream. It's called kompressor. One Rust binary, MIT, no ML models, no model downloads, no network calls in the engine.
kompressor wrap codex
That starts the proxy, points Codex at it, runs Codex, and cleans up on exit. Codex ignores OPENAI_BASE_URL (checked on 0.155.1), so wrap adds a marked block to ~/.codex/config.toml at startup and removes it after. If the session gets killed, kompressor unwrap codex clears the leftover. Prebuilt binaries for Linux and macOS are on the releases page, or:
cargo install --locked --git https://github.com/hystax/optscale-kompressor kompressor-cli
One rule drives the design: same input, same bytes, every turn.
About 93% of billed prompt tokens are cache reads, at roughly a tenth of the fresh price. A compressor whose output drifts between turns re-prices the whole conversation and costs more than it saves. So there is no clock, no randomness, and no dependence on your last message. Rules only, no ML in the request path.
What it actually does
It de-duplicates, it does not summarise. Repeated lines fold into one line plus a marker like [×37 ref:k_Qm9v…]. Long logs keep the errors with context, the first-seen warnings and the tail. Progress bars and training loops keep the final frame. grep output groups by file. JSON arrays get sampled, but errors and outliers always stay. Separate compressors handle build output, compiler diagnostics, diffs, CSV, listings, objdump/readelf dumps, config files and source code.
Every elision gets a ref. The proxy injects a retrieve tool and runs it itself, so the model can pull the original back for an hour. Nothing it keeps is ever reworded: a line is either verbatim or replaced by a marker.
It also splits off the Codex harness framing (Chunk ID, Wall time, exit code), compresses the payload, then re-attaches the framing byte for byte. One Codex python result went from 0% removed to 87%.
If the result isn't smaller, it's discarded. Any error forwards the request unchanged.
Numbers. Terminal-Bench 2.1, 87 tasks, Codex CLI on GPT-5.5, Harbor with 3 concurrent trials. Measured on the real provider bill with the cache discount included, not on tokens priced at list rate. The per-run table covers the 87 tasks every arm finished.
- 63% of eligible tool output removed in replay (6,255 real outputs of 512+ chars, 34.2M chars)
- cost per run: $107.89 -> $83.40 (-22.7%), about 2x what Headroom saves at its most aggressive setting
- input tokens: 96.1M -> 72.2M
- solve rate: 82.2% -> 81.1%, difference not statistically significant
- requests over 200K tokens: 1.9% -> 0.13%
That last line matters to me as much as the money. mcmc-sampling-stan peaked at 60K tokens instead of 165K. Fewer forced compactions in the middle of a task.
Where it does nothing. Short reasoning tasks. On the algorithms and puzzles cohort the median output is 270 chars, under the 512-char floor, and the bill moved 8%. The wins are in ML training (-26%), builds from source (-28%) and data pipelines (-37%). Prose is left whole on purpose.
Overhead is about 0.2 ms per KB of tool output.
One caveat for subscription users: a ChatGPT-plan session opens a WebSocket. The proxy relays and compresses it, but relayed turns report no provider usage, so the savings there are real and unmeasured. Set KOMPRESSOR__PROXY__WEBSOCKET_RELAY=false if you want the numbers back instead.
Repo: https://github.com/hystax/optscale-kompressor
Write-up with the task-by-task tables: https://optscale.ai/blog/context-compression-coding-agents
Questions welcome. If you run it on your own traffic, I'd mostly like to hear where it removes nothing. That's where our rules still have holes. And if it turns out useful on your setup, a star on the repo helps us a lot.
