Claude Code is Anthropic's official terminal coding agent. It talks to the Anthropic Messages API and lets you point it at a custom endpoint via ANTHROPIC_BASE_URL. Compresh integrates as a drop-in proxy: route Claude Code through api.compre.sh and Compresh reconstructs (compresses) the conversation in-flight before forwarding to Anthropic — no plugin, no code change.
When ANTHROPIC_BASE_URL is set, Claude Code silently bypasses valid Pro/Max subscription credentials and bills the API route instead (claude-code #23022) — you'd pay per token on top of your subscription. The proxy below is for API-key users only. On a subscription, register compresh-mcp instead — compression as explicit tools, while your subscription keeps driving the model:
pipx install compresh-mcp
claude mcp add compresh --scope user -- "$(which compresh-mcp)" Proxy (base URL) TESTED
Claude Code keeps using the Anthropic Messages format. Compresh sits in front on the same /v1/messages endpoint, replaces the older turns with a query-aware slice, and passes the request through to Anthropic. Your provider key stays stored (encrypted) at Compresh; Claude Code authenticates with your Compresh key.
Requirements
- Claude Code installed (
npm i -g @anthropic-ai/claude-codeor the VS Code extension). - A Compresh API key (
sk-comp_…) — sign up at compre.sh/signup. - Your Anthropic key registered at Compresh (BYOK) so the proxy can forward — add it at compre.sh/portal → Settings → Bring your own key. (Or run on Compresh credits.)
Set it up
1. Register your Anthropic provider key once at the portal (Settings → Bring your own key → Anthropic). You'll see it listed, masked, when it's saved.
2. Point Claude Code at Compresh. In the shell you launch claude from:
export ANTHROPIC_BASE_URL="https://api.compre.sh"
export ANTHROPIC_AUTH_TOKEN="sk-comp_..." # your COMPRESH key — not your Anthropic key
unset ANTHROPIC_API_KEY # AUTH_TOKEN is the gateway path; avoids the custom-key prompt Or persist it per project in .claude/settings.json:
{
"env": {
"ANTHROPIC_BASE_URL": "https://api.compre.sh",
"ANTHROPIC_AUTH_TOKEN": "sk-comp_..."
}
} 3. Start Claude Code in your project. If it was already running, quit and relaunch so it picks up the env:
cd your-project && claude Verify
Have a real, multi-turn session — compression engages once the conversation grows past the protected recent turns (short chats pass through unchanged). Then confirm savings at compre.sh/portal → Usage: you'll see requests and tokens saved climb. Want it inline? Toggle Show optimized prompt in Settings and each response carries a compresh field with the before/after token counts.
On long sessions the older history is replaced by a query-aware slice — typically ~99% fewer input tokens per turn on a strong model. Short conversations save ~0 (they're within the protection zone), and your system prompt is never compressed. The savings compound as the conversation grows.
Why not a hook or MCP?
Claude Code's hooks (UserPromptSubmit and friends) can append context to a turn but cannot rewrite or compress the prior conversation history — and appended context only adds tokens. Its MCP support exposes tools the model may choose to call; it does not participate in building the context window. Neither surface can drive transparent per-turn compression, so the proxy is the integration path for Claude Code.
Pricing
Free to start, no card. You bring your own provider key (you pay Anthropic directly for the model) and Compresh only takes a share of the input tokens it removes — no savings, no fee. New signups get $30 in free credit. See compre.sh/pricing.
Troubleshooting
"Invalid API key" / "Missing API key"
Claude Code must send your Compresh key (sk-comp_…), not your Anthropic key. Set ANTHROPIC_AUTH_TOKEN to the Compresh key and unset ANTHROPIC_API_KEY. "Missing API key" usually means the variable is empty in the current shell — re-export it before launching claude.
402 — payment required
No credit and no provider key on file. Add your Anthropic key at Settings → Bring your own key, or top up credit.
Nothing shows up in the dashboard
Your requests aren't routing through Compresh — ANTHROPIC_BASE_URL isn't active in the shell that started Claude Code. Fully quit Claude Code and relaunch it from the shell where you exported the variables (or set them in .claude/settings.json).
Related
- Anthropic SDK — same Messages API, same proxy path
- OpenClaw — local-first hook (provider key never leaves your machine)
- All integrations matrix