Wringing Excess Tokens Claude
API proxy for Claude Code — teach your Claude to optimize its own context in a meta-transparent way.

Your Claude is running dry. Make it wet.
wet claude --dangerously-skip-permissions # Claude takes it from here.
Auto compact is brutal. It hits at the worst moments - mid-swarm, mid-experiment - and when it fires, it's all or nothing. Context gets shredded indiscriminately. Important computation goes rogue. Sessions derail. I've had a Mac Mini spiral to 60GB swap from the fallout.
So I audited thousands of tool calls across my Claude Code sessions. The culprit was obvious: 82% of context bloat is stale tool results - old git status outputs, spent pytest runs, massive grep dumps you already acted on, 30k-token agent returns you'll never look at again. They sit there, rotting, pushing you toward the autocompact cliff.
The problem: there's no hook to intercept tool results before they enter context. I checked Claude Code, Codex - nothing. Opened a feature request. I forked Codex and wired in my own compression hooks. I tried JSONL manipulation. Too dirty.
Then the insight: reverse proxy. A Go shim that sits between Claude Code and api.anthropic.com, intercepts every POST /v1/messages, and compresses stale tool results in-place before they reach the API. No client patches. No prompt wrappers. Clean.
But deterministic compression alone wasn't enough - it handles Bash outputs well, but agent returns and file reads need semantic understanding. So I flipped the script: instead of just compressing mechanically, put Claude in the driver's seat. Let it profile its own context, decide what's stale, and surgically rewrite its own tool results with a Sonnet subagent. Meta-compression - Claude optimizing Claude's context.
The result: instead of autocompact's sledgehammer, you get a scalpel. Claude thinks clearer with a lean context. Token savings compound across long sessions. Same work, half the noise.
Put Claude in the driver's seat for context optimization.
One Go binary, one Claude Code skill. Toolbox and a Manual.
wet is a toolbox for agents. It gives Claude (or any agent sitting on top of Claude Code) surgical access to its own context - the ability to see exactly how much each tool result block consumes, profile the entire session's token distribution, and replace any block with either deterministic compression or a meta-aware subagent rewrite.
The Go proxy is the toolbox. It sits between Claude Code and the API, intercepts every POST /v1/messages, and exposes a full control plane:
# Launch — works with --resume, --dangerously-skip-permissions, or both
wet claude [args...] # start Claude Code through the proxy
wet claude --resume <session-id> # resume a previous session through wet
wet claude --dangerously-skip-permissions # autonomous mode through wet
wet serve --host 0.0.0.0 --mode auto # standalone proxy for Docker / IDE extension
# Observe
wet ps [--all] # list all active wet sessions
wet status [--json] # context profile: fill%, token counts, compressible items
wet inspect [--json] [--full] # every tool result block with token count, age, staleness
# Surgical compression (port auto-discovered — run from inside the wet session or its subagents)
wet compress --ids id1,id2,... # replace specific blocks — deterministic or with replacement text
wet compress --text-file plan.json # batch replacement with LLM-rewritten content
wet compress --dry-run --ids ... # preview what would change without applying
# Runtime control
wet pause # bypass all compression (accounting still runs)
wet resume # re-enable compression
wet rules list # show active compression rules
wet rules set KEY VALUE # tune thresholds at runtime
# Session forensics
wet session profile --jsonl <PATH> # context composition analysis from session trace
wet session salt # session self-identification token
wet data status # offline storage stats
wet data inspect [--all] # browse persisted compressed items
wet data diff <turn> # what changed at a specific turn
wet compress and control commands auto-discover the proxy port via WET_PORT env var — no manual port wiring needed. These commands are designed to be called by Claude from inside a wet session (or by its subagents that inherit the environment).
Each tool result becomes a first-class object. You can see it, measure it, and replace it. Deterministic compression is calibrated on SWE-bench (91.2% ratio across 13,881 outputs, <5ms overhead) and understands 10 tool families natively: git, pytest, cargo, npm, pip, docker, make, ls/find, and more.
Per-item token counts are estimated from content length (chars/4 heuristic — no external tokenizer dependency). Session-level fill% and savings come from Anthropic's actual token counts in the API response — ground truth, not estimates.
Auto mode and rules. wet can run fully automatic — mode = "auto" in the config makes the proxy compress stale Bash outputs deterministically on every request without Claude lifting a finger. The rules engine controls staleness thresholds per tool family (wet rules list, wet rules set), minimum savings gates, and bypass conditions. You tune the rules, wet enforces them. See Configuration for the full config file.
The skill is the manual. It teaches Claude the meta game — how to use the toolbox on itself:
1. Profile — run wet status, see context fill, token distribution, what's compressible vs sacred.
2. Propose — inspect individual blocks, classify each one (mechanical Bash compression vs LLM-guided rewrite for agent returns and file reads), build a compression plan with expected savings.
3. Process — execute the plan. Bash outputs get deterministic Tier 1 compression. Agent returns and search results get rewritten by a Sonnet subagent that preserves semantic content while cutting 80-90% of tokens.
Here's what Claude sees when it profiles a real session (this README was written in it):
┌──────────────────────────────────────────────────────────────────────┐
│ Tool Items Tokens Stale Status │
├──────────────────────────────────────────────────────────────────────┤
│ Read 13 33.7k 13/13 ██████████████████ 80% │
│ Agent 6 3.5k 6/6 ████░░░░░░░░░░░░░░ 8% │
│ Bash 12 3.1k 9/12 ███░░░░░░░░░░░░░░░ 7% │
│ Grep 2 1.2k 2/2 █░░░░░░░░░░░░░░░░░ 3% │
│ TaskOutput 1 0.7k 1/1 █░░░░░░░░░░░░░░░░░ 2% │
│ Edit 6 0.2k 6/6 ░░░░░░░░░░░░░░░░░░ <1% │
├──────────────────────────────────────────────────────────────────────┤
│ Total 40 42.4k 37/40 context fill: 11.5% │
│ │
│ Sacred: SOUL, IDENTITY, USER, MEMORY — never compressed │
│ Fresh: 3 items (current turn) — protected │
│ Stale: 37 items — compressible │
└──────────────────────────────────────────────────────────────────────┘
Claude sees what's sacred, what's fresh, what's fair game. It proposes a compression plan, you approve, it executes. Or in auto mode - it just handles it.
The skill is fully customizable — ask Claude to profile your sessions and adjust the compression strategy to your workflow. My case: the main session is a coordinator managing swarms of agents and agents inside agents, so agent returns are the primary culprit for context pollution. Your case might be different — heavy grep usage, large file reads, deep git histories. Tune the skill to match. The heuristics that drive what gets compressed and what stays sacred live in skill/references/heuristics.md — edit it to match your setup.
The fastest path: point your Claude at this repo and tell it to install wet. It will read the skill, build the binary, wire the statusline, and configure itself. That's the whole point - wet is built for agents to set up and operate.
Manual path:
# Homebrew (recommended)
brew tap buildoak/tap && brew install wet
# Build from source (requires Go 1.22+)
git clone https://github.com/buildoak/wet.git
cd wet && go build -o wet .
sudo mv wet /usr/local/bin/ # or anywhere on your PATH
# Install the skill — this is what teaches Claude the meta game
wet install-skill
# Wire the statusline into Claude Code
wet install-statusline
# Launch Claude through wet
wet claude --dangerously-skip-permissions
Docker / IDE Extension path:
# Build the standalone proxy image
docker build -t wet-proxy .
# Run it on localhost:8100 (auto mode shown here; passthrough is the default)
docker run --rm \
-p 8100:8100 \
-e WET_MODE=auto \
-v wet-data:/root/.wet \
wet-proxy
Then point Claude Code's shared settings at the published port:
{
"env": {
"ANTHROPIC_BASE_URL": "http://127.0.0.1:8100"
}
}
This mode is best when you want a drop-in proxy beside Claude Code IDE Extension without launching Claude through wet claude. If you also want to drive wet status, wet inspect, or wet compress from the host, run the CLI locally and pass --port 8100.
Use a specific image tag like wet-proxy rather than plain wet. wet:latest is a generic local tag and may already belong to an unrelated image on your machine.
Security note: The proxy exposes unauthenticated /_wet/* control endpoints. When binding to 0.0.0.0, ensure the port is not publicly reachable — place it behind a firewall, restrict it to a private network, or add network-level access control (e.g., a reverse proxy with auth).
The skill is not optional for Tier 2 / agent-driven workflows. Without it, wet still works as a proxy and can run deterministic auto compression, but Claude will not know how to profile its own context, propose compression plans, and execute semantic rewrites. The proxy is the toolbox - the skill is the manual that makes Claude a self-optimizing agent.
The statusline is customizable — ask Claude to tweak it to your preferences. After install, it shows context health in real time:
[Opus 4.6 (1M)] (90k/1000k) | wet: 9% (90k/1.0M)
As your session grows, wet tracks what's been compressed:
[Opus 4.6 (1M)] (200k/1000k) | wet: 20% (200k/1.0M) | 19/105 compressed (21.6k->3.0k)
Deep into a session:
[Opus 4.6 (1M)] (350k/1000k) | wet: 35% (350k/1.0M) | 47/230 compressed (89.2k->8.1k)
Note: the statusline is a best-effort display — it may show stale data during startup or across session resumes. For precise context metrics, use wet status --json or wet inspect --json — those read live proxy state and are always accurate.
Monitor sessions:
wet ps # all active sessions at a glance
wet status # context profile for current session
wet inspect --live # live dashboard with auto-refresh
wet works with zero config out of the box. For tuning, see Configuration.
``` ┌─────────────────────────────────────────────────────────────────────────┐ │ Claude Code │ │ (unmodified client) │ └───────────────────────────────┬─────────────────────────────────────────┘ │ ANTHROPIC_BASE_URL=localhost:PORT │ ▼ ┌─────────────────────────────────────────────────────────────────────────┐ │ wet proxy │ │ │ │ ┌────────────────┐ ┌────────────────┐ ┌──────────────────────┐ │ │ │ Interceptor │───▶│ Classifier │───▶│ Compressor │ │ │ │ │ │ │ │ │ │ │ │ Catches every │ │ Each tool │ │ Tier 1: Deterministic│ │ │ │ POST /messages │ │ result scored │ │ Tier 2: LLM rewrite │ │ │ │ Parses tool │ │ for staleness │ │ │ │ │ │ result blocks │ │ by tool family │ │ Replaces in-place │ │ │ │ │ │ and turn age │ │ before API call │ │ │ └────────────────┘ └────────────────┘ └──────────────────────┘ │ │ │ │ ┌──────────────────────────────────────────────────────────────────┐ │ │ │ Control Plane (Unix socket) │ │ │ │ status · inspect · compress · pause · resume · rules │ │ │ └──────────────────────────────────────────────────────────────────┘ │ │ │ │ ┌──────────────────────────────────────────────────────────────────┐ │ │ │ Persistence Layer
—