1. Understand Which Proxy Setting the Terminal Actually Uses
Claude Code runs as a command-line application, so a working browser is not proof that the terminal can reach Anthropic’s services. Clash Verge’s system-proxy switch configures proxy settings for applications that read the operating system’s proxy configuration. Many terminal programs instead rely on proxy environment variables, their own settings, or no proxy at all. If Claude Code cannot sign in or requests time out while websites load normally, check the terminal’s proxy path before changing subscription rules or reinstalling the client.
The connection has several separate stages: Claude Code must start, the process must reach a local proxy listener, Clash must receive the connection, the active rules and proxy group must select a usable outbound, and that outbound must reach the required service. A failure at any stage can look like the same vague network error. Testing these stages one at a time helps identify whether the issue is the local port, Clash routing, the selected node, DNS, or account authentication.
For a typical desktop setup, the route looks like this:
Claude Code
→ HTTP proxy environment variable
→ Clash Verge local HTTP or mixed port
→ Clash rules and selected proxy group
→ Anthropic service
The environment variable tells the command-line process where to send proxy requests. It does not choose a Clash node or change the routing mode. Clash Verge still applies its active configuration and outbound policies to the connection.
| Setting or component | What it controls | What it does not guarantee |
|---|---|---|
| Clash Verge system proxy | OS proxy settings for applications that honor them | That every terminal process will use the proxy |
HTTPS_PROXY or https_proxy | The proxy endpoint used by many command-line HTTP clients for HTTPS requests | That the endpoint is listening or has a working outbound route |
| Clash mode and rules | How connections already received by Clash are routed | That Claude Code traffic reached Clash in the first place |
| Claude Code authentication | Whether the account or configured credentials are accepted | That a network timeout is an account problem |
2. Prepare Clash Verge Before Changing the Shell
Start Clash Verge and confirm that the intended configuration is active. Check that the core is running, the proxy group used for the destination has a selected node, and the operating system has not blocked or replaced the local listener. If the client shows a connection log, keep it visible during later tests: a new log entry when you run a command is useful evidence that the terminal request reached Clash.
Confirm the port, mode, and selected policy
- Open Clash Verge’s settings and locate the port configuration. Record the HTTP port or mixed port shown there. Do not assume a port from another computer or an old tutorial.
- Check the current mode. Rule mode is suitable for normal use when the active rules route the required services correctly. Global mode can be a short diagnostic comparison, but it should not be treated as a fix for a terminal that never connects to the local listener.
- Open the proxy group view and confirm that the group selected by the applicable rule has a usable node. A group can exist while its current selection is unavailable or set to a direct route.
- Look for a local connection test or the connection log. If the port is not listening, resolve that first; environment variables cannot make a stopped listener available.
Clash rule matching is independent of the proxy variable. Depending on the configuration and core, the request may be classified using a domain, a resolved IP address, or other available connection metadata. If a request appears in the Clash log but takes the wrong route, investigate the matched rule and policy. If no request appears, first check the variable spelling, port, and shell environment.
Use an HTTP proxy URL for the environment variables in this guide. For example, if the active local HTTP-compatible port is 7897, the URL would be http://127.0.0.1:7897. The port is only an example; replace it with the value displayed by your own Clash Verge installation. The URL scheme describes the connection from Claude Code to the local proxy. It can correctly be http:// even when the destination service uses HTTPS.
3. Set the Proxy for the Terminal Session
Set the variables in the same terminal session from which you will launch Claude Code. A value configured in one shell does not automatically appear in another, and an application already running will not receive environment changes made afterward. Start with a temporary session setting so you can test the route without permanently changing the whole system.
macOS and Linux: Bash, Zsh, or a compatible shell
Replace 7897 with the port Clash Verge currently displays. Set both uppercase and lowercase names because command-line tools do not all read the same capitalization:
export HTTP_PROXY="http://127.0.0.1:7897"
export HTTPS_PROXY="http://127.0.0.1:7897"
export ALL_PROXY="http://127.0.0.1:7897"
export http_proxy="$HTTP_PROXY"
export https_proxy="$HTTPS_PROXY"
export all_proxy="$ALL_PROXY"
claude
HTTP_PROXY and HTTPS_PROXY are the main settings to try for web requests. ALL_PROXY is used by some tools as a general fallback; setting it to an HTTP URL is appropriate only when the local port accepts HTTP proxy requests. Do not put a SOCKS URL such as socks5:// into these variables unless the client and the chosen variable explicitly support that scheme. If the tool reports an unsupported proxy protocol, use an HTTP-compatible listener instead.
To test without launching Claude Code immediately, run a request through the same shell:
curl -I --max-time 15 https://api.anthropic.com
This tests basic HTTPS connectivity through the proxy, not the validity of a Claude Code login. A response such as an HTTP status or an application-level error can still show that DNS, TCP, TLS, and the proxy route reached a server. A connection timeout, connection refused, or proxy-resolution error points earlier in the chain. Avoid adding credentials or private tokens to a command you plan to share.
Windows: PowerShell
In PowerShell, set process-level variables before starting Claude Code. These changes apply to the current PowerShell process and programs launched from it; they are not permanent system settings.
$env:HTTP_PROXY = "http://127.0.0.1:7897"
$env:HTTPS_PROXY = "http://127.0.0.1:7897"
$env:ALL_PROXY = "http://127.0.0.1:7897"
$env:http_proxy = $env:HTTP_PROXY
$env:https_proxy = $env:HTTPS_PROXY
$env:all_proxy = $env:ALL_PROXY
claude
Use the same port replacement rule as on macOS and Linux. If Claude Code is launched from Windows Terminal, VS Code, or another application, that parent application must inherit the variables too. After changing persistent Windows environment variables, close and reopen the terminal or application; an already-running process normally keeps its original environment.
4. Verify the Route and Narrow Down Sign-In or Timeout Errors
Run checks in order and change one variable at a time. First confirm that the local port is correct. Next test a request from the same terminal. Then launch Claude Code and observe the Clash connection log. This separates a local listener problem from a rule or outbound problem, and both from an authentication issue.
- Check the variable in the active shell. On macOS or Linux, use
env | grep -i proxy. In PowerShell, useGet-ChildItem Env:*proxy*. Confirm that the value points to127.0.0.1and the port shown in Clash Verge, with no accidental whitespace or misspelled variable name. - Test the local listener. Run
curl -I --max-time 15 https://api.anthropic.com. If the error says the connection was refused, verify that Clash Verge is running and that the port is listening. If there is a response, the terminal has at least reached a remote HTTP service through some route. - Watch Clash’s connection log. Run the test again while the log is open. If a connection appears, inspect its destination, matched rule, and selected policy where available. If the connection is direct or rejected unexpectedly, review the active rules and the policy group rather than changing the shell variable repeatedly.
- Compare with the browser carefully. A browser may use the operating system’s system-proxy setting while the terminal uses environment variables. A successful browser request therefore confirms neither the terminal variables nor the CLI’s route.
- Retry Claude Code after the network test passes. If the test request succeeds but sign-in still fails, check the CLI’s displayed authentication message, account status, and current sign-in flow. Do not repeatedly delete credentials or switch proxy modes without evidence that the network path is the cause.
| Symptom | Likely area to inspect | Next check |
|---|---|---|
Connection refused to 127.0.0.1 | Clash stopped, wrong port, or no HTTP-compatible listener | Recheck the active port in Clash Verge and restart the core if needed |
| Request times out and no Clash log entry appears | Shell variable not inherited, malformed URL, or wrong port | Inspect the environment in the exact terminal launching Claude Code |
| Request appears in the log but fails upstream | Rule, proxy group, selected node, DNS, or outbound reachability | Inspect the matched policy and test another known-good node if available |
| Network test responds, but sign-in is rejected | Authentication, account, or sign-in flow | Read the exact CLI message and complete the supported account sign-in process |
| Some requests work while others bypass the proxy | Different process environment or per-command proxy behavior | Launch the CLI from the configured shell and check each process’s inheritance |
Timeouts are not always evidence of a bad proxy. The local proxy may be reachable while the chosen node is slow, the service may be temporarily unavailable, or DNS resolution may differ between direct and proxied routes. Conversely, changing a DNS setting will not fix a terminal that cannot connect to the local port. Use the first point of failure in the checks above to decide what to change.
5. Make the Setup Reliable Without Over-Configuring It
Once the temporary setup works, decide where it belongs. If you use Claude Code only occasionally, exporting variables in a dedicated terminal session keeps the effect limited. If you launch it regularly from one shell, place the exports in that shell’s startup configuration. For an IDE or a desktop launcher, configure the environment in the launcher’s supported settings or start the application from a shell that already has the variables. Do not assume that every terminal emulator, IDE, and GUI launcher reads the same startup file.
Keep the settings narrow and easy to undo. Record the current Clash HTTP-compatible port, the shell or launcher where the variables are set, and the command used for a basic connectivity test. If you change the port in Clash Verge, update the environment variables too. Avoid adding broad NO_PROXY exclusions unless a specific local service needs to bypass the proxy; an overly broad exclusion can silently route a required request directly. For local development services, list only the specific hostnames or addresses that genuinely need direct access.
- Use one active proxy client while testing. Two clients can compete to change system settings or listen on similar ports.
- Keep credentials and subscription URLs out of screenshots, shell history, and shared diagnostic logs. Never include an API key in a proxy URL as a workaround for connectivity.
- Use the Clash connection log to verify whether the request entered the core, and use the CLI’s own message to distinguish transport failures from account errors.
- After troubleshooting, remove temporary global-mode changes and restore the routing policy you normally use. The proxy environment variables can remain if they point to the correct local listener.
The reliable configuration is not necessarily the one with the most features enabled. For most terminal workflows, a running Clash Verge core, a confirmed HTTP-compatible local port, correctly inherited proxy variables, and a working rule or selected outbound are enough. Add TUN or other capture methods only when a program cannot use the explicit proxy path and you understand the platform-specific routing implications.