Claude Code Proxy Setup: Corporate Networks, API Gateways, and ANTHROPIC_BASE_URL
Corporate proxy servers, TLS inspection appliances, and API gateways all sit between Claude Code and the Anthropic API. Misconfigure any layer and you get cryptic SSL errors or silently dropped connections. This guide covers every proxy scenario: HTTPS_PROXY for network routing, custom CA certificates for TLS inspection, mutual TLS for client authentication, and ANTHROPIC_BASE_URL for API gateway integration.
What Claude Code Connects To
Claude Code requires outbound HTTPS access to at least six distinct domains on port 443, according to Anthropic's network configuration documentation. Most developers expect a single API endpoint. The gap between that expectation and the actual traffic pattern is where proxy misconfigurations happen.
During normal operation, Claude Code reaches out to these hosts:
- api.anthropic.com for model API requests
- claude.ai for account authentication
- platform.claude.com for console authentication
- downloads.claude.ai for plugins, the native installer, and auto-updates
- raw.githubusercontent.com for the changelog feed and marketplace install counts
- storage.googleapis.com for the installer and auto-updater (versions before 2.1.116)
If you route Claude Code through Amazon Bedrock, Google Vertex, or Microsoft Foundry, model traffic goes to those providers instead of api.anthropic.com. Authentication and update traffic still hits the Anthropic domains.
Corporate networks add layers between Claude Code and those endpoints: forward proxies that inspect URLs, TLS inspection appliances that decrypt and re-encrypt HTTPS, API gateways that route and rate-limit LLM requests, and mTLS enforcement at the network edge. Each layer needs its own configuration. This guide covers them from the network layer up.
You can disable optional outbound traffic with a single variable. Set CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC=1 to suppress telemetry and error reporting. For granular control, use DISABLE_TELEMETRY=1 and DISABLE_ERROR_REPORTING=1 separately.
Helpful references: Fast.io Workspaces, Fast.io Collaboration, and Fast.io AI.
How to Configure Network Proxy Variables
Claude Code respects the standard HTTP proxy environment variables. Set them before launching Claude Code, because it reads proxy configuration once at startup. Changes during a running session have no effect.
Basic proxy setup:
export HTTPS_PROXY=http://proxy.example.com:8080
export HTTP_PROXY=http://proxy.example.com:8080
export NO_PROXY=localhost,127.0.0.1,.internal.corp
For proxies that require basic authentication, embed credentials in the URL:
export HTTPS_PROXY=http://username:password@proxy.example.com:8080
To persist these across sessions without editing shell profiles, add them to ~/.claude/settings.json:
{
"env": {
"HTTPS_PROXY": "http://proxy.example.com:8080",
"NO_PROXY": "localhost,127.0.0.1"
}
}
NO_PROXY accepts both comma-separated and space-separated lists. Set it to * to bypass the proxy entirely, which is useful for testing whether the proxy itself is causing a problem.
NTLM and Kerberos authentication are not natively supported. If your corporate proxy requires either protocol, deploy a local relay proxy that handles the authentication handshake. CNTLM works for NTLM environments. Px handles NTLM, Kerberos, and Windows integrated auth. Point Claude Code at the relay:
### After starting CNTLM or Px on port 3128
export HTTPS_PROXY=http://127.0.0.1:3128
SSE streaming matters here. Claude Code uses server-sent events over long-lived HTTPS connections for response streaming, not WebSockets. Corporate proxies that buffer HTTP responses before forwarding or enforce short idle timeouts will stall or cut off replies mid-stream. Set the outbound idle connection timeout on your proxy to at least 120 seconds.
Handling TLS Inspection and Custom CA Certificates
Most Node.js applications trust only their bundled Mozilla CA certificate bundle. When a TLS inspection proxy (Zscaler, CrowdStrike Falcon, Netskope) decrypts and re-signs HTTPS traffic with a corporate root CA, those applications fail with "unable to verify the first certificate" errors.
Claude Code handles this better than most. The CLAUDE_CODE_CERT_STORE variable defaults to bundled,system, which means Claude Code trusts both its bundled Mozilla CAs and the operating system's trust store. If your IT team installed the inspection proxy's root CA into the OS certificate store, Claude Code trusts it automatically.
When you need explicit control:
### Trust only the OS certificate store
export CLAUDE_CODE_CERT_STORE=system
### Trust only bundled Mozilla CAs (ignores corporate CAs)
export CLAUDE_CODE_CERT_STORE=bundled
### Add a specific corporate CA without modifying the trust store
export NODE_EXTRA_CA_CERTS=/etc/ssl/corporate-ca.pem
NODE_EXTRA_CA_CERTS works alongside CLAUDE_CODE_CERT_STORE. Point it at a PEM file containing your corporate root CA chain, and Claude Code adds those certificates on top of whatever the cert store setting already provides.
One gotcha to watch for: the Claude Code Desktop app honors NODE_EXTRA_CA_CERTS for its own traffic, but may not forward the variable to the CLI subprocess in the Code pane. If the chat panel connects fine but CLI commands fail with certificate errors, set the variable in the terminal profile (.bashrc, .zshrc) so the CLI process inherits it directly.
mTLS Client Certificate Authentication
Zero-trust networks often require mutual TLS, where the client presents a certificate to prove its identity before the proxy or gateway accepts the connection. Claude Code supports mTLS through three environment variables:
export CLAUDE_CODE_CLIENT_CERT=/path/to/client-cert.pem
export CLAUDE_CODE_CLIENT_KEY=/path/to/client-key.pem
If your private key file is encrypted, add the passphrase:
export CLAUDE_CODE_CLIENT_KEY_PASSPHRASE="your-passphrase"
These variables apply to all outbound HTTPS connections from Claude Code. If your gateway requires mTLS but external services do not, you may need to segment traffic by configuring ANTHROPIC_BASE_URL to point at the mTLS-protected gateway while leaving direct internet access unaffected.
Give your agents a workspace that survives proxy changes
Shared storage and an MCP endpoint your agents can reach through whatever proxy chain you just set up. Starts with a 14-day free trial.
How to Route API Traffic Through Gateways
ANTHROPIC_BASE_URL is the primary mechanism for redirecting Claude Code's API requests. When set, Claude Code sends all model requests to the specified URL instead of api.anthropic.com. This is how you route traffic through LLM gateways, API management platforms, or cost-tracking proxies.
export ANTHROPIC_BASE_URL=https://llm-gateway.example.com
export ANTHROPIC_AUTH_TOKEN=sk-gateway-key
The credential variables map to different HTTP headers:
ANTHROPIC_AUTH_TOKENsends the credential as anAuthorization: BearerheaderANTHROPIC_API_KEYsends it as anx-api-keyheader- Setting either one overrides a saved claude.ai subscription login
For credential rotation, configure apiKeyHelper in settings.json:
{
"apiKeyHelper": "~/bin/get-gateway-key.sh"
}
Claude Code runs this script when it needs credentials and caches the result for 5 minutes (configurable with CLAUDE_CODE_API_KEY_HELPER_TTL_MS in milliseconds). On HTTP 401 responses, it re-runs the script immediately.
Gateway requirements for operators. If you run the gateway, there are a few non-obvious requirements. Forward the anthropic-version and anthropic-beta headers unchanged. Treat anthropic-beta as an open list of comma-separated feature flags that changes with every Claude Code release. Do not allowlist specific values. Streaming is mandatory: buffering complete responses before relaying breaks the user experience. Forward error response bodies unmodified, because Claude Code's retry logic matches on the upstream's exact error wording.
Compatibility flags. Some proxies reject Claude Code's pre-release beta headers. Set CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1 to strip them. For gateways that cause duplicate tool execution, set CLAUDE_CODE_DISABLE_NONSTREAMING_FALLBACK=1. To improve prompt-cache hit rates on gateways, set CLAUDE_CODE_ATTRIBUTION_HEADER=0 to omit the attribution block from the system prompt.
LLM gateway platforms like TrueFoundry and LiteLLM add routing, cost tracking, and fallback chains between Claude Code and the model provider. TrueFoundry reports 3-4ms p95 gateway overhead at over 350 requests per second on a single vCPU. LiteLLM supports multi-provider routing through a local proxy process. Both work by setting ANTHROPIC_BASE_URL to the gateway's endpoint and providing the gateway's API key through ANTHROPIC_AUTH_TOKEN.
For VS Code, configure the gateway through extension settings:
{
"claudeCode.environmentVariables": [
{ "name": "ANTHROPIC_BASE_URL", "value": "https://llm-gateway.example.com" },
{ "name": "ANTHROPIC_AUTH_TOKEN", "value": "sk-gateway-key" }
]
}
Settings file precedence (highest to lowest):
.claude/settings.local.json(project, gitignored, best for credentials).claude/settings.json(project, committed, never put credentials here)~/.claude/settings.json(user, all projects)- Managed settings (organization-wide, distributed via MDM)
Environment variables override all settings files.
Fixing Common Proxy Failures
WAF blocking. Claude Code prompts contain XML-style tags and source code that trigger cross-site scripting detection rules in web application firewalls. On AWS WAF, exempt the /v1/messages path from the CrossSiteScripting_Body rule. On nginx with ModSecurity, add a similar path-based exception for the API endpoint.
Trailing slash 404s. Some gateways treat /v1/messages and /v1/messages/ as different routes. If you get 404 responses through your gateway, try adding or removing the trailing slash from ANTHROPIC_BASE_URL.
Certificate errors in CLI but not Chat. The Claude Code Desktop app may not propagate NODE_EXTRA_CA_CERTS to the CLI subprocess. Set the variable in your shell profile (.bashrc, .zshrc) so both the app and CLI processes inherit it.
Stalled streaming responses. Corporate proxies that buffer entire HTTP responses before forwarding break SSE streaming. Increase the idle connection timeout to at least 120 seconds. To confirm the proxy is the culprit, test with a direct connection: NO_PROXY=api.anthropic.com.
MCP tool search disabled. When ANTHROPIC_BASE_URL points to a non-Anthropic host, Claude Code disables MCP tool search by default. Set ENABLE_TOOL_SEARCH=true to re-enable it. This matters for workflows that connect to external MCP servers, such as Fast.io's MCP endpoint for workspace file operations or other tool providers your agents depend on.
SOCKS proxy not supported. Claude Code only supports HTTP and HTTPS proxies. If your network provides only a SOCKS proxy, run a local HTTP-to-SOCKS bridge (Privoxy or a similar tool) and point HTTPS_PROXY at the bridge's local address.
Variables read once at startup. Claude Code reads HTTPS_PROXY, ANTHROPIC_BASE_URL, and all other proxy variables when it launches. Changing them during a running session has no effect. Restart Claude Code after any proxy configuration change.
Verify your gateway connection before troubleshooting Claude Code itself:
curl -X POST "$ANTHROPIC_BASE_URL/v1/messages" \
-H "Authorization: Bearer $ANTHROPIC_AUTH_TOKEN" \
-H "anthropic-version: 2023-06-01" \
-H "content-type: application/json" \
-d '{"model": "claude-sonnet-4-6", "max_tokens": 1, "messages": [{"role": "user", "content": "."}]}'
If this returns a valid response, Claude Code will work through the same gateway. If it fails, the problem is in the gateway or network path, not in Claude Code's configuration.
Frequently Asked Questions
How do I configure Claude Code behind a corporate proxy?
Set HTTPS_PROXY to your proxy URL before launching Claude Code (for example, http://proxy.example.com:8080). For proxies with TLS inspection, ensure the inspection CA is installed in the OS trust store or set NODE_EXTRA_CA_CERTS to point at the CA certificate PEM file. Claude Code reads proxy variables at startup, so restart after changing them. For persistent configuration, add the variables to the env block in ~/.claude/settings.json.
What is ANTHROPIC_BASE_URL in Claude Code?
ANTHROPIC_BASE_URL redirects all Claude Code API requests from the default api.anthropic.com endpoint to a custom URL. Use it to route traffic through LLM gateways, API management platforms, or cost-tracking proxies. Set it alongside ANTHROPIC_AUTH_TOKEN (for Bearer authentication) or ANTHROPIC_API_KEY (for x-api-key authentication) to provide gateway credentials.
Does Claude Code support SOCKS proxies?
No. Claude Code only supports HTTP and HTTPS proxies via the HTTPS_PROXY and HTTP_PROXY environment variables. If your network provides only a SOCKS proxy, run a local HTTP-to-SOCKS bridge such as Privoxy and point HTTPS_PROXY at the bridge's local address (typically http://127.0.0.1:8118).
How do I add custom CA certificates for Claude Code?
Set NODE_EXTRA_CA_CERTS to the file path of a PEM file containing your custom CA certificates. Claude Code adds these to its trust list alongside the default certificates. The CLAUDE_CODE_CERT_STORE variable (defaulting to bundled,system) controls which base certificate stores Claude Code trusts. Set it to system if you want to rely solely on the OS trust store.
Can I route Claude Code through an LLM gateway like TrueFoundry or LiteLLM?
Yes. Set ANTHROPIC_BASE_URL to the gateway's endpoint and ANTHROPIC_AUTH_TOKEN to the gateway's API key. Both TrueFoundry and LiteLLM accept the Anthropic Messages API format. Some gateways reject pre-release headers, so set CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1 if you see unexpected errors.
How do I restrict developers to using our organization's API gateway?
Distribute ANTHROPIC_BASE_URL and gateway credentials through managed settings files via MDM, so developers don't configure anything manually. To block personal API usage entirely, inject the anthropic-allowed-org-ids header through your TLS-inspection proxy for traffic targeting claude.ai and api.anthropic.com.
Related Resources
Give your agents a workspace that survives proxy changes
Shared storage and an MCP endpoint your agents can reach through whatever proxy chain you just set up. Starts with a 14-day free trial.