60% Fable cost cut by converting code to images and having the model OCR it
Reducing Fable Costs by 60%: Converting Code to Images for OCR
The pxpipe project aims to drastically lower the input token overhead for Claude Code by transforming voluminous context—such as system prompts, tool documentation, and conversation history—into images.
💡 The Core Concept
The fundamental insight is that image token costs are determined by pixel dimensions, regardless of how much text is contained within the image. For dense data like JSON or source code, this creates a massive efficiency gap.
Token Efficiency Comparison
| Content Type | Text Token Efficiency | Image Token Efficiency |
|---|---|---|
| Dense Content | char / token | chars / token |
| Cost Basis | Per character/token | Per pixel area (fixed) |
pxpipe acts as a local proxy. It intercepts your request and rewrites the "bulky" sections into compact PNGs before they are sent to the model.
📉 Measured Impact
While savings vary by workload, the reduction in input tokens is significant and durable.
- Token Reduction: In one example, text tokens were compressed into image tokens.
- Financial Savings: Based on current Fable pricing, this results in an end-to-end bill reduction of 59% to 70% (reaching for highly compressed requests).
[!IMPORTANT] Focus on tokens, not dollars. While pricing fluctuates, the reduction in token count is a constant technical advantage.
🛠️ How it Works
The transformRequest pipeline processes text by:
- Minifying whitespace.
- Reflowing text into full rows.
- Marking original newlines with the
↵symbol. - Adding an OCR instruction banner at the top of the render.

🧪 Benchmarks & Demos
Fable 5 (The Optimized Target)
Fable 5 demonstrates a 100/100 reading accuracy on clean evals.
- The Test: Counting specific phrases across 39 filler files and performing multi-step ledger arithmetic ().
- The Result:
pxpipematchedgrepground truth line-for-line. - Cost Comparison:
Plain Claude: $42.21(Context 96% full)- pxpipe: $6.06 (Plenty of context remaining)
Note: A slight trade-off was observed in format compliance; the imaged arm occasionally required a follow-up nudge to adhere to a specific one-line output format.
Opus 4.8 (The Baseline)
Opus is disabled by default as pxpipe is tuned for Fable.
- Success: Successfully fixed a failing test suite with a fraction of the tokens.
- Failure: Could not perform the "phrase-count" task on imaged filler files. Opus correctly admitted it couldn't read the image rather than fabricating a number.
⚠️ Critical Limitations
Not all data should be imaged. There is a documented lossy limit regarding precision.
- Do NOT image: IDs, hashes, secrets, or exact numerical values.
- Safe to image: General documentation, system prompts, and older history.
The Risk: In "needle-in-a-haystack" tests using 12-character hex strings, Opus scored and Fable 5 scored . The failure mode is silent confabulation (providing a plausible but incorrect value) rather than an error message.
🚀 Quick Start
You can deploy the proxy in about 30 seconds:
# 1. Start the proxy
npx pxpipe-proxy
# 2. Point Claude Code to the local proxy
ANTHROPIC_BASE_URL=http://localhost:47821 claude
Dashboard: Visit http://127.0.0.1:47821/ to monitor:
- Tokens saved and per-session statistics.
- Side-by-side text image conversions.
- Global kill switch and model selection (including GPT 5.5/5.6).
Model Routing
pxpipe only images requests for Fable (PXPIPE_MODELS=claude-fable-5). To ensure byte-exact accuracy for specific tasks, route them to a non-Fable model:
CLAUDE_CODE_SUBAGENT_MODEL=claude-sonnet-4-6