Skip to content

Latest commit

 

History

History
163 lines (127 loc) · 13.8 KB

proxy-modes.md

File metadata and controls

163 lines (127 loc) · 13.8 KB

Proxy modes

Two independent things, both about how the traffic physically travels: how claude reaches TeamClaude, and how TeamClaude reaches Anthropic.

MITM proxy mode (default)

The plain reverse-proxy only intercepts what ANTHROPIC_BASE_URL covers. Some Claude Code features (e.g. the Claude Design MCP) use a hardcoded https://api.anthropic.com URL that ignores that variable, so they bypass the proxy. MITM proxy mode captures those too, which is why it's the default for teamclaude run (and the shell alias):

teamclaude run -- <claude args...>

To opt out and route via ANTHROPIC_BASE_URL only, pass --no-mitm:

teamclaude run --no-mitm -- <claude args...>

MITM mode launches claude pointed at TeamClaude as an HTTPS forward proxy (HTTPS_PROXY) and trusts a locally-generated CA (NODE_EXTRA_CA_CERTS). For an intercepted host, TeamClaude terminates the tunnel with a real HTTP/2 server (HTTP/1.1 clients are handled too) presenting its local leaf, then forwards each request with a buffering, retrying client — the same path the base URL mode uses. On each request it:

  • injects the active account's real credential, dropping any client x-api-key: OAuth accounts get authorization: Bearer …, API-key accounts get x-api-key;
  • rewrites the account_uuid inside metadata.user_id to the active account's UUID (so the body agrees with the injected token);
  • routes by the request's model (a Fable-exhausted account is skipped for Fable but still serves other models);
  • reads anthropic-ratelimit-* from responses for quota; and
  • resends the request on a different account if one returns a quota 429, so a "you've reached your limit" is never surfaced while another account has headroom.

Because the request is buffered, the retry is transparent to claude. Client token refreshes (/v1/oauth/token), trusted-device enrollment (/api/auth/trusted_devices and its subpaths), Remote Control (/v1/code/*, and the bridge's /v1/environments/*, /v1/sessions/*, /v2/session_ingress/* and /v2/ccr-sessions/*, which claude remote-control sends through HTTPS_PROXY since Claude Code 2.1.287), claude.ai attachment transfers (/api/oauth/files/*, /api/oauth/file_upload) and the claude.ai connector list (/v1/mcp_servers) are passed through with the client's own credential, since they are bound to the paired identity and fail under a rotated token. Any host other than the upstream is blind-tunnelled. The server accepts both base-URL and proxy clients at once, so instances launched with and without --no-mitm can share one server.

Client bootstrap (/api/claude_cli/*), policy (/api/claude_code/policy_limits), feature evaluation (/api/eval/*, /api/eval-authed/*, /api/claude_code_grove and /api/claude_code_penguin_mode), WebFetch domain checks (/api/web/domain_info), and the MCP registry (/mcp-registry/v0/servers) also use the client's own credential and the configured Anthropic upstream. They bypass account selection, even with an account pin, so an inference-only gateway cannot take over these calls through its priority or a model route. Without a client credential they remain unauthenticated; the proxy does not borrow one from the pool. Their answer describes the credential that sends them, so with proxy.controlPlane set to "pool" they go through account selection instead, as model requests do (see configuration).

A pool with Codex accounts also intercepts chatgpt.com, once the proxy's certificate names it (see the trust model). Inside that tunnel only /backend-api/codex/* is pooled; every other request (workspace discovery, plugins, settings) is passed through to chatgpt.com with the client's own login, and the Codex Responses WebSocket is refused so the CLI falls back to pooled HTTPS — see Codex accounts. chatgpt.com is where ChatGPT Desktop talks to as well. On a machine running that app, set proxy.terminalOnly to true to tunnel that host untouched: the terminal Codex CLI keeps reaching the pool through its explicit /backend-api/codex base URL, and the desktop app keeps its own login.

Trusted-device enrollment always uses the client login, including with proxy.controlPlane: "pool" or an account pin. Enrolling under a pooled account makes Remote Control reject the device when it connects under the client login. If an older proxy enrolled a device under the wrong account, restart the updated proxy and run /login in the affected Claude Code session before retrying /remote-control.

Trust model

  • The CA is generated locally, stored in the config dir, and trusted only by the claude process you launch via teamclaude run (through NODE_EXTRA_CA_CERTS) — it is never added to your system trust store. The leaf private key is 0600; the CA private key is never written to disk.
  • TeamClaude still verifies the real Anthropic certificate on the upstream leg.
  • Plain-HTTP forwarding consumes x-api-key values matching the shared proxy key or a configured client key instead of sending them to the destination. Unrelated application API keys remain intact, including on key-exempt loopback connections and when no proxy key is configured.
  • The chain is renewed when the leaf no longer names every intercepted host (the first Codex account adds chatgpt.com) or either certificate has under 30 days left. Since the CA key is not kept, a renewal always brings a new CA. So while the proxy runs, teamclaude env and teamclaude run keep the stored chain, which is the one the proxy presents, and print a warning that a renewal is due. Restart the proxy to renew it: a starting server renews a stored chain that falls short before it opens its port. Until then, a host that an account added since the start needs (chatgpt.com for the first Codex account) is intercepted only if the certificate the proxy presents already names it. Otherwise it is tunnelled untouched, so its client runs on its own login and nothing is pooled or booked, and a CONNECT whose pin names an account of that host's provider, or an API-key account with an upstream of its own, is refused with 503; the proxy logs both. A session pin is not on the CONNECT, so it does not stop that tunnel, and applies to that host only after the restart. Clients launched before a renewal still trust the old CA and need a restart of their own.

Verify the proxy and CA without any credentials — the proxy always answers a built-in test host:

# (with the server running and certs generated, e.g. after one `teamclaude run`)
curl --proxy http://localhost:3456 --cacert ~/.config/teamclaude-ca.pem https://www.example.org/
# → {"teamclaude":"mitm-proxy-ok","host":"www.example.org",...}

Upstream proxy

For a host that has no direct route to the internet — the corporate case, where every outbound connection must go through an HTTP proxy. Without it TeamClaude fails with connect ETIMEDOUT on the first upstream request, even though Claude Code itself works (#155).

{ "upstreamProxy": "http://user:pass@proxy.corp.example:3128" }

A bare "proxy.corp.example:3128" works too. Set it live from the TUI settings screen (Network → Upstream proxy) — it applies to the next request, without a restart.

  • Covers all Anthropic-bound traffic: request forwarding, OAuth login, token refresh, profile and usage lookups, and (since per-account routing landed) teamclaude api, which used to go direct. A proxy that covered only some of them would leave you able to refresh an account but not add one, or the reverse.
  • HTTPS_PROXY / ALL_PROXY are picked up automatically when the config sets nothing, so a machine already configured for other tools needs no extra setup. When that happens the server says so on startup, and the TUI marks the row with where the value came from — a proxy nobody typed into the config should never be silently in force.
  • NO_PROXY (or noProxy) exempts hosts by suffix; "upstreamProxy": false ignores the environment entirely.
  • A proxy that is this server is refused. teamclaude env exports HTTPS_PROXY pointing at TeamClaude, so a server or CLI started from that shell would inherit itself as its egress proxy — every upstream call would re-enter the proxy and be answered for whichever account it selected, silently (a usage probe would then store that one account's quota under all of them). A value whose address is our own listener is dropped, whether it came from the environment or the config, and the startup line and the TUI row say so.
  • TLS stays end-to-end. The tunnel is a plain CONNECT; the proxy sees ciphertext only, and certificate verification is unchanged. A proxy that intercepts TLS needs its CA in NODE_EXTRA_CA_CERTS.
  • SOCKS URLs are refused here (http CONNECT only), as is https:// to the proxy itself: TeamClaude does not speak TLS to the proxy, and accepting the scheme would send the CONNECT (credentials included) in plaintext to port 443. Write http://host:port — the tunnel through it is end-to-end TLS regardless. (SOCKS is supported one level down, per account: see per-account routing below.)

This is a property of the network, not a routing policy: when set, it is simply how this machine reaches Anthropic. That is what separates it from sx.org below, which is a specific egress provider chosen per request. If both are configured, a request routed via sx.org uses sx.org; everything else uses the upstream proxy. Neither is related to proxy.port, which is the local port Claude Code connects to.

Per-account routing

The fleet settings above move every account together. accounts[].routing does the opposite: it pins one account to its own proxy and leaves the rest untouched.

teamclaude login --name "waffles@waffle.com" --routing "socks5h://alice:s3cret@proxy.example.com:1080"
teamclaude routing waffles@waffle.com socks5h://alice:s3cret@proxy.example.com:1080
teamclaude routing waffles@waffle.com none   # back to the fleet path
{ "name": "waffles@waffle.com", "type": "oauth", "routing": "socks5h://alice:s3cret@proxy.example.com:1080" }
  • All of that account's traffic tunnels through it: request forwarding, OAuth login and token refresh, profile, usage and quota probes. A proxy that covered only some of those would strand the account mid-rotation.
  • Only that account. Every other account keeps the fleet path, and the routed account ignores both the fleet upstream proxy and sx.org (chaining would be two hops for one problem).
  • Schemes: http (CONNECT), socks5, socks5h, socks4, socks4a, with optional user:pass@ auth (SOCKS4 takes a username only). The h/a suffixes follow curl's convention and resolve hostnames at the proxy; the bare forms resolve locally. A bare host:port is http.
  • TLS stays end-to-end exactly as through the fleet proxy: the account's proxy relays ciphertext only, and certificate verification is unchanged.
  • Changes apply live: the CLI command and disk edits both flow through the same reload as every other per-account field. The URL shows password-masked in accounts, status, the TUI and the dashboard.
  • A new URL is tested first: a tunnel to the account's upstream and a TLS handshake, with no request sent. A proxy that does not answer is refused and nothing is saved (--no-check skips the test).
  • A proxy that goes down later takes only its own account out. The request fails over to the next account and the routed one sits out for 30 seconds before its proxy is tried again. See When the proxy is down.

Typical uses: one account that only answers from a specific region, an account served through a jump host the others cannot use, or one seat whose traffic must exit a particular network. See accounts.md for the CLI reference.

sx.org proxy mode

Off by default. Some transient 429s key on the proxy's outbound IP, not the account, so rotating accounts doesn't help. To work around them, TeamClaude can route upstream requests through a residential proxy from sx.org, giving a different egress IP.

No sx.org account yet? Sign up through TeamClaude's referral link, https://sx.org/c/ufVrLW — it costs you nothing extra, and the referral supports TeamClaude development.

Open the TUI, press g for the settings screen, and put your sx.org API key in the sx.org API key row (stored in config.sx.apiKey). TeamClaude reuses an existing active proxy port on your sx.org account, or auto-creates a residential US one, and dials the upstream through it via HTTP CONNECT on both the reverse-proxy and MITM paths.

The sx.org mode row cycles with ←/→:

Mode Behavior
always Tunnel every upstream request through sx.org.
on 429 only Connect directly; on a 429 (which is IP-based), immediately retry that request through sx.org's fresh egress IP, no wait. On the MITM path, a recent 429 routes new tunnels through sx.org for a short window.
off Never use sx.org, but keep the API key so you can re-enable it instantly.

TLS is established end-to-end with api.anthropic.com over the tunnel, so the sx.org proxy only ever relays ciphertext and the real Anthropic certificate is still verified. Mode and key changes apply live (no restart). A Clear sx.org key row appears once a key is set, to forget it entirely.

Cost: in always mode all Claude traffic flows through the residential proxy, which sx.org meters by bandwidth — expect real per-GB cost. on 429 only uses the proxy just when you're actually being throttled, so it's the cheaper way to ride out rate limits.