Fewer tokens, same answers: hands-on with Pithio, the local context compressor for coding agents
Pithio shrinks the tool output your coding agent reads — test logs, JSON API pages, CI failures — before the model sees it, and keeps the original one command away. Install it, compress a real test run, and recover the exact lines you need.
pip install pithio==0.1.4, compress any command with pithio run --, and fetch details back with pithio more, q, or grep. In this sandbox a 200-line test run fell from 1,802 to 103 tokens with both failures intact, and a 100-row JSON response fell 57% with all five 500s named. Every command in this tutorial was executed on December 5, 2026.- Why now: Pithio was created December 3, 2026 and reached Hacker News’ front page as a Show HN post on December 5; ten GitHub stars at the time of writing, six releases, current version 0.1.4.
- What it does: shortens terminal output, logs, JSON, CSV, YAML and web/MCP results before the model reads them; every shortened output names what was left out and carries a handle to the stored original.
- Install:
pip install pithio==0.1.4— one package, no dependencies, no daemon. Also on npm, or via the shell installer in the README. - Recovery:
pithio more HANDLE --grep FAILEDfor exact lines,pithio q HANDLEfor SQL over the stored output,pithio grep HANDLEfor text search. - Verified here: install, doctor self-test, a 200-line test run (1,802 → 103 tokens), a 100-row JSON response (3,702 → 1,604), agent setup and removal, gain/show/audit. The Python SDK was imported and its signature checked; no live API call was made.

Your coding agent reads everything its tools print. A test suite prints two hundred lines to say two things failed. A GitHub API page prints a hundred near-identical JSON objects to answer one lookup. A CI log repeats the same warning a thousand times. Every one of those lines costs tokens, and tokens are the meter running on every agent session.
Pithio is a small local tool that shortens tool output before the model reads it — and, unlike a summarizer, it keeps the original on your machine and gives the agent a way to fetch any detail back. It was created on December 3, 2026, reached Hacker News’ front page as a Show HN post on December 5, and had ten stars on GitHub on the evening of December 5. Small numbers, but the idea is the one every agent user has had while watching a context window fill with repeated lines. This tutorial installs Pithio 0.1.4, compresses a real 200-line test run, recovers exact lines from the compressed output, wires it into two coding agents, and measures what it saved — every command below was run in a sandbox on December 5, 2026.

What you’ll need#
- Python 3.9 or later with pip, or Node.js for the npm install. The tutorial uses pip on Linux; macOS works the same way, and Windows uses the PowerShell installer from the README.
- A coding agent (Claude Code, Codex, Cursor, Gemini CLI, or one of the 22 agents Pithio supports) for step 5. Steps 1–4 and 6 need no agent at all.
- No API key, no account, no GPU. Everything runs locally; Pithio sends nothing anywhere. Originals are kept for one day in
~/.pithio, and outputs that look like they hold a secret are never stored. - About 20 minutes. The install is one package with no dependencies.
1. Install Pithio#
Install from PyPI and confirm the version. Pin it: this is a three-day-old project on its sixth release, and the interface is still moving.
pip install pithio==0.1.4
pithio --version
# pithio 0.1.4
The install is clean — one package, no dependencies, no daemon, no background service. The same release is also available as npm install -g pithio, as a shell installer (curl -fsSL https://raw.githubusercontent.com/allenjoseph05/pithio/main/install.sh | sh), or as a prebuilt binary from the repo’s Releases page. The project is Apache 2.0 licensed; versions 0.1.0 and 0.1.1 were first released under the Functional Source License, and are also available under Apache 2.0.
Run the built-in self-check before doing anything else:
pithio doctor
pithio doctor
ok pithio 0.1.4 at /tmp/pithio-test/bin/pithio
ok store ~/.pithio is writable; 2 originals kept (0.0 MB; each kept one day)
info Claude Code: no pithio hook found (set up with `pithio setup claude-code`)
ok self-test: a 120-item list shortened 1683 -> 1036 tokens; item 57 recovered
Doctor checks the binary, the local store, which agents are wired up, and runs a self-test: shorten a 120-item list and recover one item from it. If the self-test line is missing or fails, stop — the rest of the tutorial depends on it.
2. Compress a real test run#
The fastest way to see what Pithio does is pithio run, which runs any shell command and shortens its output. Build a realistic fixture first — a 200-line pytest-style run with two failures buried in it:
python3 - <<'EOF'
lines = []
for i in range(1, 201):
lines.append(f"test sample::case_{i:03d} ... ok")
lines[57] = "test sample::reports_expired_session ... FAILED"
lines[120] = "test sample::reports_expired_session ... FAILED"
open('sample-test.log', 'w').write("\n".join(lines) + "\n")
EOF
Now run it through Pithio instead of reading it raw:
pithio run -- cat sample-test.log
test sample::case_001 ... ok
[... 56 more lines of the kinds shown above (other numbers) ...]
test sample::reports_expired_session ... FAILED
[... 142 more lines of the kinds shown above (other numbers), 1 of them warnings or errors ...]
[pithio: level 2, repeats only: every kind of line is shown, repeats folded with exact counts; original 1802 tokens: pithio more 97e6785a1cbbaba5]
Two hundred lines became four. The token count fell from 1,802 to 103 — a 94% saving — and both FAILED lines survived: the note says level 2, “repeats only,” meaning every distinct kind of line is shown and repeats are folded with exact counts. The handle at the end (97e6785a1cbbaba5) is the key to the stored original. Every shortened output opens with a note like this one naming its level: level 1 is lossless (the same data, written more compactly), level 2 folds repeats, level 3 leaves some parts out and says what and how to get them. Short outputs and source files the agent is editing are left alone, and output is never larger than the input.
3. Get a detail back#
Compression is only safe if the details are recoverable. Three commands do that, all taking the handle from the note:
pithio more 97e6785a1cbbaba5 --grep FAILED
58: test sample::reports_expired_session ... FAILED
121: test sample::reports_expired_session ... FAILED
[2 of 201 lines match "FAILED"]
more reads the stored original page by page; --grep filters it to matching lines, with line numbers. For structured data, q runs SQL against the stored output:
pithio q 97e6785a1cbbaba5
table "$": 200 rows (exact)
columns: line number 200 values, e.g. 1; time (always empty); level (always empty); kind text 2 values, e.g. "test sample::case_# ... …"; problem bool 2 values, e.g. false; text text 199 values, e.g. "test sample::case_001 ..…"
e.g. pithio q 97e6785a1cbbaba5 "SELECT kind, COUNT(*) WHERE problem GROUP BY kind ORDER BY COUNT(*) DESC LIMIT 5"
And pithio grep HANDLE "worker 7" returns the lines containing a string. This is the part that separates Pithio from a summarizer: the agent is not trusting a model’s paraphrase, it is querying the exact original bytes, and the counts are exact — q answers “how many 500s” by counting, not by estimating.
4. Compress structured data: JSON API responses#
Test logs are the easy case — repeats fold cleanly. JSON is the harder one, because every object looks alike and the differences are the data. Generate a 100-row API response and run it through:
python3 - <<'EOF'
import json
rows = [{"id": i, "status": 200 if i % 17 else 500,
"path": f"/api/v1/items/{i % 5}", "ms": 12 + i % 40}
for i in range(1, 101)]
json.dump(rows, open('sample-api.json', 'w'), indent=2)
EOF
pithio run -- cat sample-api.json
[pithio: NOTE level 1, lossless: all 100 items are shown below (no item left out); value counts over all 100 items: status: 200 95, 500 5; path: /api/v1/items/0 20, /api/v1/items/1 20, /api/v1/items/2 20, /api/v1/items/3 20, /api/v1/items/4 20; ms: min 12, max 51, mean 29.7 (mean rounded)]
"§1"
§1 = table 100 rows
cols: #|id:i|path|ms:i
rules (the same value in every row, except the rows numbered):
status = 200
except {"17":500,"34":500,"51":500,"68":500,"85":500}
1|1|/api/v1/items/1|13
2|2|/api/v1/items/2|14
...
The 100 objects became a table with one rule — status = 200 — plus the five exceptions, rows 17, 34, 51, 68 and 85. Token count fell from 3,702 to 1,604, a 57% saving, and the note claims level 1, lossless: every item is still shown, and the five 500s are named explicitly. That is the design working as intended — the exceptions are the information, and they are the part that survives. Keep the skepticism for step 6, where the audit command checks exactly this kind of claim.
5. Connect your coding agents#
pithio run is the manual mode. The point of the tool is the automatic one: register a hook with each agent so its tool outputs are shortened from the next session onward. Pithio supports 22 agents, including Claude Code, Codex, Cursor, Copilot, Gemini CLI, Pi, OpenCode, Aider, Cline, and Windsurf.
pithio setup # every agent found on this computer, all projects
pithio setup codex # one agent only
pithio doctor # check the setup
On this machine, setup connected seven agents it found — Claude Code (~/.claude/settings.json), Codex (~/.codex/hooks.json), Cursor, Gemini CLI, Mistral Vibe, Pi, and OpenCode — and printed a warning that pithio was not on PATH, which matters because Codex, Cursor, Copilot, Gemini and others invoke it by name. Add the install directory to PATH before restarting the agents. Agents that only read project rules (Aider, Cline, Windsurf and others) need pithio setup <agent> run inside each project instead.
Two things to know before you run setup. First, it edits your agents’ settings files — that is the whole mechanism, a hook registration, not a background process. Second, it is fully reversible: pithio remove (or pithio remove codex for one agent) takes the hooks back out. I ran both directions in the sandbox; after remove, no pithio reference remained in any of the seven settings files.
6. Measure what you saved#
Pithio keeps score, which is what makes the claim testable rather than vibes-based:
pithio gain
pithio show
pithio audit
Period (UTC) Tokens saved Est. USD saved
Today 3797 0.0152
This week 3797 0.0152
All time 3797 0.0152
Metered tool-result tokens, counted once. Estimate uses claude-opus-5-5 fresh-input pricing at $4.0/million. Week starts Monday UTC.
gain reports tokens saved by period with a dollar estimate (the pricing basis is printed in the output — Claude Opus 5.5 at $4.00 per million fresh-input tokens — so adjust it mentally if your model is cheaper). show lists recent shortened outputs next to their originals, with the token counts: my two runs showed 3,702 → 1,604 and 1,802 → 103. audit checks every stored output against what its note promised: same input gives the same output, error and failure lines are kept, and the JSON codec round-trips. On my run it passed the level-2 output and the determinism checks — and flagged the level-1 contract on my JSON sample as unverified (“0 of 1 verified”). The original is still stored and retrievable, so nothing was lost, but the flag is worth knowing: a “lossless” note is a claim, and audit is the command that tests it. Run audit after any session where the numbers matter to you.

7. Use it from Python: the SDK#
If you build agent apps rather than just using agents, Pithio ships a Python SDK (pip install pithio-sdk) that wraps an Anthropic or OpenAI client so tool results are shortened in every request, with a recovery tool added for the model:
import pithio
client = pithio.wrap(anthropic.Anthropic())
# wrap(client, shorten=True, record=True, add_recovery_tool=True,
# keep=0.5, min_tokens=300, store=True, store_dir=None, log_path=None)
I verified the install and the wrap signature — it takes a sync or async Anthropic or OpenAI client and returns the same client — but I did not execute a live API call against it, because that needs an API key and a paid call, so treat the SDK as documented-and-importable rather than end-to-end verified here. The same caveat applies to the two server modes in the README, the MCP gateway (pithio serve --config PATH) and the local proxy (pithio proxy on 127.0.0.1:8788): both are documented, neither was exercised in this tutorial.
When to use this vs alternatives#
Use Pithio when your agent sessions burn context on repetitive tool output — long test runs, CI logs, JSON API pages, search results — and you want the savings without giving up exact recovery. It is free, local, and the hook model means you set it up once per agent rather than changing how you work.
Use the agent’s built-in compaction instead when the problem is a long conversation rather than verbose tool output. Compaction summarizes the whole session; Pithio shortens individual tool results as they arrive. They solve different halves of the same bill and can run together.
Use a proxy-based compressor such as Headroom — covered in this blog’s hands-on Headroom tutorial — if you want compression applied at the API boundary for every model call, including calls Pithio’s hooks never see. The trade-off is architectural: a proxy sits in the request path, while Pithio sits in the agent’s tool-output path and stores originals locally for exact recovery.
Skip all of it if your sessions are short and your outputs are small. Compression earns its keep on long sessions with repetitive output; on a ten-minute task it saves pennies and adds a moving part. And if your workflow is mostly prose rather than tool output — drafting, editing, research — there is nothing repetitive for Pithio to fold, and it leaves those outputs alone by design.
What the benchmarks claim — and what they don’t prove#
Pithio’s own benchmark page reports that, on 171 questions generated from 50 real developer tool outputs, Claude Haiku answered 157 correctly reading shortened output against 148 reading the original — 91.8% versus 86.5% — while input tokens per tool output fell from 39,775 to 28,330. On Loghub system logs the gain was larger: 40 of 54 correct against 31, with tokens down 60%. Research-paper questions (Qasper) moved from 57.2% to 61.7%. Ten GitHub API commit pages shrank by 92.2% with all 27 answers still visible in the shorter view.
Read those numbers with the methodology attached: questions and scoring were fixed before each run, each set was run once, the model was Claude Haiku, tokens were counted with o200k, and the work is dated December 2026. Single runs on one model, self-reported by the project, are evidence, not proof — and the direction is worth noting, because a tool that throws away information should make answers worse, not better. The plausible mechanism is that shorter, de-duplicated output is easier for the model to scan than pages of repeats. The safety checks are the more load-bearing numbers: across 805 development inputs, zero outputs longer than the input, zero empty outputs for non-empty input, zero nondeterministic outputs, and 95th-percentile shortening time of 161 ms for outputs under 8,000 tokens. My own measurements — 94% off a test log, 57% off a JSON table, exact line recovery — are consistent with the project’s claims at small scale, which is the most this tutorial can honestly say.
The takeaway#
Pithio does one narrow thing well: it makes the text your agent reads shorter without making the details unreachable. The install is a single pip package, the first compression takes one command, and the recovery path — more, q, grep against the stored original — is the feature that makes the compression safe to trust. The project is three days old, the audit command flagged one of my two samples, and the benchmarks are single-run and self-reported, so treat it as a promising early tool rather than settled infrastructure. But the core loop ran exactly as documented in this sandbox, the savings on real tool output are large, and the undo is one command. If your agent’s context window keeps filling with repeated lines, that is a cheap experiment to run.
Sources: Pithio on GitHub — allenjoseph05/pithio; Pithio — Benchmarks; Show HN: Pithio — fewer AI tokens, better context. All commands in this tutorial were executed in a sandbox on December 5, 2026; outputs are quoted verbatim except for file paths.