proxyserver

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 5, 2026 License: GPL-3.0 Imports: 16 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
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.

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server is the reverse proxy. Safe for concurrent use: one Server serves all requests via its ServeHTTP method.

func New

func New(cfg Config) *Server

func (*Server) ServeHTTP

func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL