Clash For Developers: Git, npm, Docker & AI Tools Setup

Developer tools rarely fail for the same reason. A browser may follow the operating system proxy, Git may use its own proxy configuration, npm may inherit environment variables, Docker may run behind a daemon with a separate network namespace, and an AI coding extension may connect through the IDE process or through a helper service. Turning on Clash does not automatically make all of these tools use the same path.

A dependable developer workflow starts by separating three questions: how traffic enters Clash, which rule matches the destination, and whether the application is actually using the path you intended. Mihomo-based clients can provide a shared local proxy port and TUN mode, but TUN is not a replacement for correct rules, DNS settings, or application-specific configuration. The goal is to make ordinary development traffic predictable while keeping private services and local networks on a direct path when appropriate.

Map the developer traffic path before changing settings

Before editing YAML or changing proxy nodes, list the tools that need access and the destinations they contact. A single command such as git clone can involve a repository host, an authentication endpoint, a release server, and a large object storage domain. An npm install may contact the package registry, a tarball CDN, a security audit endpoint, and a Git repository referenced by a dependency. Docker may contact a registry endpoint, an authentication service, and several content delivery hosts. AI coding tools can use an account website, an API endpoint, telemetry services, and model or extension download servers.

This matters because rules normally match domains, IP addresses, ports, or process-related metadata. A rule for one website does not automatically cover every service owned by the same company. Likewise, allowing a main registry domain does not guarantee that every package tarball is served from that domain.

Identify which process owns the connection

On a desktop system, Git and npm usually run as local processes and can be captured by a system proxy or TUN interface. Docker is different. The Docker CLI sends requests to the Docker daemon, and the daemon may run as a Windows service, a Linux system service, a rootless user service, or a virtualized component inside Docker Desktop. Configuring a proxy for the shell does not necessarily configure the daemon.

IDE extensions also require care. Some extensions make requests from the IDE process, while others launch a separate language server or helper binary. A terminal opened inside an IDE may inherit the IDE’s environment variables, but an external terminal may not. On macOS and Linux, GUI applications launched from the desktop may not receive the same shell startup files as commands launched from a terminal.

Make a small inventory before troubleshooting:

For a first baseline, confirm that Clash itself is running and that its connection log records new traffic. Check the active mixed port rather than relying on a remembered default. A typical configuration may contain the following fields:

mixed-port: 7890
allow-lan: false
mode: rule
log-level: info
tun:
  enable: true
  stack: mixed
  auto-route: true
  strict-route: true

This is a structural example, not a universal drop-in configuration. TUN field names and supported values depend on the installed Mihomo version and client. Use the client’s generated configuration and documentation as the authority. Most importantly, do not enable LAN exposure merely to solve a local application problem. allow-lan: false is usually the safer desktop default unless other devices genuinely need to use the proxy.

Configure TUN mode as the shared capture layer

System proxy mode is convenient, but it only affects applications that honor the operating system’s proxy settings. Many command-line tools, service processes, container daemons, and language runtimes do not. TUN mode creates a virtual network interface and allows the core to intercept a broader range of traffic at the network layer. This can make Git, package managers, IDE helpers, and applications without proxy controls work through one routing policy.

TUN mode still depends on operating-system permissions and correct routing. The client may need administrator or root privileges to create the virtual interface and install routes. Some security products, VPN clients, corporate network agents, and virtualization platforms may also install competing routes. If TUN is enabled but no connections appear in the Clash log, check whether the interface started successfully and whether another network service has taken control of the default route.

Choose the TUN stack and DNS behavior deliberately

Mihomo TUN configurations commonly expose a stack choice such as system, gvisor, or mixed. The best value depends on platform support, performance, and compatibility. A mixed stack is often a practical starting point, but it should not be treated as a guaranteed solution for every driver or operating system. If applications connect intermittently, compare the client log, TUN status, and DNS behavior before changing several settings at once.

DNS is especially important for developer traffic. If the operating system resolves a domain to an unreachable address before Clash can apply the intended policy, the proxy rule may appear to be correct while the connection still fails. Fake-IP mode, redirection, and enhanced DNS modes can improve routing consistency, but they may conflict with local development domains, corporate DNS, split-horizon records, or software that expects a real address.

Keep local names and private networks explicit. Development environments often use domains such as *.test, *.local, internal service names, private registry hosts, or RFC1918 addresses. These should normally remain direct or be resolved through the appropriate internal DNS server. A broad proxy rule that captures all DNS traffic can break access to Kubernetes clusters, office services, NAS devices, and local virtual machines.

Verify TUN with small tests

Do not begin with a large image pull or a full dependency installation. First open a known external domain, then test a package registry, and finally test the actual tool. Watch the Clash connection log for the destination, matched rule, selected proxy group, and connection result. If the browser works but a TUN test does not appear in the log, the TUN interface or route is not active. If the connection appears but uses the wrong policy, the problem is in rule order or destination matching.

When disabling TUN, also confirm that the original system routes are restored. A stale virtual interface or route can make the system appear offline even after the client switch is turned off. Restarting the client is sometimes enough, but persistent route problems should be investigated at the operating-system level rather than solved by repeatedly changing proxy groups.

Route Git, npm, and Docker without mixing their settings

Once the shared capture layer is working, configure each developer tool according to its own behavior. Explicit application settings are useful for environments where TUN is unavailable, but they can create confusing double-proxy paths when both the application and TUN redirect the same connection. Choose one primary path for each tool and document it.

Git proxy configuration

Git can use HTTP or SOCKS proxy settings. For an HTTP or mixed local port, a common configuration is:

git config --global http.proxy http://127.0.0.1:7890
git config --global https.proxy http://127.0.0.1:7890

If the local port supports SOCKS5, Git may also be configured with a SOCKS URL:

git config --global http.proxy socks5h://127.0.0.1:7890
git config --global https.proxy socks5h://127.0.0.1:7890

The socks5h form asks the proxy side to resolve the hostname, which can be useful when local DNS is unreliable or blocked. Do not assume that every Git build, credential helper, or SSH transport handles proxy syntax in exactly the same way. HTTPS repository URLs use Git’s HTTP transport, while SSH repository URLs involve a separate SSH client and usually require an SSH-specific proxy command or a network-level capture such as TUN.

Inspect the effective Git settings before testing:

git config --global --get http.proxy
git config --global --get https.proxy
git ls-remote https://example.com/organization/project.git

If the repository host is reachable but cloning fails during large objects, inspect whether the repository uses a separate object storage domain. A successful authentication request does not prove that the subsequent packfile download uses the same host. Remove stale settings with git config --global --unset http.proxy or the corresponding HTTPS key when returning to a TUN-only design.

npm registry and environment variables

npm can read registry and proxy values from its configuration, environment variables, and project-level files. Check the active values instead of guessing:

npm config get registry
npm config get proxy
npm config get https-proxy
npm ping
npm view lodash version

A registry URL that responds to npm ping may still fail during installation if package tarballs are hosted elsewhere or if a dependency invokes Git, a binary downloader, or a post-install script. Keep the registry choice separate from the network path. The registry determines where package metadata and artifacts come from; Clash determines how those connections are routed.

When using TUN, avoid setting several competing proxy variables unless a specific npm version or corporate environment requires them. An old HTTP_PROXY, HTTPS_PROXY, or NO_PROXY value can override expectations. Use NO_PROXY for local registries, loopback addresses, cluster services, and internal domains that must not pass through a public proxy. Review both uppercase and lowercase forms because different libraries inspect different spellings.

Configure the Docker daemon separately

Docker failures are often misdiagnosed because the command is run in a terminal that already has proxy variables. The Docker CLI may contact the daemon through a local socket, while the daemon performs image pulls itself. Therefore, a working curl command or a successful browser request does not prove that Docker Hub, a private registry, or an image mirror is reachable from the daemon.

Docker Desktop has its own network and proxy controls. On Linux, the daemon may need a service-level proxy configuration, commonly supplied through the service manager rather than the user’s shell profile. The exact configuration method varies by distribution and Docker installation. After changing daemon proxy settings, restart the daemon and inspect its logs. Do not place credentials directly in a broadly shared configuration file if the proxy requires authentication; use the platform’s supported secret or credential mechanism.

Test the daemon path with a small image and then inspect detailed output:

docker version
docker info
docker pull hello-world

If Docker runs inside a virtual machine or WSL-based environment, there may be three separate paths: the host’s Clash TUN interface, the virtual machine’s route, and the daemon’s own proxy configuration. In that case, decide whether the daemon should reach Clash through a host gateway address or through a daemon-level proxy. A loopback address such as 127.0.0.1 inside the virtual machine refers to the virtual machine itself, not automatically to the host running Clash.

Build targeted rules for AI and development services

Broadly sending every domain through one proxy group is easy to write but difficult to maintain. A better configuration separates local traffic, private services, development platforms, package infrastructure, and a final fallback. Rules are evaluated from top to bottom, so a specific exception must appear before a broad category or final MATCH rule.

rules:
  - DOMAIN-SUFFIX,example.internal,DIRECT
  - IP-CIDR,192.168.0.0/16,DIRECT,no-resolve
  - DOMAIN-SUFFIX,github.com,Developer
  - DOMAIN-SUFFIX,githubusercontent.com,Developer
  - DOMAIN-SUFFIX,npmjs.com,Developer
  - DOMAIN-SUFFIX,npmjs.org,Developer
  - DOMAIN-SUFFIX,docker.io,Developer
  - DOMAIN-SUFFIX,ghcr.io,Developer
  - MATCH,PROXY

Replace the example policy names with groups that actually exist in the active configuration. Also add the real artifact, authentication, and API domains used by the services in your workflow. Do not copy a long domain list without checking it: service providers change infrastructure, and an overly broad suffix can route unrelated private services through an external proxy.

AI coding tools require the same disciplined approach. Identify whether the extension uses a vendor API, a company-managed gateway, an IDE account service, or a local model endpoint. A web login domain may differ from the API domain, and an extension download host may differ from both. If the tool supports an explicit HTTP proxy, compare that path with TUN capture. If it does not, TUN may be the simplest option, provided that its background helper processes are also captured.

For privacy and reliability, avoid sending local source-control servers, internal code hosts, private package registries, or self-hosted model endpoints to a general proxy group. Put those destinations in direct or internal rules first. This is not only a performance decision; it reduces the chance of exposing source code metadata, credentials, package names, or API traffic to an unintended intermediary.

Debug timeouts with reproducible checks

When a command times out, collect evidence in a fixed order. First check whether the process created a connection in the Clash log. If there is no entry, the process is bypassing Clash, using a different network namespace, or failing before it makes a network request. If there is an entry, inspect the matched rule and proxy group. A direct connection to a blocked destination and a proxy connection to an unavailable node produce different remedies.

Next compare DNS and transport. Test the hostname, not only its resolved IP, because rules may match the domain while an IP-only test takes a different path. Check whether IPv6 is being preferred when only IPv4 is routed correctly. A package manager may also open several parallel connections, so a single successful request does not guarantee that every artifact host is reachable.

Change one variable per test: proxy group, rule, DNS mode, application proxy, or TUN state. Save the original configuration before editing and validate YAML indentation after every change. A configuration reload can fail because of a syntax error even when the previous runtime remains active, making it appear that a new rule has no effect.

Developer proxy FAQ

Is TUN mode better than HTTP proxy variables?

Neither is universally better. TUN covers applications and services that ignore proxy variables, while explicit variables are easier to audit and can be limited to one command or project. Use TUN as the broad capture layer when multiple tools need the same route, and use application settings when a service requires a specific protocol or must bypass the shared route. Avoid configuring both without understanding the resulting path.

Why does HTTPS cloning work but SSH cloning fail?

HTTPS cloning uses Git’s HTTP transport and can often use Git proxy settings. SSH cloning uses the SSH client, which does not automatically read Git’s HTTP proxy configuration. Configure an SSH-compatible proxy method, switch the repository URL to HTTPS, or rely on a correctly functioning TUN route. Check the SSH verbose output to confirm where the connection stops.

Why does Docker ignore my terminal proxy?

The Docker daemon normally performs registry communication. Its environment and network path can be different from the shell running the Docker CLI, especially with Docker Desktop, WSL, virtual machines, rootless mode, or a remote daemon. Configure and restart the daemon or its desktop proxy settings, then verify with docker info and a small image pull.

How should AI coding tools be routed?

Find the actual API, authentication, extension, and download domains used by the tool. Route only the required external services through the intended proxy group, keep internal endpoints direct, and verify helper-process traffic in the Clash log. Do not assume that the vendor’s main website is the same endpoint used for model requests.

Download Clash