Documentation
¶
Overview ¶
Package proxyserver implements the HTTP proxy that sits between Claude Code (pointed here via ANTHROPIC_BASE_URL) and the real Anthropic API. It tokenizes real values out of every outbound request body and detokenizes them back into every inbound response body, so real PII never reaches Anthropic's servers while Claude Code's own tool execution, permission dialogs, and UI stay completely native. This proxy only ever works at the network layer.
Index ¶
Constants ¶
const ( // DefaultMaxBodyBytes bounds how large a single request or // non-streaming response body this proxy will buffer in memory. This // is the OOM guard: without it, a large tool_result (e.g. reading a // big log file) combined with enough concurrent requests could grow // memory usage without bound. Streaming responses are bounded // per-content-block instead (see the SSE handler), since a stream's // total size isn't meaningfully capped by this constant. DefaultMaxBodyBytes int64 = 64 << 20 // 64 MiB // DefaultMaxConcurrent bounds how many requests may be actively // buffering a body at once, the other half of the OOM guard, since // the byte cap alone doesn't bound (concurrent requests × cap). // Streaming (SSE) responses release their slot as soon as streaming // begins (see ServeHTTP) rather than holding it for the connection's // full lifetime, because holding it would cap concurrent agentic // turns (including parallel subagents sharing one proxy) far below // what memory alone would justify. Only the genuinely bounded-but- // unbounded-in-aggregate phases (reading+tokenizing a request body, // and buffering+detokenizing a non-streaming response body) hold // this slot for their duration. // // What a released slot costs is bounded per stream, not zero. A text // block holds back only what SafeFlushPoint/textFlushBoundary are // still resolving, a small constant; a tool_use block genuinely // accumulates its whole input until content_block_stop, and is capped // at MaxBodyBytes for exactly that reason (see handleBlockDelta's // input_json_delta case). So per-connection streaming memory is // bounded by that cap rather than by this counter. DefaultMaxConcurrent = 16 )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
Upstream *url.URL
Engine *redact.Engine
MaxBodyBytes int64 // 0 => DefaultMaxBodyBytes
MaxConcurrent int // 0 => DefaultMaxConcurrent
Logger *slog.Logger
// DebugLogger, if set, receives the "full" tier's request/response
// body logging; see package debuglog. Nil (the default) disables
// this entirely at effectively zero per-request cost.
DebugLogger *debuglog.Logger
}
Config configures a new Server. Upstream and Engine are required; everything else has a sane default.