Claude Code With Clash Verge: Setup Guide For Stable Access
Understand how Claude Code reaches the network
Claude Code runs in a terminal, but its network requests do not automatically follow the same path as a browser. A browser may read the operating system proxy, use an extension, or apply its own proxy profile. A command-line program usually depends on environment variables, application-specific settings, or a local proxy option. This is why a web page can open normally while Claude Code reports an authentication error, a timeout, or a failure to connect to the model service.
Clash Verge sits between the terminal application and the external service. Its embedded proxy core opens a local HTTP, SOCKS5, or mixed port. Claude Code then sends its HTTPS requests to that local port, and the core applies the active mode, proxy group, and rules. The complete path is therefore made of several independent parts: Claude Code must create the request, the terminal must know where the proxy is, Clash Verge must be listening, and the selected rules must send the destination through a usable proxy group.
Do not treat “Clash Verge is running” as proof that Claude Code is using it. The most useful verification is visible traffic in the Clash Verge connection log while Claude Code is starting, authenticating, or sending a prompt. If the command fails but no related connection appears, investigate the terminal proxy variables or the application’s network path before changing nodes.
HTTP_PROXY / HTTPS_PROXY
Environment variables that tell many command-line tools to send HTTP and HTTPS requests through a local proxy listener.
ALL_PROXY
A commonly supported variable for SOCKS-based routing. Support varies by program, so an HTTP or mixed port is often easier for initial testing.
Clash connection log
The runtime view that shows whether a request entered Clash, which rule matched, and which proxy group handled it.
Claude Code also has a separate authentication layer. A correctly routed request can still fail because the account is not authorized, an API key is invalid, a required environment variable is misspelled, or the selected service does not support the endpoint being requested. Proxy troubleshooting should therefore be separated from account troubleshooting: first confirm that the request reaches the network, then verify credentials and Claude Code configuration.
Prepare Clash Verge before configuring the terminal
Start with a maintained Clash Verge installation appropriate for your operating system, then import a configuration that contains working proxy nodes, proxy groups, and rules. The exact labels can differ between Clash Verge releases and between the original client and Clash Verge Rev, but the important concepts remain similar: an active profile, a running core, a local listener, and a routing mode.
Select and validate the active profile
Open the Profiles or configuration page and identify the profile currently selected for runtime use. If several subscriptions or local YAML files are present, do not assume that the newest file is active. Confirm that the profile has loaded without parser errors and that its proxy groups contain usable members. A profile can appear in the list while the running core is still using a different configuration.
Next, open the proxies or groups view and select a group that can reach the service required by your Claude Code account. Prefer a stable group with predictable behavior instead of repeatedly switching between nodes during the first test. Latency shown in the client is only a rough signal; a node can have low ping latency but still fail during long HTTPS requests, authentication, or streaming responses.
Confirm the local listener and controller state
Find the port settings in Clash Verge. A typical configuration might expose a mixed port like the following:
mixed-port: 7890
allow-lan: false
mode: rule
log-level: info
This is only an example. Your installation may use another port, or the client may manage the listener through its own interface. A mixed port usually accepts both HTTP proxy and SOCKS5 proxy requests, which makes it convenient for terminal testing. If only an HTTP port or only a SOCKS port is available, use the matching environment variable format rather than copying the example blindly.
Keep allow-lan: false when Claude Code and Clash Verge run on the same computer and no other device needs access. Enabling LAN access exposes the listener to other devices on the local network and should be accompanied by an intentional bind address, firewall policy, and authentication design. It is unnecessary for ordinary local terminal use.
Check the system proxy separately
Turn on the system proxy only if you also want supported desktop applications to use Clash Verge. This switch is useful for a browser-based login or for testing general desktop connectivity, but it is not a replacement for terminal variables. Leave the setting enabled during diagnosis if desired, yet still configure the terminal explicitly so the test has a known path.
Before opening Claude Code, make a simple request through the local listener. Replace the port with the actual value shown by Clash Verge:
curl -I -x http://127.0.0.1:7890 https://example.com
A successful response confirms that a program can reach the local HTTP proxy and receive an HTTPS response through it. It does not verify Claude Code credentials, model access, or the final routing rule. If this test fails, fix Clash Verge, the port, the active profile, or the selected proxy group first.
Configure proxy variables for Claude Code
The safest beginner workflow is to set proxy variables only in the terminal session used for Claude Code. This keeps the change reversible and prevents unrelated applications from inheriting the proxy. Once the setup is confirmed, you can decide whether a persistent user-level setting is appropriate.
Windows PowerShell
In PowerShell, set the variables for the current session as follows:
$env:HTTP_PROXY = "http://127.0.0.1:7890"
$env:HTTPS_PROXY = "http://127.0.0.1:7890"
$env:NO_PROXY = "127.0.0.1,localhost"
HTTPS_PROXY commonly uses an HTTP proxy URL even when the destination is HTTPS. The word describes the protocol used for the destination request, not necessarily the protocol spoken to the local proxy. If your Clash Verge listener is SOCKS5-only, use the syntax supported by the program and your installed command-line tools, such as socks5h://127.0.0.1:7891 where SOCKS5 hostname resolution is supported.
These variables affect programs launched from the same PowerShell process after they are set. If another terminal window is already open, setting variables in the new window will not change the old one. Clear the temporary values when finished:
Remove-Item Env:HTTP_PROXY
Remove-Item Env:HTTPS_PROXY
Remove-Item Env:NO_PROXY
macOS and Linux shells
For Bash, Zsh, and many compatible shells, use:
export HTTP_PROXY="http://127.0.0.1:7890"
export HTTPS_PROXY="http://127.0.0.1:7890"
export NO_PROXY="127.0.0.1,localhost"
Some software reads lowercase names, some reads uppercase names, and some checks both. When a tool behaves inconsistently, define both forms in the temporary test session:
export http_proxy="http://127.0.0.1:7890"
export https_proxy="http://127.0.0.1:7890"
export no_proxy="127.0.0.1,localhost"
Do not immediately place these lines in ~/.zshrc, ~/.bashrc, or another shell startup file. A persistent proxy can affect package managers, Git, cloud command-line tools, and local development services in ways that are easy to overlook. First confirm that Claude Code works, then decide whether a dedicated shell alias, project script, or user-level setting gives you better control.
Choose the least complicated variable set
| Use case | Suggested setting | Reason |
|---|---|---|
| First local test | HTTP_PROXY and HTTPS_PROXY |
Clear and widely understood by command-line clients. |
| SOCKS-only listener | ALL_PROXY with supported SOCKS syntax |
Useful when no HTTP or mixed port is available. |
| Local services | NO_PROXY |
Prevents localhost and local development endpoints from being routed externally. |
| Long-term workstation use | Persistent setting only after testing | Reduces repeated setup but can affect unrelated tools. |
Run a controlled setup test
Use the following sequence instead of launching Claude Code immediately and changing several settings at once. A controlled test makes it clear whether the failure belongs to Clash Verge, the terminal, authentication, or the application itself.
- Start Clash Verge. Confirm that the intended profile is active, the core is running, and the selected proxy group has at least one available member.
-
Record the real local port.
Read it from the client’s settings or runtime view. Do not rely on the common value
7890unless it is actually shown by your installation. - Set temporary variables. Use the PowerShell or shell commands above in the same terminal window from which Claude Code will be launched.
-
Test the local proxy.
Run a simple
curlrequest through the listener. Watch the Clash Verge connection log and confirm that the request appears. - Check the destination path. Inspect the matched rule and proxy group in the log. If the request is rejected, sent directly, or matched by an unexpected rule, correct the routing policy before testing authentication.
- Launch Claude Code. Start it from the same terminal session. If it asks you to authenticate, complete the supported sign-in flow without closing the terminal that contains the proxy variables.
- Send a small prompt. Begin with a short request that does not require a large repository scan. This separates basic connectivity from long-running context, file access, and tool execution.
- Observe the connection log again. Confirm that the relevant requests appear while authentication or model interaction is taking place. A browser login alone is not enough evidence that the terminal process is proxied.
When the first prompt succeeds, test a second request that reads a small local project. Claude Code may perform additional operations after the initial model response, including file inspection or tool-related requests. Keeping the first few tests small reduces noise and makes timeouts easier to identify.
If your organization uses a network security product, it may inspect or block HTTPS independently of Clash Verge. In that environment, a local proxy connection can be healthy while the upstream request is denied. The Clash log may show the request leaving through the selected node, but the terminal can still receive an authentication or policy response from the upstream service. Record the status message and distinguish a network refusal from an invalid account credential.
Improve routing stability without overcomplicating the YAML
A beginner does not need to rewrite an entire configuration to make Claude Code more reliable. Start by identifying the domains shown in the Clash connection log during authentication and model requests. Then check whether those domains are covered by the intended rules. A broad rule that sends all traffic through one group may be useful for diagnosis, but it is not always the best permanent policy.
Rule order matters. Clash evaluates rules from top to bottom, and the first matching rule normally determines the policy. A domain rule placed below a broad direct or reject rule may never be reached. Similarly, a rule that matches a parent domain may cover more hosts than expected. Review the actual matched rule in the connection log instead of judging the result only from the YAML file.
Do not enable TUN just to fix an explicit proxy test
TUN mode can capture traffic from applications that ignore system proxy settings, but it adds another layer involving virtual interfaces, routes, DNS handling, permissions, and operating-system integration. If Claude Code works with explicit HTTP_PROXY and HTTPS_PROXY variables, TUN is not required for that workflow. Enable TUN only when you have a specific application that cannot use a local proxy or when you understand the additional routing behavior.
Account for long-running requests
AI coding requests can remain open longer than a simple web page. A node that handles short requests may reset a long streaming response, suffer from intermittent packet loss, or enforce an idle timeout. When responses stop midway, compare another stable proxy group, inspect the Clash log for connection resets, and check whether the terminal reports a timeout or a server-side error. Avoid changing DNS, TUN, rules, and nodes simultaneously because that removes the ability to identify the cause.
Keep DNS troubleshooting separate from proxy authentication whenever possible. If the terminal cannot resolve the local proxy hostname, that is a local configuration issue. If the request reaches Clash but the upstream connection fails, focus on the selected node, rule, destination reachability, or account service. Mihomo-based clients may offer more DNS and routing controls than older Clash cores, but an extra option is not automatically a fix.
Troubleshoot common Claude Code and Clash Verge failures
No request appears in the Clash log
The terminal probably is not using the variables you set, or Claude Code may be launched from a different process environment. Print the relevant variables without exposing credential values, verify the spelling and capitalization expected by the tool, and confirm that the command is running in the same shell. Also check for a wrapper script, IDE-integrated terminal, container, or remote shell that has its own environment.
Connection refused on the local port
This normally indicates that Clash Verge is not listening on the address and port specified by the terminal. Confirm that the core is running, the profile loaded successfully, and no other program replaced or occupied the port. If the client uses an IPv6 listener or a non-loopback address, adjust the proxy URL only after verifying the actual bind address. For local use, 127.0.0.1 is usually the clearest starting point.
Authentication still fails after traffic is proxied
Successful proxying does not make an invalid credential valid. Check whether the environment variable name is correct, whether an old variable overrides a new one, and whether the account or API key is authorized for the requested service. Also verify that the terminal is not using a stale login session or an unintended account. Do not repeatedly rotate proxy nodes when the server is explicitly returning an authentication response.
Timeouts or interrupted responses
First compare the local curl test with a request started by Claude Code. If simple HTTPS traffic works but Claude Code repeatedly times out, inspect the connection log for the destination, rule, proxy group, and reset reason. Try one stable node rather than an automatic group, then test a small prompt. If the small prompt succeeds but a large repository task fails, the problem may involve response duration, upstream limits, local resource usage, or a tool-specific request rather than basic proxy connectivity.
The request uses DIRECT unexpectedly
Review the active mode and rule order. In rule mode, a matching direct rule can bypass the selected proxy group even when the system proxy switch is enabled. A global mode test can help isolate routing behavior, but use it temporarily and understand that it changes all traffic handled by Clash. Return to rule mode after confirming the specific policy that should handle the destination.
Requests appear to loop or behave inconsistently
A proxy loop can occur when a local service is sent back through itself or when multiple proxy applications are configured to chain into one another unintentionally. Add local addresses to NO_PROXY, disable competing VPN or proxy tools during testing, and avoid setting the Clash listener as an upstream proxy for itself. One active local proxy path is easier to verify than several layered clients.
Keep a safer daily workflow
Once Claude Code works, document the minimum settings that made it successful: the Clash Verge listener type and port, the profile name, the intended proxy group, and the terminal variables. Do not document private keys in the same note. This record makes future troubleshooting faster when a client update, profile refresh, or operating-system change alters the runtime behavior.
Use a dedicated terminal profile or a small local command to enable the proxy when needed, rather than forcing every shell and application through Clash permanently. Before starting a coding session, check that the profile is current and that the selected group is available. After finishing, clear temporary variables if the terminal remains open for unrelated work.
Keep configuration backups before editing rules or changing providers. Subscription-generated files can be replaced during an update, while local overrides may be stored separately by the GUI. If a rule is important for Claude Code, place it in the supported override or merge mechanism of the installed client instead of modifying a generated file that will later be overwritten.
Finally, remember that a proxy improves the network path but does not guarantee service availability, account permission, or uninterrupted model responses. Treat Clash Verge as one layer in the workflow. Confirm the local listener, verify the matched route, protect credentials, and test with a small request before beginning a large coding task.