Why Claude Code can fail when your browser works
A working Claude conversation in a browser does not prove that Claude Code can reach its services. The browser may inherit Clash Verge’s system proxy setting, while a terminal process may start with no proxy variables at all. Claude Code runs as a command-line application, so its network path depends on the shell environment, the proxy behavior of its runtime, and the rules currently loaded by the Mihomo core. Those pieces can disagree even when the Clash Verge window says that the proxy is running.
It helps to separate the connection into stages. First, the terminal process must be able to reach a local Clash listener. Next, Clash must accept the connection and match the destination against a routing rule. The selected policy group must then choose a usable proxy node, and that node must be able to complete the upstream TLS connection. A failure at any stage can surface as a Claude Code sign-in problem, a request timeout, or a generic network error. Changing an API key before identifying the failed stage can obscure the real cause.
For diagnosis, treat authentication and model requests as related but distinct traffic. Claude Code may contact Anthropic API hosts such as api.anthropic.com, and sign-in or account-related flows can involve additional Claude or Anthropic domains. The exact hostnames can change as the product evolves, and redirects may introduce destinations that are not obvious from the first request. Do not assume that one remembered domain list covers every installation. Capture the actual destination names from Mihomo’s connection log while reproducing the failing operation.
Also distinguish a connection failure from an application-level rejection. A DNS error, refused local connection, TLS handshake failure, and timeout before any response point toward different parts of the path. An HTTP response such as 401 means a server answered and authentication should be checked; it does not by itself prove that the proxy is broken. A 403 or 429 likewise calls for checking account access, policy, or rate limits before replacing nodes repeatedly.
Prepare Clash Verge before changing terminal settings
Start by confirming that Clash Verge is using the profile you intend to test. A profile can be active while still containing an old subscription, an unavailable provider, or rules that send Anthropic traffic somewhere unexpected. Check the profile name and its last update time, then confirm that the Mihomo core is running. If the client offers a configuration reload action, use it after editing rules rather than assuming that a saved file has already become the live configuration.
Next, identify the local listener that your terminal can use. Clash Verge versions and profiles may expose different port numbers and listener types; do not copy a port from an old guide without checking your current settings. Look for the HTTP or mixed-port value in the client or active configuration. A mixed port can accept HTTP proxy requests as well as SOCKS connections, while an HTTP-only port is suitable for the HTTP_PROXY and HTTPS_PROXY variables used below. The address is commonly loopback, such as 127.0.0.1, but use the value actually configured on your machine.
Choose a known-working node manually for the first test. An automatic group can be convenient for daily use, but it adds another variable: a latency probe may select a node that answers the probe yet fails to sustain the longer TLS sessions used by a coding assistant. In Clash Verge, select a node or a stable proxy group, make a simple connectivity check, and keep that selection fixed while testing Claude Code. Only after the direct path is proven should you restore automatic selection and compare results.
Then inspect routing rather than immediately adding broad rules. In the Mihomo connection view, locate the destination host and read the matched rule and outbound. If the request is marked DIRECT when it should use a proxy, the final catch-all rule or a higher-priority rule may be responsible. If it is assigned to a proxy group, verify that the group currently points to the node you selected. Rules are evaluated in order, so a broad domain suffix, IP range, or geolocation rule above a more specific entry can decide the route first.
When logs confirm that Anthropic destinations are being sent to the wrong policy, add only the narrow rules your evidence supports. For example, a domain rule for a hostname observed in the log can be placed above broad regional or catch-all rules and directed to the intended proxy group. If an authentication redirect produces another hostname, observe that hostname and evaluate it separately. Avoid copying a large list of guessed domains or routing all HTTPS traffic through one special group: either approach can hide mistakes and change unrelated application behavior.
Set terminal proxy variables and verify the route
For a first test, configure the shell that launches Claude Code to use the verified HTTP or mixed listener. Substitute your actual port for PORT; the placeholder is not a literal value. On macOS or Linux, run the following in the same terminal session:
export HTTP_PROXY="http://127.0.0.1:PORT"
export HTTPS_PROXY="http://127.0.0.1:PORT"
export http_proxy="$HTTP_PROXY"
export https_proxy="$HTTPS_PROXY"
On Windows PowerShell, use the equivalent session-scoped commands, again replacing PORT with the port shown in Clash Verge:
$env:HTTP_PROXY = "http://127.0.0.1:PORT"
$env:HTTPS_PROXY = "http://127.0.0.1:PORT"
$env:http_proxy = $env:HTTP_PROXY
$env:https_proxy = $env:HTTPS_PROXY
Setting both uppercase and lowercase spellings is a practical compatibility measure: command-line tools and libraries do not all consult the same spelling. These commands affect processes started from that shell, not applications that were already running elsewhere. If you set variables in a shell startup file, open a new terminal after saving it. Keep the change temporary until the connection works; this makes it easy to compare a clean shell with a configured one.
Test the listener before launching Claude Code. With curl, request a lightweight HTTPS endpoint through the proxy, then inspect both the command result and Clash’s connection log. For example, on a shell that supports curl’s proxy option, run curl -I --proxy http://127.0.0.1:PORT https://api.anthropic.com, substituting your real port. An HTTP response, including an application-level error response, can still demonstrate that DNS, TCP, TLS, and the proxy path reached a server. A connection refusal suggests the listener address or port is wrong, or the listener is not active. A timeout requires checking the selected node and the matching Mihomo rule.
This curl test is a diagnostic, not a complete Claude Code test. It exercises one destination and one client implementation; the CLI may make additional requests for authentication, configuration, or model responses. Start Claude Code from the same terminal where the variables are set, perform one operation, and immediately inspect the connection log. Confirm that the observed hostnames are matched to the expected policy and that the outbound node is the one you selected. If the CLI reports a different hostname from your test, use the log evidence to expand your diagnosis instead of assuming curl proved every route.
Once the temporary session works, choose a persistent setup deliberately. You can add the variables to the startup file for the shell you actually use, or configure a terminal profile specifically for Claude Code. Avoid putting proxy variables in a global operating-system setting if only terminal development tools should use them. If you use an editor’s integrated terminal, fully restart the editor after changing persistent variables: many desktop applications pass an environment snapshot to their child processes when they start.
If you use a SOCKS-only listener, do not label its URL as an HTTP proxy merely because the port is local. Use a client option or environment variable that explicitly supports the relevant SOCKS scheme, and confirm the behavior of the installed Claude Code runtime. For the simplest baseline, an available HTTP or mixed listener avoids uncertainty about whether the CLI’s network stack honors a SOCKS URL. Similarly, enabling TUN can route applications that ignore explicit proxy variables, but it changes the system-level path and is not necessary to prove that a terminal proxy works.
Diagnose sign-in failures, timeouts, and unexpected routes
If Claude Code cannot connect at all, first check that it was launched after the proxy variables were set and that the port in those variables matches the live Clash Verge listener. A browser succeeding is not a substitute for this check. In Mihomo’s log, look for a connection at the moment of the CLI attempt. No matching entry often means the process did not use the configured listener, the variable was not inherited, or a different networking path is in use. An entry with DIRECT indicates a routing decision to investigate; an entry assigned to the expected group shifts attention toward the selected node or the upstream service.
For sign-in loops, separate the account flow from a model request. Retry authentication once while watching logs, note every host that appears, and check whether each connection reaches an appropriate outbound. A successful browser login may use browser cookies or a browser-specific proxy path that the terminal does not share. Do not repeatedly delete credentials or change API keys until the network path has been verified. If the CLI receives a clear authentication status from the server, then review the account or credential method supported by your installed version rather than treating the response as a transport timeout.
For timeouts after a request begins, keep the node fixed and check whether the connection is established but stalls, resets, or closes during the response. Long-lived or streamed responses can reveal instability that a quick connectivity probe misses. Compare a second known-good node, one at a time. If only one node fails, the problem is likely node quality, upstream reachability, or a middlebox on that path; changing the domain rule will not repair a weak tunnel. If every node fails for the same observed destination while other HTTPS sites work, investigate the specific route, DNS result, and service response.
For TLS or certificate errors, check the system clock and whether TLS inspection software, a corporate security agent, or a custom certificate store is involved. A proxy should ordinarily tunnel HTTPS rather than require you to disable certificate verification. Do not work around certificate failures by turning off TLS checks or trusting an unknown certificate. That can expose authentication tokens and source code. Record the exact error, verify the machine clock, and compare the same request through a trusted network path before changing security settings.
DNS behavior can also make apparently correct rules misleading. If the log shows a destination but the route differs from expectations, inspect the actual matched rule and whether the core is using its configured DNS path. Avoid adding a broad IP rule based on one temporary address: content delivery networks can change addresses, and an IP-based match may affect unrelated services. Prefer observed domain rules where suitable, then reload the profile and confirm the new rule appears in the live connection verdict.
Use this sequence to keep troubleshooting measurable:
- Confirm Clash Verge’s active profile, running core, listener type, and port.
- Select a known-working node or stable group and leave it unchanged.
- Set proxy variables in the exact shell that will launch Claude Code.
- Test the listener with curl and compare the result with Mihomo’s log.
- Run one Claude Code operation and record its actual destination hosts and matched rules.
- Change one cause at a time, reload the profile if needed, and repeat the same test.
Other proxy clients can be perfectly appropriate, but their limitations become relevant when they expose fewer details about the active listener, routing verdict, or core connections. A browser-oriented proxy toggle alone may not provide a terminal with an explicit endpoint, while a minimal interface can make it harder to distinguish a wrong rule from a failed node. Clash Verge’s practical advantage is the combination of a configurable local proxy, selectable policy groups, and Mihomo connection visibility in one workflow. That does not make every profile correct automatically: the useful difference is that you can verify the route instead of guessing. Once the log confirms the intended host, rule, and outbound—and the same terminal session completes a request—you can keep the setup narrow and return to coding with a reproducible baseline.