costcut

The token-reduction layer for AI-agent context.

Compress tool output and large reads before they hit the model — and expand any elided region back to the byte-identical original on demand. Lossy in the prompt, lossless in the store.

100% free · MIT licensed · no accounts, no limits, no payments

92.3% on JSON · library · CLI · proxy · MCP · local-first · no ML

Install Docs
pip install costcut

# wrap any read-only command — get a compact view + a handle
costcut wrap --kind json -- cat big_state.json
costcut get <handle>            # expand back, byte-identical
costcut get <handle> --lines 40-80   # or just a slice

What gets compressed

JSON dumps

Long homogeneous arrays are sampled, huge scalar strings truncated — whitespace stripped. The flagship case.

Diffs & grep

Diff hunks and grep matches are headed-and-summarised, with the full body one costcut get away.

File reads & logs

Large reads and git logs collapse to a head plus a retrievable pointer; code files can use a signature view.

Nothing under ~6 KB

Small outputs pass through verbatim — there is nothing worth eliding, and no store entry is created.

Four ways to run it

Library

compress() / retrieve()

CLI

wrap · get · gc · bench

Proxy hook

costcut init

MCP server

costcut_compress …

Real, reproducible results

Measured by costcut bench with the neutral o200k_base tokenizer — and every row round-trips byte-identically. Run it yourself; the numbers are the product's own.

Input Tokens raw → compact Reduction Restore
JSON state dump (60 records) 6055 → 466 92.3% byte-identical
ripgrep match dump 3080 → 1728 43.9% byte-identical
multi-file git diff 5948 → 4922 17.2% byte-identical

Structural diff/grep defaults are conservative — they keep more context and are not tuned to flatter the corpus.

Nothing is lost

Every compact rendering names a handle and the exact command to recover the rest:

--- CTXTEE json cut=54items handle=33d6f94 get="costcut get 33d6f94" ---

The full original lives in a local SQLite store (~/.costcut, durable 7 days). Retrieve the whole thing or a precise slice — a line range, one file's matches, a single diff hunk, or a symbol body — many turns later, with no re-run. No data ever leaves your machine.

Install — it's free
pip install costcut
Read the docs
guides & API