Claude Code · Certificates and network
SSL certificate hostname mismatch (ERR_TLS_CERT_ALTNAME_INVALID)
Fix ERR_TLS_CERT_ALTNAME_INVALID (SSL hostname mismatch) in Claude Code: captive Wi-Fi, hosts-file overrides, VPN DNS or a gateway certificate.
Message
The exact error
Unable to connect to API: SSL certificate hostname mismatchAlso appears as:
- During /login (OAuth error)
- OAuth error: SSL certificate error (ERR_TLS_CERT_ALTNAME_INVALID). If you are behind a corporate proxy or TLS-intercepting firewall, set NODE_EXTRA_CA_CERTS to your CA bundle path, or ask IT to allowlist *.anthropic.com. Run `claude doctor` for details.
- Related code with the same message
- HOSTNAME_MISMATCH
Meaning
What does an SSL hostname mismatch mean?
A certificate lists the hostnames it’s valid for. This error means the server that answered presented a certificate that doesn’t cover the name Claude Code connected to, such as api.anthropic.com or platform.claude.com. Trusting a different CA won’t fix it: the problem is that the wrong server, or a misconfigured proxy, is responding.
Causes
What causes ERR_TLS_CERT_ALTNAME_INVALID?
- Hotel, airport or café Wi-Fi with a sign-in page that intercepts HTTPS until you log in
- A proxy or firewall that blocks the host and serves its own block page certificate
- An entry in your hosts file or a DNS override pointing Anthropic’s hostnames elsewhere
- A VPN or DNS filter that resolves Anthropic’s hostnames to a different server
ANTHROPIC_BASE_URLset to a gateway whose certificate doesn’t include the hostname you used
Fix
How do I fix the hostname mismatch?
Sign in to the network
On public Wi-Fi, open any website in your browser and complete the sign-in page, then retry.
Read the names on the certificate you’re getting
This prints the certificate’s subject and the hostnames it covers. They should include
api.anthropic.com. If they name a firewall, a Wi-Fi portal or another company, that device is answering in Anthropic’s place.macOS, Linux and WSL (OpenSSL) openssl s_client -connect api.anthropic.com:443 -servername api.anthropic.com </dev/null \ | openssl x509 -noout -subject -ext subjectAltNameCheck where the hostname points
Remove any hosts-file line for an Anthropic or Claude hostname that you didn’t add on purpose.
macOS / Linux grep -i anthropic /etc/hosts nslookup api.anthropic.comWindows PowerShell Select-String -Path C:\Windows\System32\drivers\etc\hosts -Pattern anthropic nslookup api.anthropic.comCheck for a gateway URL
Run
echo $ANTHROPIC_BASE_URL(orecho $env:ANTHROPIC_BASE_URLin PowerShell) and look for it in theenvblock of your settings files. If it points at a gateway, its certificate must include that gateway’s hostname; ask its operator to fix it.Ask IT to let Anthropic’s hosts through
If a corporate proxy is answering, the error message’s own advice applies: ask IT to allowlist
*.anthropic.com(and the other hosts Claude Code needs) rather than block or rewrite them.
Don’t do this
- Don’t set
NODE_TLS_REJECT_UNAUTHORIZED=0. It switches off certificate checking entirely, so any machine on the network could read or change your traffic, including your API key. - Adding the proxy’s CA with
NODE_EXTRA_CA_CERTSwon’t help here: the certificate is for the wrong name, not from an unknown issuer.
FAQ
Questions people ask
How do I see which hostnames a certificate covers?
Run openssl s_client -connect api.anthropic.com:443 -servername api.anthropic.com </dev/null and pipe the output to openssl x509 -noout -subject -ext subjectAltName. The names listed must include the host Claude Code connects to. If they name a firewall, a Wi-Fi portal or another company, that device is answering in Anthropic’s place.
Will adding a CA certificate fix ERR_TLS_CERT_ALTNAME_INVALID?
No. NODE_EXTRA_CA_CERTS and the system store decide which issuers Claude Code trusts, but this error means the certificate names a different host. Find out what is answering instead: a Wi-Fi sign-in page, a hosts-file entry, a VPN’s DNS or a gateway set in ANTHROPIC_BASE_URL. Fix that, and the certificate matches again.
Related
Related errors
Keep exploring