1. Scope, symptoms, and the fastest way to frame the problem
This guide is for developers who already run Clash Verge Rev, Clash Verge, Mihomo, or another Clash-compatible client and can open ordinary websites, yet Gemini CLI repeatedly reports a timeout, hangs during authentication, or stops before the first model response. The important clue is that a healthy browser session does not prove that the CLI is using the same route. Chrome may follow the operating system proxy, while a terminal process may use an old HTTPS_PROXY value, connect directly, or inherit no proxy settings at all.
Treat the failure as a routing investigation rather than immediately replacing your subscription. A timeout can be caused by several different layers: the CLI may be pointing at the wrong local port, Clash may be in a mode that does not capture the process, a rule may send a Gemini hostname to DIRECT, DNS may return an unusable address, or the selected proxy node may accept the connection but fail during a long streaming request. These cases look similar from the application’s perspective, but each requires a different fix.
Start with one reproducible command and record the exact output, operating system, client version, Clash mode, and approximate time. Do not test ten configuration changes at once. Run the same command after each controlled change so you can tell whether the improvement came from a rule, an environment variable, a DNS adjustment, or a different node. If your organization restricts AI services or requires approved egress routes, follow that policy before changing any proxy configuration.
A browser success is only one probe. The useful question is: which process opened the failing socket, which local proxy did it contact, which rule matched the destination, and which remote node carried the connection?
2. Identify the CLI traffic path before editing YAML
First confirm that the command you are running is the Gemini CLI you think it is. Package managers, global Node installations, virtual environments, and IDE terminals can expose different binaries. Use the platform-appropriate command to locate it, then inspect its version:
- On macOS or Linux, use
command -v geminiandgemini --version. - On Windows PowerShell, use
Get-Command geminiandgemini --version. - Inside an IDE, repeat the check in the integrated terminal; its PATH and environment may differ from your system terminal.
Next, determine how the CLI handles HTTP and HTTPS proxy settings. Many JavaScript-based tools read standard environment variables, but support varies by release and by the underlying HTTP library. A tool can honor HTTPS_PROXY for API traffic while ignoring a lowercase variant, or it can use a custom setting instead of the shell environment. Read the current Gemini CLI documentation for the release you installed, then inspect the environment actually visible to the process.
A common Clash setup exposes an HTTP proxy on a port such as 7890 and a SOCKS5 proxy on a nearby port such as 7891. Do not copy these numbers blindly. Open the Clash client’s settings and verify the active mixed, HTTP, or SOCKS port. If the CLI expects an HTTP CONNECT proxy, point it to the HTTP or mixed port rather than assuming that a SOCKS-only port will work.
# Example only: replace 127.0.0.1 and the port with your active Clash listener
export HTTPS_PROXY=http://127.0.0.1:7890
export HTTP_PROXY=http://127.0.0.1:7890
export ALL_PROXY=http://127.0.0.1:7890
# Inspect what the current shell exposes
env | grep -i proxy
On PowerShell, the equivalent temporary variables are:
$env:HTTPS_PROXY = "http://127.0.0.1:7890"
$env:HTTP_PROXY = "http://127.0.0.1:7890"
$env:ALL_PROXY = "http://127.0.0.1:7890"
Get-ChildItem Env: | Where-Object { $_.Name -match "PROXY" }
Use temporary variables first. Persisting an incorrect proxy in your shell profile can silently break Git, package managers, cloud tools, and internal services later. When you finish testing, remove or correct the values instead of leaving several conflicting uppercase and lowercase entries behind.
3. Verify Clash mode, listener, and process visibility
Clash clients commonly expose several operating modes: Rule, Global, and Direct. For troubleshooting, Rule mode is usually the most informative because it lets you observe whether Gemini traffic matches an explicit policy. Global mode can be useful as a short diagnostic: if the CLI works only in Global mode, the node and local listener may be healthy while your rule set is incomplete. Do not treat Global mode as the final configuration if you need domestic services, corporate resources, or private registries to remain direct.
Check the client’s connection or log panel while starting one Gemini CLI request. You should see a new connection associated with a Gemini or Google API hostname. If no connection appears, the CLI is not reaching the Clash listener. The most likely causes are an incorrect port, an unsupported proxy scheme, an environment variable that was not exported, or a process launched before the variable was changed. Restart the terminal or IDE after changing inherited environment settings.
If a connection appears but is marked DIRECT, the rule engine is working exactly as configured; the problem is that the selected policy is not the one you intended. If it is sent to a proxy group but repeatedly fails, test another node in that group. If the log shows a local connection error, fix the listener or proxy protocol before spending time on remote DNS.
Avoid changing the system proxy, TUN mode, and shell variables simultaneously. A clean diagnostic sequence is:
- Confirm the Clash listener is enabled and note its exact port.
- Set a temporary HTTP proxy variable for a new terminal session.
- Run the CLI and watch Clash logs.
- Switch one proxy group member and repeat the same request.
- Only then test TUN mode if the application does not honor environment variables.
TUN is valuable when a process ignores proxy variables or opens connections through a runtime that has no proxy support. However, TUN introduces another layer: the operating system route, virtual interface, DNS handling, and Clash’s traffic sniffing all participate. Enable it only after confirming that ordinary local proxy routing cannot capture the CLI. On Windows, elevated permissions, another VPN adapter, or security software may prevent the TUN interface from behaving normally. On macOS and Linux, check for competing VPNs, custom routes, and firewall rules that intercept the same traffic.
4. Check rule matching instead of guessing a hostname list
A Gemini CLI request may involve more than one hostname. Authentication can use Google account endpoints, the model service can use a Google API hostname, and package installation or update checks may contact a separate distribution host. The exact set changes with the CLI release, login method, account type, and API workflow. Hard-coding an old forum list is therefore less reliable than observing the current traffic in Clash logs.
In Rule mode, start the CLI authentication or a minimal model request and record every failed or delayed destination. Pay attention to whether the log displays the original domain or only an IP address. If sniffing is disabled or the client cannot identify TLS hostnames, a broad IP rule may be tempting, but it can route unrelated Google services through the same group and make diagnosis harder.
Place explicit service rules above broad catch-all rules. The following is a conceptual example; adapt the policy name and domain list to your own profile:
rules:
- DOMAIN-SUFFIX,googleapis.com,Gemini
- DOMAIN-SUFFIX,googleusercontent.com,Gemini
- DOMAIN,accounts.google.com,Gemini
- DOMAIN,gemini.google.com,Gemini
- MATCH,DIRECT
This example is intentionally conservative. Do not route every Google property through a relay simply because one Gemini request failed. Google Workspace, internal identity systems, cloud consoles, and ordinary search traffic may have different privacy, latency, or compliance requirements. A narrower rule set is easier to audit and less likely to create unexpected login loops.
Rule order matters. A preceding GEOIP,CN,DIRECT, GEOSITE,cn,DIRECT, or provider-generated rule can catch a destination before your Gemini policy is evaluated. A rule provider can also change independently of your local file, so inspect the rendered rules in the active profile rather than only the YAML source. After editing, reload the configuration and confirm that the running profile—not an unused backup—is selected.
When a request fails, compare three observations: the hostname in the CLI error, the hostname shown in Clash logs, and the policy name displayed beside the connection. A mismatch is useful evidence. For example, if the CLI reports a Google API timeout but Clash shows no matching connection, the request may be bypassing the local proxy. If Clash shows the expected hostname on DIRECT, the rule needs attention. If it shows the expected proxy group and a connection reset, focus on the node, protocol, or upstream path instead of adding more domains.
5. Test DNS, IPv6, and TLS separately
DNS failures often masquerade as proxy failures. A browser may have a cached address or use its own secure DNS resolver, while the CLI relies on the operating system resolver or Clash’s fake-IP mapping. If the CLI fails immediately with a name resolution error, investigate DNS first. If it waits for a long period before reporting a timeout, compare IPv4 and IPv6 behavior, listener reachability, and the remote node as well.
Review the active Mihomo DNS settings and identify whether the profile uses fake-ip or redir-host. Fake-IP can provide consistent policy matching, but some applications do not handle synthetic addresses correctly. Authentication helpers, certificate checks, and libraries that perform their own DNS resolution may also behave differently from a browser. Temporarily testing a compatible DNS mode can help isolate the cause, but keep the change controlled and reversible.
Useful checks include resolving the relevant hostname through the system resolver, checking whether an IPv6 address is returned, and making a simple HTTPS request through the same local proxy. A successful response from a test endpoint does not prove that Gemini authentication is complete, but it confirms that the local listener can establish at least one CONNECT tunnel.
# Replace the hostname and port with values from your active profile
nslookup generativelanguage.googleapis.com
curl -v -x http://127.0.0.1:7890 https://generativelanguage.googleapis.com/
The expected HTTP status for an unauthenticated API endpoint is less important than the transport evidence. You are checking whether DNS resolves, whether the CONNECT request reaches Clash, whether TLS negotiation completes, and whether the remote side returns any response at all. A certificate error indicates a different class of problem from a connection timeout; do not “fix” certificate validation by disabling TLS verification in the CLI or profile.
If IPv6 is enabled on the operating system but the selected node or local route handles IPv6 poorly, the CLI may try an unreachable address before falling back to IPv4. Compare behavior with IPv6 temporarily disabled at the appropriate system or Clash layer, then restore it if it is not the cause. Likewise, avoid forcing a remote DNS server that is unreachable from your network. The best resolver is not automatically the most geographically distant or the most frequently recommended one; it is the resolver that gives the active routing path accurate and timely answers.
6. Distinguish a bad node from a bad configuration
Once the CLI is visibly using the intended Clash policy, test at least two or three nodes in the same group. A node can pass a quick web page check yet fail under the longer-lived TLS connection used for model streaming. Some relays have high packet loss, aggressive idle timeouts, overloaded CPU, or poor peering toward Google’s edge. These conditions produce intermittent CLI failures that are easy to misdiagnose as a rule problem.
Run the same small prompt repeatedly rather than sending a large task while testing. Record connection time, time to the first token, whether the stream stops halfway, and whether a retry succeeds on the same node. A node that consistently completes short requests but fails on long responses may have a transport or timeout limitation. A node that fails during every authentication attempt is less likely to be suffering from application load.
Keep the test fair. Do not change the CLI version, prompt, shell environment, and policy at the same time. If one node succeeds and another fails under identical conditions, retain the working node temporarily and investigate provider quality. If every node fails but a browser works, return to the local proxy variables, rule match, DNS, and runtime behavior. If both browser and CLI fail through the same policy, the issue may be upstream availability, account eligibility, or a broader network restriction rather than the CLI itself.
For teams, document a minimum operational standard for AI-related routes: successful authentication, a small completion, a multi-turn request, and a response that streams for several minutes without resetting. This is more useful than ranking nodes only by a single latency number. Also remember that proxy nodes are third-party infrastructure. Avoid sending secrets, private source code, access tokens, or regulated data while validating an unfamiliar route.
7. Common fixes and frequently asked questions
Why does Gemini work in my browser but time out in the terminal?
The browser and terminal may use different proxy paths. The browser can follow the system proxy or a browser extension, while Gemini CLI may ignore that setting and connect directly. Verify the CLI’s supported proxy mechanism, set the correct temporary environment variables, and confirm the resulting connection in Clash logs. Also repeat the test outside an IDE, because an integrated terminal can inherit a stale environment snapshot.
Should I use the HTTP port, SOCKS port, or mixed port?
Use the port and protocol supported by the CLI. An HTTP CONNECT-capable client should normally use the HTTP or mixed listener with an http:// URL. A SOCKS-aware client can use the SOCKS listener, but merely changing the port number does not convert one protocol into another. Verify the active listener in Clash instead of relying on common default values.
Do I need TUN mode for Gemini CLI?
Not necessarily. If the CLI correctly honors an HTTP or SOCKS proxy, a local listener is simpler and easier to audit. TUN mode is useful when the process ignores proxy variables, uses a runtime with limited proxy support, or launches child processes that do not inherit the shell environment. Enable it only after checking permissions, competing VPN adapters, DNS behavior, and the operating system route.
Why did my new rule not change the result?
The active profile may not be the file you edited, the configuration may not have been reloaded, or a higher rule may match first. Inspect the live rule display and connection log, then confirm the exact hostname and policy shown for the failing request. Generated rule providers can also override your assumptions, so check the rendered order rather than only the source snippet.
Some VPN clients hide rule order, process visibility, or DNS decisions behind a single connect button, which makes a browser-only success especially difficult to interpret when a CLI needs explicit proxy variables and long-lived streaming connections. Clash is more useful in this scenario because its local listeners, rule logs, selectable groups, DNS controls, and optional TUN mode let you separate those variables and keep unrelated traffic on DIRECT. If you want a client that makes this troubleshooting path visible across Windows, macOS, Linux, and Android, you can continue with the appropriate Clash-compatible download.
Ready to get started?
Choose a Clash-compatible client, verify your local listener, and troubleshoot Gemini CLI traffic with clear routing evidence.
Use visible rules, local proxy listeners, DNS controls, and TUN support to troubleshoot CLI traffic across major desktop platforms.
Free Download