Claude Code can talk to Anthropic with your own account, to a gateway you point it at, or to a cloud provider's hosted Claude models. Each path has its own variables and its own failure modes. This guide covers the install first, then the three paths. Everything comes from Anthropic's docs as they read on 2026-12-03, plus the few checks I ran myself, which I mark as mine.

Read this first: regions

Anthropic's Supported Regions Policy says its products, Claude Code included, are available only in the countries and regions it lists, and that any country or region not listed is unsupported. When I read it, mainland China and Hong Kong were not on the list, and Taiwan, Japan, Singapore and the United States were.

This guide does not cover how to get around that. The gateway and cloud routes below are documented in Anthropic's docs, but whether a route is appropriate for your location, your employer and the provider's own terms is your call.

Pick a path

Claude Code can connect through three paths: your own official account, an LLM gateway with a gateway address and credential, or a cloud provider such as Amazon Bedrock, Google Cloud or Microsoft Foundry

  • A. Official account. Pro, Max, Ultra, Team, Enterprise or a Console account. The free claude.ai plan does not include Claude Code.
  • B. LLM gateway. You set a base URL and a credential, and Claude Code sends its requests there.
  • C. Cloud provider. Amazon Bedrock, Google Cloud's Agent Platform or Microsoft Foundry. Each has its own page in the docs.

Install first, then configure the path.

Install

Native installer (recommended in the docs)

# macOS, Linux, WSL curl -fsSL https://claude.ai/install.sh | bash 
# Windows PowerShell (the prompt starts with PS) irm https://claude.ai/install.ps1 | iex 
:: Windows CMD (the prompt has no PS) curl -fsSL https://claude.ai/install.cmd -o install.cmd && install.cmd && del install.cmd 

Package managers also work: brew install --cask claude-code on macOS, winget install Anthropic.ClaudeCode on Windows.

What the docs say about it:

  • The installer shows no progress while it downloads, so it can look stuck.
  • When it finishes, open a new terminal and run claude --version. A version number means it worked. claude doctor prints a more detailed read-only check.
  • If the command fails with syntax error near unexpected token '<' or a 403, you probably downloaded a web page instead of the script. The docs link a troubleshooting page for that and for alternative install methods.
  • Homebrew and WinGet installs do not auto-update. Native installs do.

npm

The npm package needs Node.js 22 or later:

npm install -g @anthropic-ai/claude-code@latest 

The docs say not to use sudo for this and not to upgrade with npm update -g, because it may not move you to the newest release. Re-run the install command instead.

If registry.npmjs.org is slow or unreachable on your network, you can point npm at a mirror with --registry. I checked that registry.npmmirror.com lists @anthropic-ai/claude-code (latest tag 2.1.336 when I looked) and the platform package for Windows x64. It is a third-party mirror and can lag, so trust claude --version over what the mirror claims.

Network access

Claude Code needs to reach a list of hosts, which the network configuration page documents. The main ones are api.anthropic.com, claude.ai, platform.claude.com, downloads.claude.ai (native installer and updates) and registry.npmjs.org (npm installs). When a gateway or cloud provider carries the model traffic, requests go there instead of api.anthropic.com, but some optional traffic still goes to Anthropic. More on that in the gateway section.

Path A: your own official account

Run claude and follow the browser prompts. The account is yours alone, and Anthropic's terms do not allow sharing it.

If your network requires a proxy

Claude Code reads the standard variables:

export HTTPS_PROXY=http://proxy.example.com:8080 export NO_PROXY="localhost,127.0.0.1" 

Three details from the docs:

  • SOCKS proxies are not supported. Only HTTP and HTTPS proxies.
  • Write the proxy as a full URL with http://, not just host:port.
  • To make background agents see the proxy too, put the variables in the env block of ~/.claude/settings.json instead of exporting them in one terminal.

Claude Code docs, network configuration page, captured 2026-12-03: "Claude Code does not support SOCKS proxies."

To check that the settings loaded, start claude --debug, or run /status in a session and look at the Proxy row.

Path B: an LLM gateway

A gateway is a proxy between Claude Code and a model provider. You tell Claude Code where it is and how to authenticate.

Request path: Claude Code sends requests to the gateway using a base URL and credential, the gateway forwards them to the model provider, and /status shows which base URL is in use

Pick the credential variable

Claude Code docs, Connect to a gateway page, captured 2026-12-03: the table that maps ANTHROPIC_AUTH_TOKEN, ANTHROPIC_API_KEY and apiKeyHelper to the kind of credential

Variable Use it when the gateway says
ANTHROPIC_AUTH_TOKEN "bearer token" or "Authorization header"
ANTHROPIC_API_KEY "API key" or "x-api-key"
apiKeyHelper The credential rotates or comes from a vault

If you are not told which kind it is, start with ANTHROPIC_AUTH_TOKEN. A 401 later means you picked the wrong one, so switch. Each variable puts the credential in a different HTTP header, which is why a wrong pick fails with 401.

Set the base URL and credential

export ANTHROPIC_BASE_URL=https://llm-gateway.example.com export ANTHROPIC_AUTH_TOKEN=sk-gateway-key 
$env:ANTHROPIC_BASE_URL = "https://llm-gateway.example.com" $env:ANTHROPIC_AUTH_TOKEN = "sk-gateway-key" 

Shell exports last for one terminal session, and an editor launched from the dock or Start menu will not see them. To persist the values, use the env block of ~/.claude/settings.json:

{ "env": { "ANTHROPIC_BASE_URL": "https://llm-gateway.example.com", "ANTHROPIC_AUTH_TOKEN": "sk-gateway-key" } } 

The docs warn against putting the credential in a project's .claude/settings.json, because that file is committed and shared with everyone who clones the repository. If a shell export and a settings-file env block set the same variable, the settings file wins.

Test with curl before opening Claude Code

This is the docs' own check. It sends a one-token request straight to the gateway:

curl -sS -w '\n%{http_code}\n' -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": "."}]}' 

How to read the result, per the docs:

  • JSON that starts with {"id":"msg_ means the URL and credential work.
  • An error about an unknown model still proves the URL and credential work. The gateway authenticated you before it rejected the model name.
  • 401 means the credential was rejected, so try the other variable.

If your gateway expects the x-api-key header, replace the Authorization line with -H "x-api-key: $ANTHROPIC_API_KEY".

Then start claude, send a message, and run /status. The Status tab should show an Anthropic base URL row with your gateway address, and an Auth token or API key row naming the variable you set. If the base URL row is missing, the variable did not reach the session.

Who provides the gateway

  1. Your organization. This is the case the docs are written for.
  2. A model vendor's Anthropic-compatible endpoint. For example, DeepSeek's Anthropic API page lists https://api.deepseek.com/anthropic as the base URL and says authentication can use either x-api-key or an Authorization: Bearer header. It maps model names that start with claude-opus to deepseek-v4-pro, and names that start with claude-haiku or claude-sonnet to deepseek-flash. It also lists ignored fields (cache_control, top_k, budget_tokens, among others) and restrictions, such as tool_choice set to any or tool returning 400 in thinking mode, and deepseek-v4-pro replacing images with "[Unsupported Image]". I read that page, not DeepSeek's separate Claude Code page, so check that one for the exact Claude Code variables.
  3. A third-party relay service. It forwards your requests to some upstream.
  4. A gateway you run yourself.

Limits you should know about

  • Anthropic's docs say it "doesn't endorse, maintain, or audit third-party gateway products, and doesn't support routing Claude Code to non-Claude models through any gateway". A vendor's compatibility layer can work and still be incomplete.
  • While a gateway credential variable or apiKeyHelper is active, requests carry that credential instead of your claude.ai login, and the subscription's usage limits do not apply to them. The traffic is billed to whoever owns the credential the gateway forwards.
  • If both a gateway credential and a saved claude.ai login exist, startup shows a warning that names the two sources. Run /logout if you want only the gateway credential.
  • Your code and prompts pass through whatever gateway you use. With a third-party relay, ask what it retains and logs, whether model names and billing are transparent, and how reliable it is. Do not paste real keys into scripts from people you do not know.

Common gateway errors

Gateway errors and what to check first: 401 means the credential is in the wrong variable, 400 unknown fields means the upstream rejects new request fields, missing models means names are not in the built-in list, certificate errors mean the runtime does not trust your CA

These come from the docs' troubleshooting table:

What you see Cause Fix
401, invalid token Credential in the wrong variable, or revoked Switch variable, or regenerate the key at the gateway
400 with Extra inputs are not permitted or other unknown fields Upstream rejects fields Claude Code sends Set CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1
Gateway models missing from /model Names are not in Claude Code's built-in list Set CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY=1
403 with an HTML body A firewall in front of the gateway blocked the request body Ask the gateway admin to exempt /v1/messages from body inspection
curl works, Claude Code reports a certificate error The runtime does not trust the CA that curl uses Set NODE_EXTRA_CA_CERTS to the CA bundle path

Gateway-only networks

If your network only allows egress to the gateway, Claude Code's background traffic (version checks, telemetry and similar requests to Anthropic and to GitHub) will fail and may show up as blocked connections. The docs say to set CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC=1 alongside the gateway variables. One side effect is that it disables auto-updates, so plan another way to update.

Path C: a cloud provider

If your company already has a cloud account, Claude Code can use Amazon Bedrock, Google Cloud's Agent Platform or Microsoft Foundry. Billing, regions and permissions then follow that provider's rules. Each has its own page in the docs with its own variables, so I do not reproduce them here. Start from Anthropic's docs for the provider you use.

Quick troubleshooting

Symptom Check first
claude not found after install Did you open a new terminal? Is the install directory on PATH? Run claude doctor
Install script returns a 403 or downloads a web page Network or region restriction on the download. Try the npm route, or the docs' install troubleshooting page
It starts, but requests time out Proxy variable format (full http:// URL, no SOCKS). Run claude --debug and read the log
A gateway is set but Claude Code still asks you to log in /status: is there an Anthropic base URL row and a credential row? Where did you set the variables?
Gateway returns 401 or 400 See the error table above

What I did and did not check

I did not run every command on a clean machine for this article. The commands, variable names and troubleshooting entries are from Anthropic's docs as they read on 2026-12-03. The npm mirror lookup and the reading of DeepSeek's compatibility page are mine. Claude Code changes quickly, so if this is more than a few weeks old, trust the docs over me.

One small thing to try: after you install, run claude --version, start a session, and open /status. It tells you which base URL, credential and proxy Claude Code is actually using, which is the first thing to know before debugging anything else.

This article was created with the help of AI.