config

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2026 License: GPL-3.0 Imports: 5 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 config holds the on-disk configuration for the proxy along with the defaults that make it usable with no configuration at all.

Index

Constants

View Source
const DefaultInterceptHost = "api.anthropic.com"

DefaultInterceptHost is the hostname the proxy terminates TLS for.

View Source
const DefaultUpstream = "https://api.anthropic.com"

DefaultUpstream is the Anthropic API endpoint every non-intercepted request is forwarded to verbatim.

Variables

This section is empty.

Functions

func DefaultPath

func DefaultPath() string

DefaultPath reports the default config file location.

func ExpandUser

func ExpandUser(path string) string

ExpandUser resolves a leading "~" to the user's home directory.

Tilde expansion is a shell feature, not a filesystem one: a shell rewrites "~/x" before the program is ever started. A path that arrives from a configuration file passes through no shell, so without this it would be used verbatim as a relative path and create a directory literally named "~" next to the working directory.

Only the current user's home is expanded. "~other/x" is left alone, since resolving another user's home would need the password database and is not something this proxy should be guessing at.

func Root

func Root() string

Root reports the configuration directory, honouring XDG_CONFIG_HOME.

Types

type Codex

type Codex struct {
	// BaseURL is the ChatGPT backend that serves the Responses API.
	BaseURL string `json:"base_url"`
	// UserAgent and Originator identify the request as coming from the Codex
	// CLI, which is the client the subscription endpoint expects.
	UserAgent  string `json:"user_agent"`
	Originator string `json:"originator"`
	// Models restricts the exposed catalog to these ids when non-empty.
	Models []string `json:"models,omitempty"`
	// EffortVariants adds one model entry per supported reasoning level
	// (for example gpt-5.5-high) to the advertised model list.
	//
	// It is off by default: Claude Code selects effort itself, with /effort
	// and --effort, and sends it with the request, so per-effort ids only
	// multiply the picker rows. Turn it on for a client that has no effort
	// control of its own.
	EffortVariants bool `json:"effort_variants"`
	// ModelPrefix, when set, is accepted (and advertised) in front of every
	// Codex model id, e.g. "codex/gpt-5.5".
	ModelPrefix string `json:"model_prefix,omitempty"`
	// CallbackPort is the loopback port the OAuth redirect URI points at. The
	// value is fixed by the registered OAuth client and should not change.
	CallbackPort int `json:"callback_port"`
	// AuthFile, when set, is the only credential file consulted, in either
	// this proxy's layout or the Codex CLI's.
	AuthFile string `json:"auth_file,omitempty"`
	// UseCLIAuth reads (and keeps in sync) the Codex CLI's
	// ~/.codex/auth.json when this proxy has no credentials of its own.
	UseCLIAuth bool `json:"use_codex_cli_auth"`
}

Codex groups the settings of the OpenAI Codex (ChatGPT subscription) backend.

type Config

type Config struct {
	// ListenProxy serves the HTTP CONNECT proxy Claude Code is pointed at.
	// Empty disables it.
	ListenProxy string `json:"listen_proxy"`
	// ListenTLS serves the same router directly over TLS using a certificate
	// for the intercepted host, for hosts-file style redirection. Empty
	// disables it.
	ListenTLS string `json:"listen_tls"`
	// ListenHTTP serves the router over plain HTTP, which is handy for local
	// testing and for ANTHROPIC_BASE_URL setups. Empty disables it.
	ListenHTTP string `json:"listen_http"`

	// Upstream is where pass-through traffic goes.
	Upstream string `json:"upstream"`
	// InterceptHosts are the CONNECT targets whose TLS is terminated locally.
	// Everything else is tunnelled untouched.
	InterceptHosts []string `json:"intercept_hosts"`

	// ProxyUsername and ProxyPassword, when both set, require Basic
	// credentials on the CONNECT proxy.
	ProxyUsername string `json:"proxy_username,omitempty"`
	ProxyPassword string `json:"proxy_password,omitempty"`

	// CADir stores the local CA, AuthDir the provider credentials.
	CADir   string `json:"ca_dir"`
	AuthDir string `json:"auth_dir"`

	// LogLevel is one of debug, info, warn, error.
	LogLevel string `json:"log_level"`

	// ExperimentalModifyBootstrapModels makes the proxy add its models to
	// Claude Code's startup response, so they appear in the /model picker
	// with no client-side configuration.
	//
	// It is off by default and enabled only by the
	// --experimental-modify-bootstrap-models flag: it rewrites an
	// undocumented Claude Code response rather than a published Anthropic
	// API one, and the shape can change with any Claude Code release.
	ExperimentalModifyBootstrapModels bool `json:"-"`

	Codex Codex `json:"codex"`
	DNS   DNS   `json:"dns"`
	// contains filtered or unexported fields
}

Config is the complete proxy configuration.

The three listen fields are opt-in once a configuration file exists: an empty value means that listener is not started.

func Default

func Default() *Config

Default returns a fully populated configuration.

func Load

func Load(path string) (*Config, error)

Load reads path, filling unset fields from Default. A missing file is not an error: the defaults are returned so the proxy runs out of the box.

Listeners are the one exception to filling in defaults. Once a configuration file exists, only the listeners it names are started: a key that is absent disables its listener rather than inheriting the default address. Without a file, all three defaults apply.

func (*Config) Intercepts

func (c *Config) Intercepts(host string) bool

Intercepts reports whether TLS for host should be terminated locally.

func (*Config) ListenAddrs

func (c *Config) ListenAddrs() []string

ListenAddrs reports every address the proxy listens on. The resolver refuses to dial these, so a hosts-file redirect cannot make the proxy call itself.

func (*Config) ListenerSummary

func (c *Config) ListenerSummary() [][2]string

ListenerSummary describes each listener for reporting.

func (*Config) Path

func (c *Config) Path() string

Path reports where the config was loaded from.

func (*Config) PrimaryInterceptHost

func (c *Config) PrimaryInterceptHost() string

PrimaryInterceptHost reports the host used when a client omits SNI.

func (*Config) Save

func (c *Config) Save() error

Save writes the configuration back to disk, creating parent directories.

type DNS

type DNS struct {
	// Enabled turns the internal resolver on. With it off, outbound
	// connections go through the operating system resolver, which honours
	// /etc/hosts and can therefore loop.
	Enabled bool `json:"enabled"`
	// Servers are the nameservers to query, as host or host:port. When empty
	// they come from /etc/resolv.conf, skipping loopback stub resolvers
	// (systemd-resolved, dnsmasq) because those consult /etc/hosts as well.
	Servers []string `json:"servers,omitempty"`
	// TimeoutMS bounds a single DNS query.
	TimeoutMS int `json:"timeout_ms"`
	// Static pins hostnames to IP addresses, answered without any query.
	Static map[string][]string `json:"static,omitempty"`
	// MinTTLSeconds and MaxTTLSeconds clamp how long an answer is cached.
	MinTTLSeconds int `json:"min_ttl_seconds"`
	MaxTTLSeconds int `json:"max_ttl_seconds"`
}

DNS configures the proxy's own resolver, which is used for every outbound connection.

The proxy resolves upstream names itself so it is not subject to the redirection it installs: in the hosts-file deployment api.anthropic.com points at this proxy, and the system resolver would send it back to itself.

Jump to

Keyboard shortcuts

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