thedistillery
v0.1.1
Published
The Distillery — token optimization proxy for Claude Code
Maintainers
Readme
The Distillery
A token optimization proxy for Claude Code. Intercepts Anthropic API requests via ANTHROPIC_BASE_URL, removes redundant context, and reduces your Claude Code bill.
Install
npm install -g thedistilleryQuick Start
# Log in (one-time)
thedistillery auth login
# Start the proxy — automatically configures Claude Code routing
thedistillery start
# Use Claude Code normally — The Distillery runs in the background
# Check your savings
thedistillery statsUsing a tool other than Claude Code (Cline, Goose, Aider, Zed, Codex CLI)? Run
export ANTHROPIC_BASE_URL=http://127.0.0.1:3080or use your tool's config mechanism. See Supported clients for per-tool instructions.
How It Works
The Distillery sits between Claude Code and the Anthropic API. It intercepts every request and removes redundant context before forwarding:
- Deduplication — removes identical tool outputs seen earlier in the session
- Compression — trims oversized tool results to head+tail with a
~N tokens omittedmarker - History trim — prunes old turns when context is too large
All processing is local. No code or prompts reach The Distillery's servers — only token counts and cost deltas sync for billing.
Supported clients
The Distillery works with any AI coding tool that can be pointed at a custom Anthropic base URL, plus OpenAI-API-compatible tools through either the OpenAI adapter at /v1/chat/completions or the OpenAI passthrough at /openai/v1.
| Client | Configuration mechanism | OpenAI adapter required |
|---|---|---|
| Claude Code | auto-configured by thedistillery start (injected into ~/.claude/settings.json) | No |
| Cline | cline.anthropicBaseUrl in VSCode settings.json | No |
| Goose | ANTHROPIC_HOST=http://localhost:3080 | No |
| Zed | language_models.anthropic.api_url in settings.json | No |
| Aider | --openai-api-base http://localhost:3080/v1 + --model openai/claude-sonnet-4-5 | Yes |
| Codex CLI | API-key auth + OPENAI_BASE_URL=http://localhost:3080/openai/v1 | Yes |
Full step-by-step guides for each client live on the marketing site at thedistillery.dev/clients. Clients marked "OpenAI adapter required" route requests through The Distillery's OpenAI-compatible endpoints. Codex CLI must be logged in with codex login --with-api-key; ChatGPT login uses a websocket backend and bypasses OPENAI_BASE_URL.
Using AWS Bedrock (Bedrock-Mantle OpenAI-compatible)? See Bedrock setup for the manual OPENAI_BASE_URL and .distilleryrc.json configuration.
Configuration
Preset
Set a project-level optimization preset by creating .distilleryrc.json in your project directory (or any parent):
{ "preset": "balanced" }Presets: conservative (dedup only), balanced (dedup + compression at 8,000 chars), aggressive (dedup + compression at 2,000 chars).
Disable compression per project
{ "preset": "balanced", "compression": false }Environment variables
| Variable | Description |
|----------|-------------|
| DISTILLERY_PORT | Port the proxy listens on (default: 3080) |
| DISTILLERY_BYPASS | Set to 1 to disable optimization (pass-through mode) |
CLI Commands
thedistillery start # Start the proxy (default port 3080)
thedistillery start --port 4000 # Use a different port
thedistillery stats # Show cumulative token and cost savings
thedistillery config show # Show active config resolution chain
thedistillery export # Export session log as JSON or CSV
thedistillery billing invoices # Show invoice historyData
Session data is stored in ~/.distillery/data.db (SQLite, WAL mode).
Links
- Website: thedistillery.dev
- App: app.thedistillery.dev
- API: api.thedistillery.dev
- Agent setup guides (OpenClaw, Hermes, Cline, Roo Code, Continue.dev, OpenCode, Goose, Aider): thedistillery.dev/for-agents
Uninstall
For a longer explanation of why each step is needed, see thedistillery.dev/docs/uninstalling.
Important: If you added
export ANTHROPIC_BASE_URL=http://127.0.0.1:3080to a shell profile (.zshrc,.bashrc,$PROFILE, or similar), you must remove that line before finishing. After uninstall the proxy port is dead — Claude Code will fail on every request until the variable is gone. The env-var cleanup step below covers this in detail.
1. Save your savings history (optional)
thedistillery export --format json --output ~/distillery-history.json2. Stop the proxy
thedistillery stop3. Log out (clears your API token from disk)
thedistillery auth logout4. Remove Claude Code hook entries
Open ~/.claude/settings.json and delete any entry under hooks.Stop[] or hooks.PreToolUse[] whose hooks[].command path contains any of these substrings: thedistillery, tokenslayer, cliptoken. If an array becomes empty after deletion, leave it as [] or remove the key entirely — both are valid.
5. Uninstall the package
# npm
npm uninstall -g thedistillery
# pnpm
pnpm remove -g thedistillery
# Yarn classic
yarn global remove thedistillery6. Delete the data directory
macOS / Linux:
rm -rf ~/.distilleryWindows PowerShell:
Remove-Item -Recurse -Force $HOME\.distillery7. Scrub your shell profile
Open the profile files you use and remove any lines that set the following variables:
ANTHROPIC_BASE_URL, DISTILLERY_PORT, DISTILLERY_BYPASS, and (for legacy users) TOKENSLAYER_PORT, TOKENSLAYER_BYPASS, CLIPTOKEN_PORT, CLIPTOKEN_BYPASS.
Profile files to check:
- bash/zsh:
~/.bashrc,~/.bash_profile,~/.zshrc,~/.profile - fish:
~/.config/fish/config.fish - Windows PowerShell:
$PROFILE(usuallyDocuments\PowerShell\Microsoft.PowerShell_profile.ps1)
After editing, restart your shell so the changes take effect.
8. Remove per-project config files (optional)
macOS / Linux:
find ~ -name '.distilleryrc.json' -o -name '.tokenslayerrc.json' 2>/dev/nullWindows PowerShell:
Get-ChildItem -Path $HOME -Recurse -Force -Include .distilleryrc.json,.tokenslayerrc.json -ErrorAction SilentlyContinueDelete any files the search returns.
Verify the uninstall is complete
macOS / Linux:
which thedistillery # should print nothing
ls ~/.distillery # should report: No such file or directory
echo $ANTHROPIC_BASE_URL # should be emptyWindows PowerShell:
where thedistillery # should print nothing
Test-Path $HOME\.distillery # should return False
$env:ANTHROPIC_BASE_URL # should be emptySelf-Hosting
The Distillery is designed for local, loopback-only use. The proxy binds to
127.0.0.1 (localhost) by default and must remain on loopback.
Warning: Do not bind to 0.0.0.0. Binding to all interfaces exposes the
proxy to your local network. Because the proxy forwards requests using your
Anthropic API key, any host on the network could then make authenticated API
calls at your expense.
Supported deployment:
ANTHROPIC_BASE_URL=http://127.0.0.1:3080— single developer machine- Port override via
DISTILLERY_PORT— stays on loopback regardless of port
For the full threat model covering the BYOK architecture, see the SECURITY.md.
License
This project is licensed under the Elastic License 2.0.
