Your Terminal Isn't Using Your Browser's Network: A Proxy Env Var Primer for curl, Node and Claude Code

2026-11-30来源 dev.toEnglish
Your Terminal Isn't Using Your Browser's Network: A Proxy Env Var Primer for curl, Node and Claude Code

You open a website in your browser and it works. You run a command in the terminal and it times out, or a CLI tool reports "unable to connect", or a login that worked a minute ago in the browser keeps failing in the app.

Nothing is "broken". Your browser and your terminal are simply not using the same network path, and most of us never check.

This post is a short, practical primer: how to see what each of them is actually doing in about a minute, which tools read proxy environment variables (I tested the two I wasn't sure about), and a few Claude Code specifics from its docs.

TL;DR

  • A browser, a terminal tool and a system-wide tunnel can each leave your machine through a different route.
  • curl https://claude.ai/cdn-cgi/trace shows the address a site sees for that one connection. Run it in the terminal and compare with the same URL in your browser.
  • curl reads HTTPS_PROXY. Node's fetch does not, unless you opt in. Claude Code does read it, but does not support SOCKS.
  • Only use proxies you are authorized to use, and follow the service's terms and supported regions.

One laptop, three different routes

Think of three separate doors out of your machine:

  1. The browser. It usually follows the operating system's proxy settings, a PAC file, or a browser extension. An extension-based proxy affects the browser only.
  2. Terminal tools. Most of them ignore the OS proxy settings. They follow environment variables (HTTPS_PROXY, NO_PROXY…) or their own config keys.
  3. A system-wide tunnel (a VPN or a TUN-style interface). It sits below both and captures everything, including your terminal.

One laptop, three possible routes

If you use a system-wide tunnel, the browser and the terminal usually agree. If you rely on a browser extension or a system proxy setting, they can easily disagree. That is where most "works in the browser, fails in the terminal" reports come from.

The 60-second check

Cloudflare serves a tiny diagnostic page on every site it fronts: /cdn-cgi/trace. It returns plain text, including the address that Cloudflare saw for that connection.

macOS / Linux:

curl -s https://claude.ai/cdn-cgi/trace 

Windows PowerShell (use curl.exe; plain curl can be an alias for Invoke-WebRequest):

curl.exe -s https://claude.ai/cdn-cgi/trace 

You get something like this (values below are illustrative, trimmed):

h=claude.ai ip=203.0.113.25 colo=NRT http=http/2 loc=JP tls=TLSv1.3 

The lines worth reading: ip= is the address the site saw, loc= is the country code, colo= is the Cloudflare data center that answered.

Now open the same URL in your browser and compare. Same ip= and loc=? Then both use the same route. Different? Then you have two routes, and any service that sees both (for example, you sign in with the browser and then call an API from the terminal) sees two different origins for one account.

Compare browser and terminal

Two caveats: the trace only tells you what one connection looked like at that moment, and it says nothing about whether a service will accept it. It is a diagnostic, not a verdict.

Setting a proxy for the terminal

If your environment requires a proxy (a company network, a locked-down server, a test setup), terminal tools mostly look at these variables:

# macOS / Linux (bash, zsh) export HTTPS_PROXY="http://127.0.0.1:8080" export HTTP_PROXY="http://127.0.0.1:8080" export NO_PROXY="localhost,127.0.0.1" 
# Windows PowerShell $env:HTTPS_PROXY = "http://127.0.0.1:8080" $env:NO_PROXY = "localhost,127.0.0.1" 
:: Windows cmd set HTTPS_PROXY=http://127.0.0.1:8080 

A few details that cause most of the confusion:

  • Write a full URL, including http://. A bare host:port works in some tools and fails in others.
  • Variables are read at startup. Changing them in a running shell does nothing for a process that is already running.
  • Lowercase and uppercase both exist (https_proxy and HTTPS_PROXY). Tools differ in which one wins, so set one style consistently.
  • It only applies to that shell. A tool launched from an IDE, a desktop shortcut or a service manager does not inherit what you exported in another terminal window.
  • NO_PROXY lists hosts that should skip the proxy. Forgetting it is how people end up proxying localhost.

Who actually reads these variables?

I assumed everything did. So I checked the two I wasn't sure about. The test: start a tiny local proxy that only counts CONNECT requests, run each client against https://claude.ai/cdn-cgi/trace with HTTPS_PROXY pointing at it, and see how many connections the proxy receives.

// minimal CONNECT counter (full script: see the end of the post) proxy.on('connect', (req, client, head) => { connects.push(req.url); // just count const [host, port] = req.url.split(':'); const up = net.connect(Number(port) || 443, host, () => { client.write('HTTP/1.1 200 Connection Established\r\n\r\n'); up.write(head); up.pipe(client); client.pipe(up); }); }); 

Results on Node 22.23.1 and curl 8.17.0 (Windows):

Client Setup Connections seen by the proxy
curl HTTPS_PROXY set 1
curl nothing set 0
Node fetch HTTPS_PROXY set 0 (ignored)
Node fetch HTTPS_PROXY + NODE_USE_ENV_PROXY=1 1

Which clients honor HTTPS_PROXY?

So a script that works through your proxy with curl can silently bypass it when the same request is made with Node's built-in fetch. The Node docs say NODE_USE_ENV_PROXY=1 was added in v24.0.0 and --use-env-proxy in v24.5.0; it also worked on my 22.x build, with an "experimental" warning. Both are marked as under active development, so check your version.

The Node docs add a sentence I think is worth repeating: this is meant for reaching external networks through authorized proxies, for example when a firewall requires one. It is not for hiding traffic or evading network policy.

For other tools (git, pip, npm and so on), the usual pattern is "reads the standard variables or has its own config key", but the details differ by tool and version, so check each tool's documentation rather than assuming.

Claude Code specifics

Per Claude Code's network configuration docs:

  • It respects the standard variables HTTPS_PROXY, HTTP_PROXY and NO_PROXY. Lowercase variants work too, and it uses the first one set in this order: https_proxy, HTTPS_PROXY, http_proxy, HTTP_PROXY.
  • It does not support SOCKS proxies. If your proxy offers both HTTP and SOCKS5 ports, use the HTTP one.
  • Variables exported in your shell are read once at startup.
  • To check what it loaded, run /status in an interactive session and look at the Proxy row, or start it with claude --debug.
  • If you run background agents, they are hosted by a shared supervisor process that inherits whichever shell started it first. Put the variables in the env block of ~/.claude/settings.json instead of exporting them in one shell.
  • If your proxy requires credentials, they can go in the URL, but avoid hardcoding passwords in scripts.

Claude Code and proxies

Also relevant: if your company proxy inspects TLS, you may need NODE_EXTRA_CA_CERTS pointing at the corporate root certificate.

A short debugging checklist

  1. Run the trace in the browser and in the terminal. Same ip=/loc=?
  2. env | grep -i proxy (or Get-ChildItem Env: | Where-Object Name -match proxy in PowerShell). What is actually set?
  3. Is the proxy URL complete, with scheme and port?
  4. Does the tool support the proxy type? (SOCKS5 vs HTTP.)
  5. Was the tool started after you set the variables, from the same shell?
  6. Is it a Node fetch script on an older Node? Try NODE_USE_ENV_PROXY=1.
  7. Still odd? Compare time zone, language and DNS resolver location with the address you expect. A mismatch there is a separate kind of inconsistency.

Debugging checklist

Be careful with what a proxy is for

Use proxies and networks you are authorized to use. A proxy does not change which countries a service supports, and each service sets its own terms. If a region is not supported, the fix is to read the terms, not to hunt for another route.

Disclosure: I work on AnboVPN, which offers HTTP/SOCKS5 proxies among other things. The tip above is generic, but it is also how our own proxy accounts are used: the same credentials work on an HTTP port and a SOCKS5 port, so tools that only speak HTTP (like Claude Code) use the HTTP one. If you want to compare what your browser and terminal each look like from the outside, we have a free check page: anbolink.com/tools/claude-ip-check.

The full experiment script (Node 22+; it starts a local counter, so it needs no external proxy):

// Which clients honor HTTPS_PROXY? Start a local CONNECT counter, run each client against it, count connections. // Usage: node proxy-experiment.mjs (Node 22+; no external proxy needed; the counter only logs "host:port", never content) import http from 'node:http'; import net from 'node:net'; import { spawn } from 'node:child_process'; // Must be async: the proxy runs inside this process, so a blocking spawnSync would freeze it too. const run = (cmd, args, env) => new Promise((resolve) => { const p = spawn(cmd, args, { env, stdio: ['ignore', 'ignore', 'pipe'] }); let err = ''; p.stderr.on('data', (d) => (err += d)); const t = setTimeout(() => p.kill(), 30000); p.on('close', (code) => { clearTimeout(t); resolve({ status: code, stderr: err }); }); }); let connects = []; const proxy = http.createServer((_, res) => res.writeHead(405).end()); proxy.on('connect', (req, client, head) => { connects.push(req.url); // just count const [host, port] = req.url.split(':'); const up = net.connect(Number(port) || 443, host, () => { client.write('HTTP/1.1 200 Connection Established\r\n\r\n'); up.write(head); up.pipe(client); client.pipe(up); }); up.on('error', () => client.destroy()); client.on('error', () => up.destroy()); }); await new Promise((r) => proxy.listen(0, '127.0.0.1', r)); const url = `http://127.0.0.1:${proxy.address().port}`; const TARGET = 'https://claude.ai/cdn-cgi/trace'; const isWin = process.platform === 'win32'; const curl = isWin ? 'curl.exe' : 'curl'; const sink = isWin ? 'NUL' : '/dev/null'; const nodeFetch = `fetch('${TARGET}').then(r=>r.text()).then(()=>process.exit(0)).catch(e=>{console.error(e.cause?.code||e.message);process.exit(1)})`; const cases = [ ['curl, HTTPS_PROXY set', curl, ['-s', '-m', '20', '-o', sink, TARGET], { HTTPS_PROXY: url }], ['curl, nothing set', curl, ['-s', '-m', '20', '-o', sink, TARGET], {}], ['Node fetch, HTTPS_PROXY set', process.execPath, ['-e', nodeFetch], { HTTPS_PROXY: url }], ['Node fetch, HTTPS_PROXY + NODE_USE_ENV_PROXY=1', process.execPath, ['-e', nodeFetch], { HTTPS_PROXY: url, NODE_USE_ENV_PROXY: '1' }], ]; console.log(`node ${process.version}`); for (const [name, cmd, args, env] of cases) { connects = []; const clean = { HTTP_PROXY: '', http_proxy: '', HTTPS_PROXY: '', https_proxy: '', ALL_PROXY: '', all_proxy: '' }; const r = await run(cmd, args, { ...process.env, ...clean, ...env }); console.log(`${name.padEnd(48)} connections seen by proxy: ${connects.length} exit: ${r.status}`); } proxy.close(); 

原文:https://www.a8q9.cn/en/article/your-terminal-isn-t-using-your-browser-s-network-a-proxy-env-var-primer-for-curl-a062a9.html

相关文章