pxpipe: Cut Claude Code Token Costs by 70% With This Ingenious Image Compression Trick

By Prahlad Menon 2 min read

Your Claude Code bill is probably 3x higher than it needs to be.

Here’s why: text input costs roughly one token per character. But images? Fixed cost based on pixel dimensions — regardless of how much text is packed inside. Dense content like code, JSON, and tool output can squeeze ~3.1 characters into every image token, versus ~1 character per text token.

pxpipe exploits this pricing gap with a local proxy that renders the bulky parts of your requests into compact PNGs before they leave your machine. The result: 59-70% lower bills on token-heavy workloads.

The Math That Makes This Work

A 1928×1928 image costs approximately 4,761 vision tokens and can hold ~92,000 characters. Text wins only above ~19 chars/token — but Claude Code traffic runs around 1.91 chars/token.

In concrete terms:

  • ~48,000 chars of system prompt + tool docs: ≈25,000 tokens as text, ≈2,700 tokens as an image
  • One real session: $42.21 at 96% context full → $6.06 with pxpipe at 73.5k/1M tokens

That’s not cherry-picked. The proxy logs every request to ~/.pxpipe/events.jsonl with both the compressed cost and an exact count_tokens counterfactual, so you can verify savings on your own workload.

What Gets Compressed

pxpipe is surgical about what it touches:

Content TypeTreatment
Large tool results (>6k chars)Rendered as images
Older collapsed historyRendered as images
System prompt + tool docsRendered as images
Recent messagesAlways text
Model outputNever touched
Sparse proseStays text (profitability gate)

The key insight: recent turns stay as text so the model can work accurately on active content. Only the static, token-dense bulk gets compressed.

Installation

Two commands:

npx pxpipe-proxy                           # Start proxy on 127.0.0.1:47821
ANTHROPIC_BASE_URL=http://127.0.0.1:47821 claude  # Point Claude Code at it

The dashboard at http://127.0.0.1:47821 shows tokens saved, every text→image conversion side by side, and a kill switch. Responses stream normally — pxpipe only compresses requests, never output.

The Tradeoffs (Read This)

pxpipe is honest about its limitations:

1. It’s Lossy

Image processing isn’t OCR — pixels become patch embeddings, not discrete characters. When a glyph is ambiguous, the language model fills in something plausible. Exact 12-char hex strings in dense renders:

  • Fable 5: 13/15 correct
  • Opus 4.8: 0/15 correct

Misses are silent confabulations, not errors. The model confidently returns a wrong hash. For byte-exact values (IDs, cryptographic hashes, secrets), keep them as text.

2. Model-Dependent Accuracy

ModelStatusNotes
Claude Fable 5Default ✅100/100 on novel arithmetic
GPT 5.6Default ✅Comparable accuracy
Opus 4.7/4.8Opt-in only~7% misread rate
GPT 5.5Opt-in onlyDegrades on imaged context

The default models read renders flawlessly. Older models are disabled because they misread too often.

3. Latency

PNG encoding adds processing time before requests leave. For most workloads this is negligible, but time-sensitive applications should test.

Benchmark Results

Measured with novel random-number problems the model cannot have memorized:

TestNText Accuracypxpipe AccuracyToken Savings
Novel arithmetic (Fable 5)100100%100%-38%
Novel arithmetic (Opus 4.8)100100%93%-38%
Gist recall A/B (Fable 5)98/arm98/9898/98-
State tracking (Fable 5)18/arm18/1818/18-
Confabulation test (Fable 5)16/arm0/160/16-

SWE-bench Lite: 10/10 both arms at -65% request size.
SWE-bench Pro: 14/19 vs 15/19, verdicts agree 18/19.

The single disagreement resolved 3/3 on replication — run-to-run variance, not compression artifacts.

The Escape Hatch

For work requiring byte-exact accuracy, route to subagents on non-allowlisted models:

CLAUDE_CODE_SUBAGENT_MODEL=claude-sonnet-4-6

Or set model: sonnet in agent frontmatter. These pass through as text, giving you full precision when needed.

Why This Matters for the Industry

pxpipe represents an interesting arbitrage against current pricing models. If this approach catches on, AI providers might respond by:

  1. Raising image processing prices
  2. Detecting and blocking rendered text
  3. Offering native text compression

For now, the gap exists and pxpipe exploits it legitimately. The channel it uses is the same vision system that Anthropic’s computer use already relies on for screenshots — it’s just being used more efficiently.

Complementary Tools

pxpipe fits into a broader cost-optimization stack:

ToolWhat It Does
pxpipeCompresses static context as images
rtkCompresses CLI output
Structured project contextReduces redundant file reads
Session resetsClears accumulated context
Model routingUses cheaper models for simpler tasks

We’ve covered several of these approaches: running Claude Code locally with zero API fees, extending context with RAG, and choosing the right model tier.

The Meta-Point

What’s remarkable about pxpipe is that it was largely written by Claude agents running behind pxpipe itself — reading their own collapsed history as image pages while working. The README explicitly acknowledges this.

This is the kind of tool that emerges when developers actually use AI coding assistants daily: they feel the cost pressure, notice the pricing asymmetry, and build infrastructure to exploit it.

Try It

GitHub: teamchong/pxpipe
License: MIT
Requirements: Node.js, Claude Code or compatible client

If you’re running Claude Code heavily and watching tokens burn, pxpipe offers a 59-70% reduction without sacrificing context. The math is logged per-request, so you can verify savings on your own workload before committing.

Just remember: recent turns stay text, exact strings need the escape hatch, and the default models are the accurate ones. Within those constraints, it’s essentially free money.


Running AI coding agents? Check out our coverage of Claude Code’s 48-agent studio architecture, local Claude Code with zero API fees, and why RAG isn’t dead even with 1M context.