Why Claude Code Times Out When Clash Looks Connected

Claude Code is not a single browser request. A normal session may involve authentication, account discovery, model API calls, usage checks, telemetry, update checks, and long-lived streaming connections. Each request can use a different hostname, resolver result, connection lifetime, and routing decision. That is why a browser tab may open an Anthropic page while the terminal still reports an API timeout, a stalled login, or a connection reset.

Clash evaluates outbound connections independently. The application can show a healthy node and a green system-proxy indicator while Claude Code traffic is still using DIRECT, an unsuitable policy group, or a rule that sends only part of the session through the proxy. The terminal then waits for a response that never arrives. Retrying the command often creates more noise rather than fixing the route, especially when a streaming request is repeatedly assigned to a congested server.

The most useful mental model is to separate the problem into layers: the Claude Code process must reach the local Clash listener, Clash must classify the destination correctly, DNS must return usable answers, the selected node must support the required TLS and streaming behavior, and the remote service must accept the account and request. A failure in any one layer can look like the same generic timeout. Troubleshooting becomes much faster when you test those layers in order instead of changing five settings at once.

ℹ Scope: Use these checks for permitted accounts, personal networks, and environments where proxy software is allowed. Corporate, school, and regional policies may require an approved VPN or gateway instead of an independent Clash profile.

Identify the Failing Layer Before Changing YAML

Start by recording the exact symptom. “Claude Code does not work” is too broad to guide a repair. Does the command fail immediately, hang after authentication, return an HTTP error, or begin generating text and then stop? An immediate error usually points to a missing executable, invalid environment variable, or unavailable local port. A delay of thirty seconds or more suggests DNS, routing, TLS negotiation, or a dead node. A session that begins successfully but freezes during generation is more consistent with streaming instability, connection reuse, idle timeouts, or an overloaded exit.

Check whether the failure is limited to Claude Code. Open an ordinary HTTPS site through the same Clash profile, then test an Anthropic-related web page and another developer service. A general failure indicates that the listener, system proxy, TUN interface, or selected node may be broken. If ordinary sites work but Claude Code fails, focus on the CLI’s proxy inheritance and destination rules rather than immediately replacing the subscription.

The process context matters as well. A terminal started before Clash was enabled may retain old environment variables. A GUI-launched editor can have a different environment from a shell launched by your login profile. On macOS and Linux, a shell may contain HTTP_PROXY or HTTPS_PROXY while a child process ignores them. On Windows, PowerShell, Command Prompt, an integrated IDE terminal, and a scheduled process can each expose different variables. Always test from the same terminal in which Claude Code fails.

Symptom Most likely area First check
Fails instantly Local listener or CLI environment Port, proxy variables, and process startup context
Login page opens but callback hangs OAuth route or browser and terminal mismatch Clash logs and callback handling
Request waits and ends as timeout DNS, rule match, or unreachable node Connection log and matched policy
Text starts, then stops Streaming path or unstable server Another node and long-lived connection behavior

Do not treat a successful ping as proof that a node can serve Claude Code. ICMP may be blocked, while TCP and TLS work normally, or the reverse may be true. Similarly, a latency test to a generic URL does not measure the complete path to the service you need. Use the Clash connection panel and logs to confirm which destination was contacted, which rule matched, and which proxy group actually handled it.

Check Clash Mode, Local Port, and Proxy Inheritance

Confirm that Clash is running in a mode appropriate for the way Claude Code is launched. In Rule mode, traffic is classified by domain and IP rules. In Global mode, most traffic follows the selected proxy group, which can be useful as a temporary diagnostic but is not always suitable as a permanent policy. In Direct mode, the application may bypass the proxy entirely. TUN mode captures more traffic at the network layer, but it introduces virtual-interface, DNS, and permission variables that should not be your first diagnostic step.

Next, identify the local listener. Clash clients commonly expose a mixed port that accepts HTTP and SOCKS5 connections, but the number is not universal. A profile may use one port for HTTP, another for SOCKS, and a separate external controller port. Copying a port number from an old tutorial can send Claude Code to an unrelated service or to a closed socket. In the client dashboard, verify the active port and whether the listener is bound to 127.0.0.1, localhost, or another permitted address.

If Claude Code supports explicit proxy configuration, use the listener documented by your client and keep the test narrow. For a mixed port, the scheme may be http; for a SOCKS listener, it may be socks5 or socks5h. The last option can be important because it asks the proxy side to resolve names, avoiding a local DNS answer that Clash cannot route consistently. Do not assume that an HTTP proxy URL and a SOCKS URL are interchangeable merely because both use the same port number.

Inspect the environment without exposing credentials or subscription URLs. Look for stale values such as an old VPN port, a loopback address used by another client, or a proxy variable containing a typo. Also check lowercase variants because many tools read http_proxy and https_proxy differently from their uppercase counterparts. A shell can contain conflicting values, and the last exported value may silently win. Remove obsolete entries, restart the terminal, and test again from a clean process.

⚠ Do not stack proxy layers blindly: running a browser extension, a system proxy, TUN mode, and explicit CLI variables at the same time can create loops or make the request path impossible to identify. Establish one known route first, then add layers only when the application genuinely requires them.

Review Routing Rules and DNS Behavior

In Rule mode, open the live connection list while starting Claude Code. Search for the hostnames generated during login and model requests, then read the matched rule and policy group. The important question is not whether a rule containing “Claude” exists in your YAML; it is whether the actual connection matched that rule. A broad rule placed above a specific domain rule can capture the request first. A rule provider may also have changed after its last update, making a formerly reliable assumption obsolete.

Keep vendor-specific rules above broad geographic, advertising, or final-match rules. If several Anthropic-related hostnames participate in the session, route them coherently during testing rather than sending one through a proxy and another through DIRECT. This does not mean blindly proxying every domain with a vaguely similar name. It means using the connection log to identify the real destinations and then creating the narrowest permitted policy that covers the required flow.

DNS can fail before the rule engine has a useful destination. Fake-IP mode, redirection hosts, system resolvers, and encrypted DNS each change what Clash sees and when it sees it. A stale cache may return an address that is unreachable from the selected node. A local resolver may answer quickly but produce a route that conflicts with the proxy’s expected geography. Conversely, a remote resolver can introduce delay if it is unreachable or if every query is forced through an unhealthy tunnel.

Compare behavior with the client’s DNS settings temporarily simplified. Do not change every resolver at once. Record the current mode, test a known-good resolver or the profile’s documented default, clear the relevant cache, and restart the affected process. If the connection appears in Clash logs but never completes TLS, DNS may not be the only issue; inspect the selected node and the rule result before concluding that resolver replacement is the solution.

DNS and fake-IP warning signs

Typical DNS-related clues include domains resolving in a browser but not in the CLI, repeated resolution attempts in the Clash log, a destination changing between IPv4 and IPv6, or an application connecting directly to an address that never appears in the expected proxy group. Some command-line runtimes cache DNS longer than the GUI browser does. Restart Claude Code after changing DNS or rules so that an old socket and resolver result do not contaminate the next test.

IPv6 deserves a specific check. If the operating system prefers an IPv6 address that the chosen node or local network cannot carry reliably, the request may appear to hang before falling back to IPv4. Temporarily compare IPv4 and IPv6 behavior where your client supports that control, but do not permanently disable an entire protocol stack without understanding other applications that depend on it. The goal is to isolate the failing path, not to hide a network design problem.

Hands-On Repair Sequence: From Direct Test to Stable Rule

Use the following sequence and change only one variable between tests. Keep the Clash connection log visible throughout the process. This makes it possible to distinguish “the request was never captured” from “the request was captured but the node could not complete it.”

  1. Close Claude Code and competing tunnels. Stop duplicate Clash clients, VPN applications, traffic accelerators, and browser proxy extensions. Leave one client active with one profile and one selected group.
  2. Confirm the listener. Read the current mixed or SOCKS port from the client interface instead of relying on a saved note. Verify that the port is listening locally and that no other application owns it.
  3. Run a controlled proxy test. Use a harmless HTTPS request through the same listener and observe whether a corresponding connection appears in Clash. If no connection appears, Claude Code is not using that route or the command is failing before network access.
  4. Test a temporary global policy. Select one known-good node or group and use Global mode only for diagnosis. If Claude Code works here, the problem is probably a Rule-mode match, DNS policy, or group selection rather than the account itself.
  5. Return to Rule mode. Watch the live log while starting the command again. Record each relevant hostname, the matched rule, and the selected outbound group. Add or adjust narrow rules only after collecting evidence.
  6. Compare a second node. Keep the same mode and rules, change only the server, and repeat the request. A successful second node points toward congestion, filtering, TLS compatibility, or capacity problems on the first node.
  7. Test the complete workflow. Verify login, a short model request, and a longer response separately. A node that passes a short request but fails streaming should not be called fully healthy.

Once the route works, remove temporary Global-mode assumptions and encode the stable policy in the profile. Keep the rule narrow, choose a dependable group rather than an arbitrary single server, and document why the rule exists. If your provider supplies rule providers, confirm their update schedule and inspect changes after an incident. A working configuration that depends on an undocumented remote list can regress without any local edit.

Node Health, TLS, and Long-Lived Streaming Sessions

Claude Code may keep a connection open while receiving incremental output. This stresses a proxy path differently from loading a small web page. A server can have excellent probe latency yet fail under sustained traffic because of packet loss, overloaded CPU, connection limits, or an aggressive idle timeout. If the request starts and then stops, compare nodes using the same prompt and similar response size. Do not judge a node only by the first token or by a single latency number.

Review the Clash log for TLS errors, connection resets, premature EOF messages, repeated retries, and upstream timeout notices. These details help separate a remote refusal from a local routing problem. A reset immediately after connection establishment may indicate server instability or a middlebox. A timeout before TLS begins is more suggestive of DNS, reachability, or an unsuitable rule. A clean local connection followed by an upstream error may be an account, quota, or service-side issue rather than a Clash defect.

Keep time synchronization enabled on the operating system. Incorrect clocks can break certificate validation and authentication even when ordinary pages appear to load. Also check whether security software is inspecting TLS, whether a corporate certificate is injected, and whether a managed device prohibits unknown proxy roots. Never install a certificate merely because a timeout exists; validate its source and policy purpose first.

Common Questions About Claude Code and Clash Timeouts

Why does Claude work in the browser while Claude Code times out?

The browser and terminal may use different proxy settings, DNS paths, cookies, authentication state, and network stacks. The browser may follow the system proxy while Claude Code reads environment variables, or the browser may already have a route cached through a different node. Compare the two processes in Clash’s live connection log instead of assuming that they share the same path.

Do I need TUN mode to make Claude Code work?

Not necessarily. If Claude Code supports an explicit HTTP or SOCKS proxy and the local listener is reliable, a normal proxy mode is often easier to verify. TUN mode is useful for applications that ignore proxy variables, but it adds virtual-interface permissions, DNS interception, and route precedence. Enable it only after confirming that the application cannot use a direct listener and after understanding how to disable it safely.

Why does changing only the node solve the timeout?

Nodes differ in congestion, upstream reachability, TLS behavior, connection limits, and routing to the service. A healthy subscription does not mean every server is equally suitable for long-lived developer traffic. If one node works under identical rules and listener settings, keep the comparison and retire or deprioritize the unstable node rather than rewriting the entire configuration.

Should I keep retrying the command until it succeeds?

Repeated retries can occasionally land on a healthier connection, but they hide the pattern and may create unnecessary load or confusing authentication state. Capture one failure in the Clash log, identify the matched rule and node, make one controlled change, and test again. Evidence-based iteration is faster than random retries.

Browser-first proxy tools can make the situation look simpler because they bundle cookies, DNS behavior, and interface settings into one visible window, while generic terminal clients often expose none of those decisions. A manually maintained SOCKS setup may offer flexibility but usually requires more environment work and gives weaker visibility into rule matches. Clash V.CORE is useful here because its live connections, policy groups, rule mode, DNS controls, and TUN options let you move from a narrow listener test to a stable routing policy without losing observability; once you have identified the reliable path for Claude Code, you can download Clash V.CORE and apply the same evidence-based workflow.

// Editor's Pick

Make Claude Code routing easier to diagnose

Use a clear Clash workspace to inspect proxy listeners, rule matches, DNS behavior, and node health before changing your whole configuration.

  • Live visibility into Claude Code connections
  • Rule and Global modes for controlled testing
  • Flexible HTTP and SOCKS listener support
  • DNS controls for resolving route conflicts
  • Node groups for reliable failover testing
Get Clash V.CORE →