Claude Code can fail from a terminal even when Clash Verge is open and a browser appears to work. The usual cause is a mismatch between the proxy listener Clash Verge exposes and the environment variables inherited by the shell that launches Claude Code. A browser may use the system proxy automatically, while a command-line process may connect directly unless it is explicitly given a proxy address. This guide walks through a practical, reversible setup: identify the listener, export the correct shell variables, test the route independently, and then diagnose failures without changing several settings at once. Service availability, account eligibility, and network requirements vary by region; a working proxy does not guarantee that a service or account is available in every location.

Understand the Terminal Proxy Path

For a terminal request to use Clash Verge, three things must line up: Clash Verge must be running with a reachable local listener, the shell must point proxy-aware programs at that listener, and the selected Clash route must be able to reach the destination. A failure at any one of these stages can look like a Claude Code problem, so start by separating them.

Clash Verge is the desktop interface; the proxy core does the actual listening and routing. Depending on the profile and client version, the core may expose an HTTP proxy, a SOCKS proxy, or a mixed port that accepts both HTTP and SOCKS connections. The port is configurable, so do not assume that a commonly seen number is correct for your installation. Read the active port in Clash Verge’s settings or profile, and confirm that the core is started.

For an initial terminal setup, an HTTP or mixed listener is usually the simplest choice. HTTP proxy environment variables are widely understood by command-line tools, and a mixed listener can also accept HTTP proxy requests. If you choose a SOCKS-only port, use a proxy URL and test tool options that explicitly support SOCKS. A successful browser connection alone does not prove that the terminal is using that same listener: browsers can use system proxy settings that shell programs ignore.

CheckWhat to confirmWhy it matters
Clash Verge coreThe core is running and a profile is activeA configured port is not useful if nothing is listening on it
Listener typeHTTP, SOCKS, or mixedThe proxy URL and test command must match the listener
Listener addressUsually a loopback address for local useThe shell must connect to the same machine and port
Routing modeThe selected proxy group and matching rulesA reachable listener can still route a destination directly or to an unavailable node
Terminal environmentProxy variables exist in the shell launching Claude CodeApplications inherit environment variables from their parent process

Keep a local listener bound to loopback, such as 127.0.0.1, unless you have a specific reason to expose it to other devices. A proxy listener is a network service; binding it to all interfaces can make it reachable from a local network. Do not expose a listener or Clash’s controller interface to a public network as a workaround for a terminal connection issue.

Start with the actual port: Copy the port shown by your running Clash Verge configuration. The examples below use 7890 only as a placeholder. Replace it with your HTTP or mixed listener port before testing.

Set Proxy Variables in Your Shell

Most command-line clients look for conventional environment variables such as HTTP_PROXY and HTTPS_PROXY. Set them in the same shell session from which you launch Claude Code. These variables do not change Clash Verge’s routing rules; they tell compatible programs where to send their outbound HTTP and HTTPS requests.

For a local HTTP or mixed listener on port 7890, use the following commands in a POSIX-compatible shell such as Bash, Zsh, or a typical Linux terminal:

Temporary Proxy Variables for Bash or Zsh
export HTTP_PROXY="http://127.0.0.1:7890"
export HTTPS_PROXY="http://127.0.0.1:7890"
export http_proxy="$HTTP_PROXY"
export https_proxy="$HTTPS_PROXY"

# Optional: use only if your tools support this variable
export ALL_PROXY="http://127.0.0.1:7890"
export all_proxy="$ALL_PROXY"

Using the same value for the uppercase and lowercase forms helps with tools that recognize only one spelling. The scheme in the URL describes the connection from the application to the local proxy. Even for an HTTPS destination, the proxy URL is commonly written as http:// when the local listener is an HTTP proxy: the client asks the proxy to establish a tunnel, then performs TLS with the destination through that tunnel. Do not change it to https:// unless the listener itself is configured to accept TLS from local clients.

If Clash Verge exposes only a SOCKS5 listener, the corresponding URL may look like socks5h://127.0.0.1:PORT. The h variant asks a compatible client to resolve the destination hostname through the proxy. Support differs by application, so validate the SOCKS URL with a test tool before relying on it. When an HTTP or mixed listener is available, using that for a first diagnosis avoids an unnecessary protocol-compatibility variable.

On Windows PowerShell, set variables for the current session like this, replacing the example port as needed:

Temporary Proxy Variables for PowerShell
$env:HTTP_PROXY = "http://127.0.0.1:7890"
$env:HTTPS_PROXY = "http://127.0.0.1:7890"
$env:http_proxy = $env:HTTP_PROXY
$env:https_proxy = $env:HTTPS_PROXY

These session-level settings are a good starting point because they disappear when that terminal window closes. For a persistent setup, add exports to the startup file for the shell you actually use, such as ~/.zshrc or ~/.bashrc, then open a new terminal or reload that file. Avoid adding variables to several startup files at once: that makes it harder to tell which value is active and can leave stale settings behind.

On macOS, a terminal launched from the Dock may not inherit the same environment as a shell started from another application. On Windows, a newly opened terminal inherits variables from its parent process, so a terminal already open when settings changed may keep the old values. In either case, open a fresh terminal and inspect the variables there. If you start Claude Code from an IDE, the IDE must inherit the settings too; setting variables in a separate terminal does not automatically alter an already-running IDE process.

Be careful with persistent settings: Proxy variables affect every compatible program launched from that shell, not just Claude Code. Do not place credentials or a secret proxy URL in a shared startup file, and unset the variables when you need a direct connection.

Test the Listener Before Starting Claude Code

Test in layers. First check whether the local port is listening, then send a simple HTTPS request through it, and finally launch Claude Code from the tested shell. This sequence helps distinguish a local port problem from a remote service problem.

On macOS or Linux, inspect the current values and make a request with curl:

Inspect Variables and Test an HTTPS Route
printf 'HTTP_PROXY=%s\n' "$HTTP_PROXY"
printf 'HTTPS_PROXY=%s\n' "$HTTPS_PROXY"

curl -I --connect-timeout 10 https://example.com

# Explicitly test the listener, independent of environment-variable support
curl -I --proxy http://127.0.0.1:7890 --connect-timeout 10 https://example.com

The first request checks whether curl picks up your environment. The second explicitly names the proxy and is useful when you suspect the shell variables are missing or ignored. A successful response from example.com verifies a basic route, but it does not establish that every destination is reachable or that Claude Code’s account and service requirements are satisfied.

On Windows, run the equivalent checks in PowerShell. Use curl.exe to call the curl executable explicitly, because the command name may behave differently in some PowerShell versions:

Test the Route in PowerShell
Write-Output $env:HTTP_PROXY
Write-Output $env:HTTPS_PROXY

curl.exe -I --connect-timeout 10 https://example.com
curl.exe -I --proxy http://127.0.0.1:7890 --connect-timeout 10 https://example.com

If the explicit request fails immediately with a connection-refused error, verify that Clash Verge’s core is running, that the port is correct, and that the listener is bound to the local address you used. If the request reaches the proxy but times out during the remote connection, check the selected proxy group, node health, DNS behavior, and rules for the destination. A request that returns an HTTP status code confirms that an HTTP response was received; it does not necessarily mean that the response was a success, so read the status and any accompanying error text.

When the basic route works, start Claude Code from that same terminal session. This ensures it inherits the variables you just tested. If you usually launch it through an IDE, first close and reopen the IDE after setting the environment, or configure the IDE’s integrated terminal environment so its child process receives the values.

Diagnose Common Connection Failures

Do not respond to every connection error by changing the proxy port, Clash rules, DNS settings, and shell startup files simultaneously. Change one item, repeat the same test, and note the result. The table below maps common symptoms to the most useful next check.

SymptomLikely causeNext check
Connection refused on localhostWrong port, stopped core, or listener not bound to that addressConfirm the active listener and compare its port with the proxy URL
Browser works but terminal does notThe browser uses system proxy settings; the shell does notSet variables in the launching shell and test with explicit curl --proxy
curl works but Claude Code failsThe process inherited different variables, uses a different runtime path, or encounters a service-specific issueLaunch from the tested shell, inspect the exact error, and check current application requirements
Connection hangs or times outSelected node, rule, DNS resolution, or remote route is failingCheck Clash Verge’s connection view and test another permitted destination or route
Some requests work, others failDifferent domains may match different rules or require different reachable endpointsReview rule matching and logs for the specific failed connection
Requests unexpectedly bypass ClashAn existing NO_PROXY entry matches the destination or a tool ignores proxy variablesInspect NO_PROXY and the tool’s proxy documentation

Check NO_PROXY and no_proxy if requests appear to bypass the proxy. These variables list hosts or domains that should connect directly. A broad entry, an unexpected wildcard, or a destination-specific rule can make behavior differ from your general proxy settings. Do not remove every bypass entry blindly: local development services and private network addresses may intentionally need direct connections. For a controlled test, temporarily clear the bypass variable in the current shell, repeat the request, and restore it afterward if needed.

Inspect or Temporarily Clear NO_PROXY
# Bash or Zsh: inspect the current bypass list
printf 'NO_PROXY=%s\n' "$NO_PROXY"

# Temporary diagnostic only
unset NO_PROXY
unset no_proxy

# PowerShell: inspect or temporarily clear
Write-Output $env:NO_PROXY
Remove-Item Env:NO_PROXY -ErrorAction SilentlyContinue
Remove-Item Env:no_proxy -ErrorAction SilentlyContinue

If curl succeeds but Claude Code still cannot connect, keep the scope narrow. Confirm that Claude Code was launched after the variables were set, that it is running under the expected user account, and that no wrapper script or IDE launch configuration overrides its environment. Then use the exact error message to determine whether the issue is a proxy handshake, a DNS lookup, a timeout, an authentication problem, or a service-side response. A generic “network error” is not enough to identify which layer failed.

Also verify that your Clash Verge profile is applying the route you expect. A local listener can accept a request even when the matching rule selects a direct route, a broken node, or a group that requires manual selection. Use the client’s connection or log view to find the destination and matched rule, then check that the selected proxy is available. Avoid disabling all routing rules as a first fix; that can hide the cause and change how unrelated traffic is handled.

Keep the Setup Reversible and Secure

Once the route is working, decide whether you want a temporary or persistent configuration. Temporary variables are easier to troubleshoot and reduce the chance that other command-line applications unexpectedly use the proxy. If you keep a persistent configuration, document the listener type and port, and periodically confirm that they still match the active Clash Verge profile.

To remove temporary variables in Bash or Zsh, use unset HTTP_PROXY HTTPS_PROXY http_proxy https_proxy ALL_PROXY all_proxy. In PowerShell, remove the corresponding values from the current session with Remove-Item Env:HTTP_PROXY and the other variable names you set. Closing the terminal also discards session-only variables. If you added exports to a startup file, remove those lines and start a fresh shell; otherwise the values will return the next time the file is loaded.

  • Use the local listener shown by the running Clash Verge core rather than relying on a remembered default.
  • Prefer a loopback-bound listener for applications on the same device.
  • Test the proxy with a separate command-line request before diagnosing Claude Code.
  • Launch the application from the same environment in which the test succeeded.
  • Keep a note of the original shell settings so you can restore them after troubleshooting.
  • Respect service terms, regional availability, and account requirements; proxy routing does not override them.

The reliable pattern is straightforward: confirm the listener, set the matching proxy variables, verify a request through that listener, and launch Claude Code from the tested shell. If each step succeeds but the application still reports an error, the remaining issue is more likely to be process-specific or service-specific than a general Clash Verge connection failure. Preserve the working configuration, investigate the exact error, and change only the setting that the evidence points to.