Configuration October 29, 2026

Claude Code Proxy Setup: Use Clash for Reliable Terminal Access

Troubleshoot Claude Code terminal access with a practical Clash setup guide. Check your proxy profile, shell variables, and routing rules to pinpoint connection failures, while keeping regional availability and account requirements in mind.

Docker Proxy GitHub Acceleration Advanced Config YAML

1. What this setup can—and cannot—fix

This guide is for developers who run Claude Code in a terminal and use Clash or a Mihomo-based client such as Clash Verge Rev to manage proxy traffic. The goal is to make command-line connections more predictable: identify whether a failure comes from the active Clash profile, the shell’s proxy environment, a routing rule, DNS, or an account and availability requirement. A working browser session is useful evidence, but it does not prove that a separate terminal process can reach the same service through the same route.

Claude Code is a command-line application, not simply a page loaded inside a browser. Depending on the task and the authentication method, it may contact Anthropic services for sign-in, API requests, and related application functions. Its network requests are made by a process launched from your shell, an IDE-integrated terminal, or an automation environment. Each launch context can have a different environment and can inherit different proxy settings. That is why “the browser works” and “Claude Code works” are not equivalent tests.

A proxy can affect the network path chosen by your computer; it cannot create an account entitlement, change a provider’s service policy, or make a feature available in a region where it is not offered. Before changing routing, check that your account is eligible, your credentials are valid, and your organization permits the use of the chosen network path. If a work account, employer policy, or contractual data-residency requirement applies, follow that policy rather than attempting to route around it. Treat a proxy node as infrastructure operated by someone else: avoid sending it secrets unnecessarily, and never share API keys, access tokens, or an unredacted profile when asking for help.

The instructions below use representative hostnames and configuration patterns, not a permanent allowlist. Provider endpoints and authentication flows can change, and a particular Claude Code release may use additional services. Confirm current requirements with Anthropic’s documentation and verify the actual destination shown in Clash’s connection log. In particular, do not assume that a hostname found in a forum post is still required, or that every host under a broad vendor domain should use the same policy.

2. Why a terminal can fail while the browser works

A browser and a command-line application may differ in at least four ways: which proxy configuration they read, which DNS resolver they use, which process actually opens the connection, and which network destinations they contact. A desktop browser may follow the operating system’s proxy setting, while a shell program may instead look for environment variables. Conversely, a Clash TUN interface can capture connections from processes that do not understand HTTP proxy variables, provided that the operating system routes those connections through the tunnel and the relevant traffic is not excluded.

The shell also matters. A terminal opened from a desktop menu may not load the same startup files as a login shell. An IDE can keep an integrated terminal or extension host alive after you change proxy variables, so the old process continues using its original environment. A build task, container, remote development session, or CI runner may be on another machine entirely; configuring Clash on your laptop does not automatically configure those environments. When testing, record where the command runs and which user launched it.

There is no single “Clash is on” state that guarantees every request takes the intended path. The client may be in Global, Rule, or Direct mode; the selected profile may define different rules or proxy groups; and the local mixed port may have been customized. A rule can match the API hostname but not an authentication hostname, or a broad rule earlier in the list can catch the request before the specific rule is evaluated. DNS choices can add another variable: a hostname resolved by the application or the operating system may behave differently from a hostname resolved through Mihomo.

Start with the exact symptom rather than changing multiple settings at once. A name-resolution error points toward DNS or a hostname problem. A connection timeout may indicate that the request is taking a blocked or unavailable route, that the chosen node is unhealthy, or that a local firewall is interfering. A TLS or certificate error calls for a different investigation than an HTTP authentication response. An explicit authentication or account error often means the network connection reached a service, so repeatedly changing proxy modes may not address the real cause. Note the complete error, the time, the command context, and the connection-log result before editing the profile.

Clash is useful here because it can expose the route decision for an individual connection instead of forcing every application into a single all-or-nothing VPN state. That control is only valuable when the decision is observable and the rules are ordered intentionally. A carefully tested route can send relevant Anthropic traffic through a suitable proxy group while leaving internal Git hosts, local development services, and unrelated traffic on the paths your network policy requires.

3. Configure Clash and the environment Claude Code uses

Check the active profile and local listener

First open the Clash client and confirm that the expected profile is active, the client is connected to a usable node, and the mode is appropriate for the test. In Clash Verge or Clash Verge Rev, inspect the current proxy group selection rather than assuming that a group named “Auto” has selected a reachable node. If the profile is managed by a subscription, avoid making edits that will be overwritten at the next update; use the client’s supported overrides or maintain a separate test profile where appropriate.

Find the local HTTP or mixed port in the client’s settings or the effective Mihomo configuration. Many installations use 7890 as a familiar default, but the actual value can differ, so do not copy it blindly. A mixed port accepts HTTP proxy traffic as well as SOCKS connections; an HTTP port accepts HTTP proxy requests. If you configure shell variables with an HTTP URL, point them at a listener that supports HTTP proxying. An example using a common local port is shown below; replace the port if your client displays another value.

export HTTP_PROXY=http://127.0.0.1:7890
export HTTPS_PROXY=http://127.0.0.1:7890
export http_proxy="$HTTP_PROXY"
export https_proxy="$HTTPS_PROXY"

The proxy URL in HTTPS_PROXY often still begins with http://: that describes the connection from the application to the local HTTP proxy. HTTPS destinations are then reached through the proxy’s CONNECT method. Do not change it to https:// unless the local listener itself is configured for TLS. For applications that support SOCKS instead, use the correct SOCKS URL and listener; do not assume that every command-line runtime interprets HTTP proxy variables as SOCKS settings.

On PowerShell, set variables in the current session with syntax such as $env:HTTPS_PROXY = "http://127.0.0.1:7890". On Windows Command Prompt, a session-level example is set HTTPS_PROXY=http://127.0.0.1:7890. These commands affect processes launched from that shell after the variable is set; they do not retroactively update a terminal, IDE, or Claude Code process that is already running. For a durable setup, prefer the startup mechanism appropriate to the shell and user account, and document the change so it can be reversed.

Choose explicit proxy variables or TUN deliberately

Explicit variables are a useful first test because they make the intended local proxy endpoint visible in the shell. They are not a universal guarantee: applications and their networking libraries differ in which variables they read, whether they honor lowercase names, and whether they apply proxy settings to every request. Setting both uppercase and lowercase variants can improve compatibility, but it does not override application-specific behavior or a separate proxy setting supplied by an IDE, container, or service manager.

If the command does not appear in Clash’s connection log despite the variables being set, check that the listener address and port are correct, that the process was launched from the configured shell, and that a local firewall is not blocking access to the listener. Then test with another command-line client known to support the same proxy variables. If that test reaches a destination through Clash but Claude Code does not, investigate the application’s own runtime and current documentation rather than concluding that the profile is broken.

TUN mode is an alternative when an application does not honor HTTP proxy variables or when several child processes need a consistent system-level route. It can capture traffic below the application layer, but it also changes the scope of the configuration: routing, DNS handling, permissions, and exclusions can affect more than Claude Code. Enable it only when you understand the client’s implementation and your operating system’s network behavior. After enabling TUN, confirm that the connection log shows the expected process or destination, and check that local networks and corporate resources still follow their required routes.

Avoid configuring conflicting layers without a reason. For example, an application-specific proxy, shell variables, operating-system proxy settings, and TUN capture can make it difficult to determine which route is active. For a controlled diagnosis, begin with one method, launch a fresh terminal, make one test, and inspect the log. If you switch methods, clear or unset the previous variables and restart the relevant terminal or IDE process so that stale settings do not contaminate the comparison.

4. Route observed traffic and diagnose failures

Build rules from observed traffic

In Clash’s connection view, reproduce one failing action and note the destination, matched rule, selected policy, and result. Depending on the client, the process name may also be visible. Test sign-in and a normal Claude Code request separately: authentication can involve destinations that differ from the service endpoint used for later requests. Use the log to identify the hostnames your own session actually contacted, then compare those observations with current official documentation. This evidence-based approach is more reliable than copying a large list of guessed domains.

If the observed traffic requires a profile rule, put a specific rule above broader rules that could match the same request. The following is a minimal illustration, not a complete production policy. Replace the policy name with a proxy group that exists in your profile, and add only destinations confirmed by your logs and the provider’s current guidance.

rules:
  - DOMAIN,api.anthropic.com,Claude-Proxy
  - MATCH,Your-Final-Policy

A rule for api.anthropic.com alone may not cover sign-in, console interactions, or other functions. Conversely, routing every hostname under a broad vendor suffix through a proxy may capture services that should use a corporate network or a different policy. Add a hostname only when you understand why the application contacts it and what route it should take. If your organization requires a managed VPN or a private gateway, keep those destinations on the mandated path instead of overriding them with a personal proxy.

Rule order is important in rule-based profiles. A broad domain-suffix, geographic, or catch-all rule placed before a specific Claude-related rule may decide the route first. In the connection details, confirm not only that the request appears, but also which rule matched and which proxy group handled it. After editing, apply the profile and repeat the same test. Do not judge a change from a different action or a reused connection that was opened before the profile update.

Use a repeatable diagnostic sequence

A short, repeatable sequence helps distinguish the most common causes without turning troubleshooting into guesswork. First, confirm that the system clock is accurate, the client is running, and the selected node can reach ordinary HTTPS destinations. Next, open a fresh shell, set the proxy variables if that is your chosen method, and run a harmless connectivity check against a destination you are authorized to test. The result is not proof that Claude Code’s endpoint is reachable, but it can confirm whether the shell can contact the local listener and whether basic proxying works.

Then launch Claude Code from that same shell and reproduce the smallest failing operation. Keep the shell, Clash connection log, and application output visible. If the log shows no corresponding connection, investigate environment inheritance, application proxy support, TUN capture, and whether the command is running locally or in a remote environment. If the log shows a connection routed as DIRECT when you expected a proxy, inspect rule order, profile selection, and the active mode. If the expected proxy group is selected but the connection times out, test a different suitable node and check whether the service is reachable from that exit path.

If the connection reaches a service and returns an authentication, permission, or account message, preserve that distinction. Recheck the account used by Claude Code, the sign-in state, organization settings, subscription or API access requirements, and any current regional eligibility terms. Do not assume a network change can resolve a disabled feature, expired credential, usage limit, or policy restriction. When the message is ambiguous, compare its timestamp with the Clash log and consult the provider’s official support guidance; redact tokens and personal information before sharing diagnostic output.

For DNS-related failures, check whether the hostname resolves consistently in the environment where Claude Code runs and whether Mihomo’s DNS settings or fake-IP mode are involved. Avoid disabling DNS safeguards as a first response. Instead, use the client’s documented DNS configuration, clear relevant application caches only when appropriate, and retest from a fresh process. A browser may have cached a prior resolution, so compare a newly launched terminal and browser rather than relying on an already-open tab.

A compact comparison can help choose the next check. The table describes common clues, not definitive diagnoses: one error message can have several causes, and a successful browser request does not isolate a terminal process.

Observed result Likely area to inspect Next useful check
No matching entry in Clash Environment inheritance, unsupported proxy variables, or uncaptured traffic Launch a fresh shell and verify the configured listener or TUN capture
Entry uses the wrong policy Rule order, active profile, or current mode Read the matched rule and move a confirmed specific rule above broader rules
Connection times out through the proxy Node reachability, service availability, or exit-path restrictions Test a suitable alternative node and check the provider’s status information
Authentication or permission response Credentials, account eligibility, organization policy, or access limits Verify account state and current requirements without repeatedly changing routes
DNS or TLS error Resolver behavior, stale process state, certificate handling, or system clock Compare fresh processes and inspect the exact error before changing DNS settings

Once access works, make the configuration understandable to your future self. Record which proxy method you use, the local port, the policy group, the verified hostnames, and the date you checked the provider’s guidance. Keep the number of custom rules small and review them when the application or profile changes. If the problem returns, compare current logs against the last known-good case rather than adding more broad rules. This makes it easier to identify whether a new failure comes from an application update, a profile refresh, a changed account condition, or a degraded network path.

Some one-click VPN clients can be convenient for a single browser session, but they may provide little visibility into which terminal process is routed, and switching the whole device can disrupt internal repositories or remote-work connections. Clash takes more initial care: you need to understand the active profile, local proxy settings, and rule order. In return, its connection logs and policy groups let you inspect and adjust the route for observed traffic while keeping unrelated destinations on their intended paths. If you want that process-level visibility and flexible routing for Claude Code, you can download a Clash client and apply the checks above.

Ready to get started?

Choose a Clash client for your platform, then use the tutorial to review profiles, proxy settings, and routing basics before testing Claude Code.