Why Claude Code Times Out
Claude Code runs in a terminal, but its network requests still depend on your operating system, DNS resolver, Clash client, active proxy group, and the selected proxy node. A browser working normally does not prove that a command-line process is using the same route. The browser may follow the system proxy automatically while the terminal connects directly, or Clash may proxy browser traffic but send Claude Code’s API requests through a rule that selects DIRECT.
Timeouts can appear in several forms: the initial sign-in page does not open, authentication completes but the terminal keeps waiting, requests fail intermittently, or a conversation starts and then stalls. These symptoms can have different causes. A bad node, a rule-order issue, an expired login session, DNS trouble, a restrictive network, or a temporary service-side problem can all look like a proxy failure.
This guide uses a controlled troubleshooting sequence: confirm that the client and node work, check how Claude Code is routed, pass the proxy environment to the terminal when needed, and then test DNS or TUN mode only if simpler checks do not help. Make one change at a time and restore your original settings if a test does not improve the result.
Recommended Approach
Start with the active Clash mode and proxy node. Then check the matching connection in the client’s connection log before changing DNS, TUN, or your profile.
1Check Clash Mode, Node, and Rules
First verify that Clash is running and that the profile you expect is actually active. In Clash Verge, Clash Verge Rev, or another Mihomo-based client, open the dashboard and check the system proxy toggle, current mode, active profile, and selected proxy group. Names and menu locations vary by version, but the basic checks are the same. Do not assume that importing a profile or selecting a node automatically enabled the system proxy.
Use the client’s built-in connection test, if available, to check the selected node. Then open a few ordinary websites that should use that node. If the node cannot connect or general proxied browsing also fails, troubleshoot the node or service profile before changing Claude Code settings. Try one other known-working node. Avoid repeatedly switching among many nodes while a request is in progress; doing so makes it harder to identify which change mattered.
Inspect the Routing Mode
Rule mode applies the profile’s routing rules. This is usually the best everyday setting, but an existing rule may send a service domain directly or to an unavailable group. Global mode sends traffic through the selected proxy policy, which can be a useful short test, but it is not a substitute for a correct rule configuration. Direct mode intentionally avoids the proxy and is unlikely to help when the direct route is the source of the timeout.
While Claude Code is attempting a request, look in Clash’s connection log for a new connection associated with Claude or Anthropic. Check the destination host, the matched rule, the policy group, and the result. If the connection appears as DIRECT, but you expected a proxy, a routing rule or mode is likely responsible. If no related connection appears, the terminal may not be using the system proxy, the traffic may not be captured, or the failure may happen before a network connection is made.
Read the Log Before Editing Rules
A connection log can distinguish “wrong route” from “proxy route failed.” Record the matched rule and policy before changing your profile so you can reverse the change safely.
Check Rule Order Carefully
Clash evaluates rules according to the active profile and its rule order. A broad rule near the top can match before a more specific rule lower down. If you maintain your own profile, add any service-specific routing rule above broad catch-all rules, and direct it to a proxy group that exists in your configuration. Do not paste a rule with a made-up group name: an unknown policy can cause configuration errors or leave the request routed differently than intended.
These example domains are starting points, not a complete or permanent list of every endpoint used by the application. The sign-in flow, API, and supporting services can use different hosts, and service endpoints may change. Use the connection log to identify the actual destination rather than adding large lists of unrelated domains. If your profile is provider-managed, prefer its supported rule settings or a local override instead of editing a subscription file that may be replaced on update.
2Pass the Proxy to Your Terminal
Many command-line applications do not automatically inherit a desktop client’s system proxy setting. If the browser works through Clash but Claude Code does not, the terminal process may need proxy environment variables. Set them in the same terminal session where you launch Claude Code, using the local mixed-port or HTTP/SOCKS port shown in your Clash client. Port numbers differ by profile and client; 7890 below is only a common example.
For a mixed port that accepts both HTTP and SOCKS-style proxy connections, try the following in macOS or Linux shells:
Use the address and port displayed by your client. If your profile exposes separate HTTP and SOCKS ports, use the matching protocol and port instead of assuming that a mixed port is enabled. The socks5h form asks the proxy to resolve destination names where the application supports it; if your client or application does not accept that scheme, use the documented scheme for that client. A proxy variable cannot fix a Clash listener that is disabled or bound to a different address.
On Windows PowerShell, set the variables for the current window before starting the command:
These commands affect the current shell and child processes; they do not change system-wide settings. This makes them useful for a reversible test. If the test works, you can decide whether to add the variables to your shell startup file or use a terminal-specific configuration. If it does not, close that terminal or clear the variables and return to the original setup:
Some tools recognize lowercase forms such as https_proxy as well as uppercase names. Avoid setting conflicting values in multiple places: a shell startup file, IDE terminal, launch script, and operating-system proxy can disagree. If you use an IDE, fully restart its terminal after changing environment variables; an already-running application generally does not inherit values added later.
Keep Proxy Credentials Private
Do not paste proxy passwords, subscription URLs, authentication tokens, or private configuration into screenshots, public logs, or support posts. The examples above use a local address and contain no credentials.
3Run a Controlled Connection Test
Use this sequence to isolate the failure without changing several parts of the network at once. Keep a note of the original mode, selected node, and any environment variables so you can restore them.
- Confirm the service and account. Check that Claude Code can start, your sign-in session is valid, and the provider has not reported a current service issue. If the same request fails without Clash on a network where direct access is supported, investigate account, installation, or service status as well.
- Verify the Clash profile and node. Confirm the profile is active, the client is connected, and the selected node passes its connection test. Test one other reliable node if needed.
- Test the route in Global mode briefly. If the client offers Global mode, select the intended proxy group and make one short test. If this works but Rule mode fails, return to Rule mode and investigate the matching rule. Switch back after the test.
- Watch the connection log. Start Claude Code and check whether a related connection appears. Note the destination, rule, policy, and outcome. If the log shows a direct route, inspect rule order; if it shows a proxy error, test a different node.
- Set terminal variables for one session. Use the correct local port and launch Claude Code from that same shell. If this changes the result, the gap is likely between the desktop system-proxy setting and the terminal process.
- Retry authentication only when appropriate. If the network request succeeds but sign-in still fails, use the application’s supported sign-out and sign-in flow. Do not repeatedly delete configuration or credentials as a first troubleshooting step.
- Change one setting, then retest. Return to the same operation after each change. A single successful test is more informative than changing mode, node, DNS, and TUN simultaneously.
For a quick comparison, note what changes between the working and failing cases:
| Observation | Likely area to inspect | Next safe test |
|---|---|---|
| Browser works; terminal has no matching Clash connection | Terminal proxy inheritance or traffic capture | Set session-only proxy variables or test TUN mode |
Connection is logged as DIRECT |
Rule mode, rule order, or selected policy | Compare with a brief Global mode test |
| Connection uses the proxy but fails on one node | Node health, latency, or provider-side filtering | Try one other known-working node |
| Network request succeeds but sign-in does not | Authentication session, account, or application state | Check sign-in status and supported recovery steps |
| Several unrelated applications fail at once | Clash core, profile, DNS, or local network | Check the client log and restore recent network changes |
4Use TUN and DNS as Follow-Up Checks
If terminal variables do not help and Clash shows no connection for Claude Code, check whether your client supports TUN mode. TUN creates a virtual network interface that can capture traffic from applications that do not follow the system proxy. It may require administrator privileges, permission to install or enable a network extension, or approval in the operating system’s security settings. Enable it only in the official client you already use, and review its status indicator before testing.
TUN mode is not automatically the right fix. It can change how other applications, local devices, DNS requests, and network interfaces are handled. If enabling it causes local services or ordinary browsing to stop working, turn it off and restore the previous state. Do not run two different traffic-capture tools at the same time unless you know how their routes interact; overlapping VPNs, TUN interfaces, and security software can create hard-to-diagnose conflicts.
Check DNS Without Replacing Your Whole Configuration
DNS problems are more likely when the client cannot resolve a host, the log reports a name-resolution error, or connections behave differently across networks. Confirm that Clash DNS is enabled if your profile expects Clash to handle DNS, and check whether the active mode and operating system are using the intended resolver. A stale DNS cache can also affect a test, but changing DNS servers blindly may introduce leaks, break local names, or conflict with a managed network.
Prefer a small diagnostic change over copying a complete DNS configuration from an unrelated guide. Mihomo options and profile behavior vary, and a setting that works in one environment may not fit another. If you edit YAML, save a backup, validate the configuration in the client, and change only the relevant DNS option. Do not disable operating-system security protections or add broad firewall exceptions simply to make a connection succeed.
Collect Useful, Redacted Logs
If the problem persists, collect the time of the failure, the client and core version, the selected mode, whether a connection appeared in the log, and the general error category. Redact subscription links, proxy credentials, account identifiers, authorization headers, and tokens before sharing diagnostic output. A brief test on another trusted network can help determine whether the issue follows the device or the network, but follow your organization’s policies if this is a managed computer.
When to Stop Changing Clash Settings
If other applications route normally, the expected Claude connection reaches the proxy, and the same timeout occurs across suitable nodes, the remaining issue may be account-specific, service-side, or related to the local network. Preserve the logs and check official support information rather than adding more unverified rules.
Frequently Asked Questions
Should I leave Clash in Global mode?
Usually not just to fix one application. Global mode is useful as a short diagnostic comparison, but it sends more traffic through the selected proxy and can affect services that should use a direct route. If Global mode works while Rule mode does not, use the connection log to identify the rule or policy that needs attention, then return to your preferred mode.
Why does Claude work in my browser but not Claude Code?
The browser and terminal may use different proxy mechanisms. A browser can follow the operating system’s proxy setting while the terminal process ignores it. Check whether Claude Code appears in the Clash connection log, then try session-only proxy variables using the local port configured in your client. Also verify that the terminal or IDE was started after the variables were set.
Will changing nodes always fix a timeout?
No. Changing nodes can help when the selected node is unavailable, slow, or unable to reach the destination. It will not fix a terminal that bypasses Clash, a rule that routes traffic directly, an invalid sign-in session, or a service outage. Change one node at a time and compare the result with the connection log.
What should I do if the timeout continues?
Restore any experimental settings that did not help, record the exact error and the result of each controlled test, and check the official Claude Code and provider status or support channels. Share only redacted diagnostics. If the connection works on a different network but not your current one, consult the network administrator or service provider rather than attempting to bypass network controls.