Before Changing Settings: Find Where the Connection Fails
Claude Code runs in a terminal, so its network path can differ from the one used by a browser. A web page may load through Clash’s system proxy while a command-line process connects directly, uses a stale proxy address, or follows a different Clash rule. This is why “Clash is on” does not, by itself, prove that Claude Code is using it.
Start by identifying the exact failure. A timeout or connection error usually points to a reachability, proxy, DNS, or routing problem. A successful connection followed by an authentication error may instead indicate an expired login, an account or organization issue, or a credential problem. Do not repeatedly change proxy settings to solve an error that occurs after the service has already responded.
Also note how Claude Code was started. A terminal opened from the desktop, a terminal launched inside an IDE, a remote SSH session, and a shell inside a container can each have different environment variables and network routes. Test from the same terminal and account that you use for the failing command. If the issue happens only in an IDE, compare its integrated terminal with a standalone terminal before editing your Clash profile.
Diagnostic Goal
Confirm that the Claude Code process has a reachable proxy, that Clash receives its traffic, and that the matching rule selects a working node.
Keep one known-good node selected while testing. Changing the node, shell variables, DNS mode, and routing rules all at once makes it difficult to identify which change helped. Record the original values before editing anything, and remove temporary credentials or proxy settings from logs before sharing diagnostic output.
1Make the Terminal Pass a Proxy to Claude Code
Many command-line applications read proxy settings from environment variables such as HTTPS_PROXY and HTTP_PROXY. Clash’s system-proxy switch mainly configures applications that honor the operating system’s proxy settings; it does not guarantee that every terminal program will inherit or use them. For a command-line test, set the variables in the shell where you will launch Claude Code.
Check the Current Proxy Variables
First inspect what the current shell already provides. The following commands show proxy-related variables without changing them:
If the output is empty, or points to an old port or another proxy application, Claude Code may not be reaching Clash. Confirm the actual mixed-port or HTTP port in your Clash client’s settings; do not assume every installation uses the same port. A common local address is 127.0.0.1, but the port must match the active client configuration.
Set Proxy Variables for One Test Session
Use the port shown by your client in place of 7890 in these examples. A temporary setting affects only the current shell session, making it a safer first test than changing global system configuration.
These values are examples, not universal defaults. Use the protocol and port that Clash actually exposes. If you use a SOCKS listener instead of an HTTP listener, use the corresponding SOCKS URL only if the application and its runtime support it. When uncertain, start with the HTTP-compatible mixed port shown in the Clash client.
Now run Claude Code from that same shell. If it works, the likely issue is proxy inheritance rather than the subscription itself. If it still fails, inspect the active Clash connection log while making one request. No matching connection suggests the process is not using the configured listener, or cannot reach it. A matching connection with a failed rule or node points to routing or node health instead.
Remove Stale Bypass Settings
A NO_PROXY or no_proxy variable can explicitly bypass the proxy for selected hosts. Check it if other proxy variables look correct but requests still go direct. Do not remove company-required bypass entries blindly; instead, check whether the relevant hostname is included and adjust only the entry that is causing the unintended bypass.
Environment variable names are often treated case-insensitively on Windows, but behavior can vary across tools and runtimes on Unix-like systems. Setting the uppercase forms is a practical first step; if the client still does not detect them, check its current documentation and the variables visible to the exact process that launches it.
Keep the Test Reversible
Session-only variables disappear when the terminal closes. Once connectivity is confirmed, decide whether to add them to a shell startup file; avoid storing temporary proxy settings in multiple places.
2Route Claude Code Traffic Through the Intended Clash Policy
After confirming that the terminal can reach Clash, verify what Clash does with the connection. In Rule mode, traffic is assigned according to the profile’s rules and policy groups. The system proxy setting does not automatically make every destination use the same node: a domain may match a direct rule, a reject rule, a different proxy group, or the final fallback rule.
Claude Code’s service requests commonly involve Anthropic domains, and login or related web flows may involve additional service domains. The precise destinations can vary with the product version, account flow, and configuration. Use the connection log to observe the actual hostnames generated by your own request rather than relying on a long, unverified list of domains.
Check Rule Order and Policy Selection
In Clash Verge, Clash Verge Rev, or another Mihomo-based client, open the active profile’s rules or connections view. Search for the hostname shown in the log, then check which rule matched and which policy group was selected. Rules are evaluated in order, so a broad rule above a more specific rule can take precedence. Also confirm that the chosen group exists in the loaded profile and that it has a usable node selected.
If your configuration uses a proxy group named Proxy, a domain rule can be written like this:
The group name is an example. Replace it with a real policy group from your configuration; do not paste the rule unchanged if your profile uses a different name. If you need to route a particular login hostname, add a narrow rule only after confirming that hostname in the connection log. Keep any provider-managed profile changes in an override or supported rules editor where possible, since a subscription update may overwrite direct edits.
For a quick comparison, temporarily switch the relevant policy group to a known-good node. If the request begins working, investigate the prior node or group selection. If nothing changes and the log shows the same route, switching to Global mode is not a useful long-term fix. A temporary Global-mode test can help distinguish rule selection from general connectivity, but return to your normal mode afterward and make a precise rule correction.
Select a Stable Node and Confirm the Listener
Choose a node that can reach the required service reliably, not merely one with the lowest displayed ping. A latency check may only test a simple endpoint; it does not guarantee that authentication, long-lived requests, or the service’s API will work through that node. If one node fails while another works under the same rule, the problem is more likely node-specific or related to the node’s upstream route.
Make sure the proxy listener is active and bound to an address reachable by the terminal. A local terminal on the same computer can usually connect to a loopback listener. A shell inside a container, a remote development environment, or another device may not share that loopback interface: there, 127.0.0.1 points to the container or remote machine rather than the desktop running Clash. In those cases, configure a reachable host and port using your environment’s network model, and do not expose a proxy listener to an untrusted network.
Do Not Expose an Open Proxy
Binding a Clash listener to all network interfaces can allow other devices to use it. Keep local listeners restricted where possible, and use appropriate firewall controls if remote access is necessary.
3Verify the Fix and Narrow Down Remaining Errors
Retest from a fresh terminal after changing a session variable or Clash rule. Start Claude Code, trigger a small operation that requires a network request, and watch Clash’s connection log at the same time. Check three things: the request appears, the expected rule and policy are shown, and the selected node completes the connection. A browser test alone is not enough because browsers may use system proxy settings that the CLI does not use.
Use the symptoms to choose the next check rather than changing several settings together:
| Symptom | Likely area | Next check |
|---|---|---|
| No matching connection in Clash | Shell proxy inheritance or listener address | Inspect the variables in the launching shell and confirm the configured port. |
| Connection appears but uses DIRECT | Rule order or domain matching | Inspect the matched rule and add a specific rule above broader rules if appropriate. |
| Connection uses a proxy but times out | Node, upstream route, or service reachability | Test another stable node in the same policy group and compare the log. |
| Network connects but login is rejected | Authentication, account, or authorization | Complete the supported login flow again and check the account or organization status. |
| Only an IDE terminal fails | Different environment or inherited variables | Compare the IDE terminal’s proxy variables with a standalone terminal. |
If you suspect DNS, first check whether Clash logs the destination and whether the connection resolves to the expected host. Avoid changing DNS mode as an initial response to every timeout; DNS settings can affect other applications and may obscure a simpler proxy-variable problem. If a profile uses fake-IP or another enhanced DNS mode, verify that its DNS configuration is valid and that the client is actually using that profile.
On Windows, check whether Claude Code was launched from PowerShell, Command Prompt, Windows Terminal, or an IDE, because each may inherit environment values differently. On macOS, a terminal launched from Finder or an IDE may not receive the same startup-file settings as a shell launched from another terminal. On Linux, compare the environment of the terminal process with the process that starts the CLI, especially when using a service, container, or remote session.
When connectivity succeeds but Claude Code reports an authorization or login problem, stop changing Clash rules and follow the supported sign-in flow. Confirm that the intended account is active, that any required organization access is available, and that the local session is not using stale credentials. Never paste API keys, access tokens, or full environment dumps into a public issue. If you need to share logs, redact secrets, account identifiers, and any sensitive destination details first.
For a clean rollback, close the test terminal or remove the temporary variables, undo temporary rules, and restore the normal Clash mode. Keep only the smallest verified configuration change. A reliable setup is one where the terminal’s proxy is explicit, the observed connection matches an intentional rule, and a known-good node handles the request without requiring a permanent Global-mode workaround.