Overview
CliffCompaction is a proxy you run between a coding agent and its model provider. When the conversation it is forwarding crosses a token threshold, it rewrites the request with a shorter history and passes it upstream. The agent is not modified and never learns that anything was removed, so the same proxy works for Claude Code, Codex CLI and anything else speaking the Anthropic Messages or OpenAI Chat Completions and Responses APIs.
The design rests on one rule: only truncate or drop, never rephrase. Summarising earlier context into new prose is what most harnesses do, and it lets errors compound, because each pass is a summary of a summary. CliffCompaction instead keeps system prompts, task descriptions and the most recent turns byte-for-byte, caps assistant reasoning and tool-call signatures to a character budget, and discards long tool results outright on the grounds that the files behind them are still readable with another tool call.
The second rule follows from the first: a compaction is never compacted. Each time the threshold is crossed the proxy throws away the previous compacted history and recompresses the live session from its original content, so no piece of text is ever passed through the shrinking process twice. The method is described in arXiv:2609.26779 by Trang Nguyen, Eulrang Cho and Tim Dettmers of Carnegie Mellon University with Bingqing Chen of the Bosch Center for AI, which reports up to 50% lower cost on Terminal-Bench 2.0 at a slightly higher success rate.
What it does
- Transparent proxy for Anthropic Messages, OpenAI Chat Completions and OpenAI Responses — the agent runs unchanged behind it
- Truncate-and-drop compaction that never rephrases text, and never compacts an already-compacted history
- System prompt, task description and the most recent turn pairs are forwarded verbatim
- Per-field character budgets for tool results, assistant text and thinking blocks, each settable by flag or environment variable
- Shadow mode that reports what would be compacted while leaving the real requests untouched
- Background daemon with status, restart, live-watch and disable commands, or a one-off proxy scoped to a single command
Getting started
CliffCompaction installs as a Python tool and exposes a single `cliff` command. Enabling it installs a background daemon and points your agent's configuration at the proxy.
Install the tool
The package requires Python 3.11 or newer.
uv tool install cliffcompaction
# or
pip install cliffcompactionEnable the proxy for Claude Code
`cliff enable` installs the background daemon with default settings and rewrites the agent configuration to route through it. `cliff status` checks the daemon is healthy and `cliff watch` prints requests and compaction events as they happen.
cliff enable
cliff status
cliff watchWatch it first without changing anything
Shadow mode forwards every request untouched and only reports what it would have compacted, which is the safe way to see whether the threshold is set sensibly for your workload.
cliff run --shadow -- claudeTune the budgets
The token threshold defaults to 200,000, three recent turn pairs are kept, and tool results are capped at 500 characters. Every setting has a flag and an environment variable.
cliff serve --threshold 32000 --keep-recent 3 --result-max-chars 500
CLIFF_THRESHOLD_TOKENS=32000 cliff run -- codexTurn it off
`cliff disable` removes the daemon and reverts the configuration changes that `cliff enable` made.
cliff disableCommands and code are distilled from the project's own documentation — always check the official repo for the latest.
When to use it
- Hold a multi-hour coding-agent run inside a fixed token budget without editing the agent or its scaffold
- Cut the input-token bill of a long session, where the whole history is re-sent on every single turn
- Run a small-context or cheaper model on a long task that would otherwise overflow its window
- Measure what compaction would remove from your own traffic, via shadow mode, before switching it on
How CliffCompaction compares
CliffCompaction alongside other open-source context compression & token budgets tools AI/TLDR tracks, ranked by GitHub stars.
| Tool | Stars | What it does |
|---|---|---|
| RTK | ★ 81.5k | A single-binary Rust CLI proxy that filters, groups, truncates and dedupes the output of 100+ dev commands before a coding agent reads it, cutting token use by 60–90%. |
| Headroom | ★ 73.6k | Local context-compression layer that shrinks tool outputs, logs, files and RAG chunks before they reach the model, usable as a library, a drop-in proxy or an MCP server. |
| TOON | ★ 25.4k | Token-Oriented Object Notation: a lossless, compact encoding of the JSON data model that declares row counts and field lists so tabular data costs fewer prompt tokens. |
| Context Mode | ★ 24k | An MCP server that keeps raw tool output out of the context window by sandboxing it, and indexes session events into SQLite FTS5 so an agent survives compaction. |
| pxpipe | ★ 7.4k | A local proxy that renders bulky request context — system prompt, tool docs and older turns — as PNG pages the model reads with vision, cutting the input tokens a coding agent re-sends each turn. |
| LeanCTX | ★ 3.8k | Local context layer for coding agents with ten file read modes, 95+ shell-output compressors, reversible content-addressed recovery, session memory and a savings ledger. |
| CliffCompaction | — | A transparent proxy that compacts agent history by cutting, never rewriting |