How to Feed a Neural Network a Wall of Code as an Image and Save 60% on Your Token Budget
I recently caught myself thinking that we've grown accustomed to treating language model context windows exclusively as text. You send a file of 50,000 characters and pay for 12–15,000 text tokens. If you're running Claude Code or Cursor for hours, the context constantly gets topped up with system instructions, tool documentation, and command execution logs. The API bill at the end of the month starts to become an unpleasant surprise.
The developers behind the pxpipe project noticed an interesting loophole in modern multimodal model pricing. The cost of an image in tokens depends only on its physical resolution in pixels, not on how much text is drawn on it. If you compress dense text into a compact screenshot with small font, one image token can hold roughly 3–5 times more characters than a standard text token.

And that's how the idea of a local proxy server was born—one that redraws heavy parts of a request into monochrome PNG pages on the fly before sending them to Anthropic or OpenAI.
How This Trick Works
In text format, dense data like JSON, database dumps, or code is consumed at a rate of roughly one character per token. Meanwhile, modern models like Claude 3.5 Sonnet, Claude Opus, or Gemini recognize raster images excellently through their built-in vision modules.
The pxpipe tool intercepts outgoing API requests on your machine and slices unwieldy context into dense images with a custom monospace font (for example, Spleen 5×8 or JetBrains Mono).

Instead of 25,000 tokens of raw text for the system prompt and tool descriptions, the model receives a couple of images weighing just 2,700 tokens. For a context window of 1 million tokens, this increases actual character capacity nearly fivefold: from 4 million characters to 19–21 million.
What Gets Compressed and What Stays as Text
If you turn the entire dialogue into an image, the model will inevitably start making mistakes with precise identifiers. The pxpipe developers accounted for this, so compression works selectively:
- Large tool execution results. If console command output, test logs, or a read file exceeds 6,000 characters, they get converted to PNG.
- Old message history. Early steps in a long session are packed into archive pages.
- Heavy system prompts and MCP tool specifications. They are cached and sent as a graphics sheet.
The user's latest replies, fresh model responses, and short text snippets are transmitted in their original text form unchanged. The model sees recent edits byte-for-byte.
Quick Start and Connecting to Agents
You can run the utility without permanent installation via npx. It spins up a local server on port 47821:
npx pxpipe-proxy
After that, just point Claude Code to the local address:
ANTHROPIC_BASE_URL=http://127.0.0.1:47821 claude
If you don't want to deal with environment variables, the repository includes a wrapper command warp. It proxies network calls for a specific process:
pxpipe warp -- claude
# либо для других агентов
pxpipe warp -- cursor-agent
Along with the proxy, a web dashboard starts at http://127.0.0.1:47821/. It displays saved dollars in real time, the number of trimmed tokens, and a preview of each generated page alongside the original text.
Export Without Spinning Up a Server
If you don't need a proxy but want to feed a massive codebase or git diff into a chat web interface with image support, you can use export mode:
npx pxpipe-proxy export src/
cat logs.txt | npx pxpipe-proxy export --stdin
npx pxpipe-proxy export --git
The command creates a folder with ready-to-use page-*.png files, a brief file of key entities factsheet.txt, and a prompt to paste into the dialogue window.
The Other Side of the Coin and Honest Limitations
The approach looks like cheating, but it has inevitable physical limitations. The developers list them directly in the documentation:
- Loss of accuracy on hashes and IDs. The LLM vision module works through embedding patches, not classic OCR with per-character probability. When there aren't enough pixels per letter, the language model simply invents a plausible character. In the authors' tests, exact matches of 12-character hex strings on Fable 5 came to 13 out of 15, and on some models dropped to zero. Critical identifiers are better kept in text.
- Rendering delay. Before sending a large request, the processor spends several hundred milliseconds generating PNG buffers in memory.
- Benefit depends on content density. Savings are maximum on code, stack traces, and JSON structures. On regular conversational text in natural language, the gain is minimal or absent entirely, because in regular text one token already holds about 3–4 characters.
Who the Project Will Be Useful for Right Now
If you regularly use autonomous coding agents, run benchmarks, or feed the model multi-megabyte build logs, pxpipe pays for itself from day one. On long debugging sessions, the daily bill drops from $40 to $6–7 while preserving the overall logic of the agent's operation.
You can try the tool in a couple of minutes, and for the first test you don't even need to build anything from source. All token statistics are neatly stored by the utility in a local log ~/.pxpipe/events.jsonl, so you can easily verify the real benefit on your tasks with the pxpipe stats utility.
Related projects