[VisionSqueezer Logo]
VisionSqueezer
[Build]
[crates.io]
[npm]
[License]
Fit images to a vision-LLM token budget before they reach the model. A library, CLI, and MCP server for code, agents, and pipelines.
What it does not do. VisionSqueezer cannot shrink an image you paste, drag, or @-attach into a chat window (Claude Code, Cursor, ChatGPT, and so on). The client attaches it before any tool or hook runs, so it is billed at full size.
Where it does save tokens:
- Images your code sends to a model API: the Rust crate, the Python bindings, the CLI.
- Images an agent reads from files or gets through tools (screenshots, crawlers, browser automation): the MCP server, or the Claude Code image-read hook for files inside the project.
See Where it saves tokens for the exact cases.
The MCP server runs in any MCP client (Claude Code, Cursor, Codex, Gemini CLI, and others), but it only sees images the agent passes to it.
[Vision Squeezer MCP server]
Install
One command per client (recommended)
Every client has exactly one install path, and the installer picks it:
JSON files are merged, never replaced: other servers and hooks are kept, a file that cannot be parsed is left untouched, and re-running replaces our own entry instead of adding a second.
The scope (user, local, project) is asked only when the client supports more than one. --method from older versions is accepted and ignored.
The manual commands below use npx -y vision-squeezer for brevity. Pin it as vision-squeezer@<version> (the installer does this for you): an unpinned npx keeps serving whatever version it cached first, even after a new release.
Claude Code
This runs the two commands below for you (and removes an older claude mcp add registration and settings.json hook first). To do it by hand:
Restart Claude Code, or run /reload-plugins, to load the MCP server, skills, and hook. Only want the MCP server, with no skills and no hook? claude mcp add --scope user vision-squeezer -- npx -y vision-squeezer.
Claude Desktop
Or add to claude_desktop_config.json (macOS: ~/Library/Application Support/Claude/, Windows: %APPDATA%\\Claude\\):
Cursor
Or add to ~/.cursor/mcp.json (global) or .cursor/mcp.json (project):
Click here to view installation instructions for 10+ other IDEs and Agents (VS Code, JetBrains, Windsurf, Zed, etc.)
VS Code Copilot
Or add to .vscode/mcp.json:
JetBrains (IntelliJ, WebStorm, PyCharm)
Open Tools → GitHub Copilot → Model Context Protocol (MCP) → Configure, then add:
Windsurf
Or add to ~/.codeium/windsurf/mcp_config.json:
Gemini CLI
Google replaced Gemini CLI with Antigravity CLI for free and Google One users on 2026-06-18. On Antigravity, see Antigravity.
Or add to ~/.gemini/settings.json (user) / .gemini/settings.json (project):
Codex CLI
Or add to ~/.codex/config.toml:
Qwen Code
OpenCode
opencode mcp add is interactive-only, so add directly to ~/.config/opencode/opencode.json (global) or opencode.json in the repo root (project):
Kimi CLI
Zed
Add to ~/.config/zed/settings.json:
Kiro
Add to .kiro/settings/mcp.json (workspace) or ~/.kiro/settings/mcp.json (global):
Antigravity
MCP-only, no hooks needed. Configure via the Antigravity MCP settings:
Manual install (Rust binary)
Then use the binary path directly in any config above instead of npx:
Tip: Run npx -y vision-squeezer --setup to print ready configs with auto-detected paths.
CLI Usage
Batch mode
Pass a directory instead of a file:
HTTP API (n8n, Make, Zapier)
vision-squeezer serve runs a small HTTP server, so any workflow tool can squeeze an image between two steps with a plain HTTP request. No custom node is needed.
Send the image bytes as the body of POST /optimize. Options go in the query string:
GET /health returns ok. Bodies over 25 MB get 413, bad input gets 400 with a one-line reason. There is no authentication: the server listens on 127.0.0.1 by default, and the Docker image listens on all interfaces inside the container, so publish its port only on a network you trust.
n8n. Put an HTTP Request node between the step that fetches the image and the vision model:
- Method
POST, URL http://vision-squeezer:8080/optimize?max_tokens=1600 (the container name when both run on one Docker network, localhost otherwise).
- Send Body on, Body Content Type n8n Binary File, Input Data Field Name
data.
- Options → Response → Response Format File, so the next node gets the optimized image as binary. Turn on Include Response Headers and Status to read the
X-Tokens-* values.
These settings follow n8n's documentation and have not been tested in n8n itself yet.
The Math: How Vision Models Bill You in 2026
If you send raw images to an LLM, you are leaking tokens. Modern vision models do not care about your file size (MB/KB); they only care about pixel dimensions, but each provider calculates costs completely differently. vision-squeezer simulates these algorithms to find the mathematical minimum size that drops your token usage without losing visual context.
1. OpenAI GPT-6 / GPT-5.6 (32px Patches)
Current OpenAI vision models count 32×32 patches, fit high-detail images within a 2048px edge and 2500-patch budget, then apply a 1.2 multiplier.
- The Fix:
--model gpt6 removes padding, fits the patch budget, and avoids partially used edge patches. A 1024×1024 input is 1024 patches / 1229 tokens.
2. Claude 4.7+ (28px Patches)
Claude counts ceil(Width/28) × ceil(Height/28) visual tokens. Claude 4.7+ high-resolution vision uses a 2576px edge and 4784-token budget; claude-standard covers the earlier 1568px / 1568-token tier.
- The Fix: Strip padding, fit the selected tier, and align dimensions to the 28px grid.
3. Gemini 3 (Large Tiles)
Gemini uses a massive 768×768 tile system (if the image is > 384px). Each tile is a flat 258 tokens.
- The Fix: An 800×600 image triggers a 2×1 tile grid (516 tokens).
vision-squeezer snaps it down slightly to fit exactly inside a 768×768 box, dropping the cost to 258 tokens (50% savings).
4. Llama 3.2 / 3.3 Vision (560px Tiles)
Meta's Mllama vision tiles images on a 560×560 grid, capped at 4 tiles (~1601 tokens each).
- The Fix: A 2400×1670 screenshot trimmed to 2400×1200 drops from a 2×2 to a 2×1 canvas: 6,404 → 3,202 tokens (−50%). (Llama 4 uses a different vision encoder and is not modeled.)
5. Qwen2-VL / 2.5-VL / 3-VL (28px Patch Grid)
Alibaba's Qwen-VL uses a 28px effective grid (14px patch × 2×2 merge); tokens = (W/28)·(H/28) bounded to [4, 16384].
- The Fix: The patch is small, so area is the lever — a 1024×1024 image with its border stripped to 896×896 drops 1,369 → 1,024 tokens (−25%).
6. DeepSeek Flash / DeepSeek-VL2
DeepSeek Flash now accepts images through its OpenAI-compatible API and documents an upper bound of 384 image tokens per image. Use --model deepseek for the API profile; use --model deepseek-local for the exact DeepSeek-VL2 open-weight tile math.
7. Kimi K2.5 / K2.6 / K3
Kimi supports native image and video input through Moonshot's OpenAI-compatible API. Moonshot does not publish a stable image billing grid, so --model kimi gives an advisory native-resolution estimate while still applying exact crop and file-size optimization.
8. DeepSeek-VL2 (384px Anyres Tiles)
SigLIP-384 + 2× pixel-shuffle gives 196 tokens/tile on a (m·384, n·384) canvas (m·n ≤ 9).
- The Fix: An 800×768 image snapped to 768×768 drops from 3×2 to 2×2 tiles: 1,415 → 1,023 tokens (−28%). (Open weights — the win is local-inference context, not API billing.)
Legacy gpt4o and gpt5 profiles remain available for endpoints that still use 512px high-detail tiles.
Full provider math and sources: visionsqueezer.com/providers
Pipeline
🦀 Why Rust?
VisionSqueezer is a performance-critical middleware. We chose Rust for three uncompromising reasons:
- Invisible Latency: Image processing should never be the bottleneck. Rust ensures that snapping, cropping, and encoding happen in milliseconds, making the optimization layer truly invisible to the developer's workflow.
- Minimal Footprint: As an MCP server running in the background of your IDE, VisionSqueezer is designed to be ultra-lightweight, consuming near-zero CPU and RAM when idle.
- Wasm-Ready: Rust's first-class support for WebAssembly allows us to bring the same high-performance optimization to the browser and the Edge (Cloudflare Workers), enabling client-side squeezing before the image even hits the network.
Benchmark snapshots
Captured with vision-squeezer <image> [flags] --dry-run --json on the sample images in data/. The goal is fewer tokens, not fewer megabytes: providers bill by pixel dimensions, so file size only matters for upload and latency. Without a budget the pipeline snaps to a grid and crops padding, which saves little on large photos because providers already downscale oversized images themselves. A token budget (--max-tokens, default 1600 in the MCP server) is what makes the saving real.
Case Study 1: Standard image (istanbul.jpg)
2400×1670, 0.5 MB.
Case Study 2: 12-megapixel image (istanbul2.jpg)
4096×3072, 2.2 MB.
Reading the numbers
- Budget off, tokens barely move. Claude 4.7+ already caps images at 4,784 tokens, so a 4,661-token original can come out at 4,698. The squeezed file is smaller, the bill is not.
--max-tokens 1600 cuts Claude tokens by ~66% and GPT-6 by ~50% on both photos while keeping composition, colour and large text. Fine detail (distant windows, small signs) is what goes first.
- The budget is measured with the target model, Claude when none is set.
--model gemini with the same 1600 lands on Gemini's 768px tile grid (1,032 tokens), and the file-size column follows.
- Pick the budget for your content. 1600 and 1000 kept body text legible in a retina code screenshot; 600 did not. Pass
--max-tokens 0 (or omit it on the CLI) to disable the cap.
- Colour is never dropped.
auto mode behaves like standard; black-and-white output only happens with an explicit --mode ocr.
Current model sanity checks
MCP Tool: optimize_image
Response: an MCP image block with the optimized image, then a text block with a small report. The image is never base64 inside the text: a model reads that as text tokens, which would cost more than the image it replaces.
output_path is set when the input was an image_path.
Where it saves tokens
The optimization only helps if the smaller image is what reaches the model. What that means in practice:
The baseline matters. Claude Code already downsizes large images before it sends them: in our test a 2400×1670 file reached the model as 1999×1392. Against that, the 1600-token budget saves about 56% on istanbul.jpg, not the 66% measured against the original file.
Token counts in this README are estimates from each provider's published rules. For Claude we checked them against Anthropic's count_tokens endpoint (claude-sonnet-5-5, image tokens only):
The real saving is 3,603 → 1,587 (−56%) against what Claude Code sends, and 4,759 → 1,587 (−67%) against the original. GPT and Gemini estimates have not been checked against their APIs.
"MCP tool only" means the agent has to call optimize_image itself with an image_path; tell it to in AGENTS.md. The hooks for Cursor, Gemini CLI, and OpenCode keep their copy in a self-ignoring .vision-squeezer/ folder inside the project, because those clients restrict reads to the workspace.
Save screenshots into the project (for example screenshots/) and reference them by path to get the saving. The hook only rewrites files inside the project: it answers with an allow decision, so it must not open files a plain Read would have asked about.
Config Reference
Supported Models
Platform support
Prebuilt MCP binaries cover Linux x86_64/ARM64, macOS Apple Silicon/Intel, and Windows x86_64/ARM64. Python wheels cover Linux x86_64/ARM64, macOS Apple Silicon/Intel, and Windows x86_64. Unsupported Python architectures can install from source with pip install --no-binary vision-squeezer vision-squeezer.
Advanced Features
Persistence & Analytics
VisionSqueezer tracks every optimization locally in ~/.vision-squeezer/stats.db.
Shell Hook & Claude Code Skills
Add to .zshrc / .bashrc:
This installs two things at once:
squeeze alias — optimize and capture the output path in one step:
- Claude Code skills — written to
~/.claude/skills/ automatically on first run
Available Skills
Example output:
Marketplace install (alternative to setup-hook):
Add to ~/.claude/settings.json:
Then run /plugins add vision-stats@vision-squeezer, /plugins add vision-doctor@vision-squeezer, or /plugins add vision-upgrade@vision-squeezer in Claude Code.
Sandbox Mode: "Think in Code"
Execute atomic operations locally before the image ever reaches an LLM. The agent decides how to process the image; you pay zero tokens for the intermediate steps.
CLI:
MCP tool — sandbox_execute:
Supported ops: crop, grayscale, binarize, resize, contrast, brightness.
Crawler Integration
Optimize images on the fly in any Playwright/Puppeteer scraping pipeline — zero API token waste on raw screenshots.
Contributing
PRs welcome. See CONTRIBUTING.md for setup and guidelines.
Please follow our Code of Conduct.
License
Elastic License 2.0 (ELv2) — See LICENSE for details.