1 Why Claude Code CLI deserves its own routing story next to browser Claude
If you already solved Claude inside Safari or Chrome using the approaches in our Claude + Anthropic split-routing guide, you still owe yourself a fresh pass when you adopt the Claude Code CLI. Browser tabs inherit interactive caching layers, negotiated HTTP stacks, and often proxy-aware TLS libraries that behave politely with OS dialog flows. Your shell usually inherits whatever Node decided about DNS resolvers, IPv6 preference, certificate stores, and whether HTTPS_PROXY even exists—none of which magically aligns with Mihomo FakeIP strategies unless you engineer alignment deliberately.
Practically, Claude Code stitches together three stresses at once. First, package-manager throughput: installing @anthropic-ai/claude-code through npm install -g @anthropic-ai/claude-code touches registry metadata endpoints that developers routinely pin either DIRECT or through ultra-stable exits depending on geography. Second, identity planes: OAuth-like flows against Claude.ai surfaces plus console chores under *.anthropic.com often behave differently once CLIs spawn localhost callbacks or spawn subprocess browsers. Third, sustained inference loops: unlike a quick REST demonstration, terminal agents may maintain conversational context across dozens of round trips where intermittent RST storms show up as vague “retry later” sensations rather than crisp HTTP codes.
None of those stresses invalidate what you learned while tuning Codex-style pipelines—the patterns rhyme—but vendor edges diverge. Pair this article with the OpenAI Codex CLI routing guide when your workstation mixes vendors; reuse discipline around npm hygiene while swapping suffix rows for Anthropic’s observable SNIs instead of OpenAI’s.
Throughout, “Clash-compatible” refers to cores—especially Mihomo—that honor familiar rules, rule-providers, and outbound naming conventions found in mainstream GUIs such as Clash Verge Rev. Rename placeholder groups (AI, ANTHROPIC, PROXY) to whatever your subscription actually exports before pasting snippets into production YAML.
2 Phase one: npm registry installs without sabotaging Anthropic latency
Most engineers install Claude Code globally via npm: npm install -g @anthropic-ai/claude-code. Upstream docs assume modern Node—typically Node 18 or newer—which matters because TLS cipher suites and IPv6 behaviors shifted materially across Node majors. From a routing standpoint, npm first resolves registry metadata through HTTPS APIs such as registry.npmjs.org, then follows redirects toward tarball hosts whose suffixes vary by CDN rollout. Blindly copying two suffix rows from a random gist works until npm silently introduces another edge hostname after an infrastructure migration.
The conservative split-routing habit is unchanged from other CLI ecosystems: anchor DOMAIN-SUFFIX,npmjs.org and DOMAIN-SUFFIX,registry.npmjs.org near the top of your explicit domain rules, watch Mihomo connection logs during upgrade spikes, and append additional suffix rows only after you observe unexpected SNIs. Some offices mandate corporate mirrors—when your .npmrc points at artifacts.company.example, duplicate those suffix rows honestly rather than pretending npm traffic still resembles the public registry graph.
Slow installs rarely indicate Anthropic outages; they frequently expose congestion on whichever exit carries tarball bytes. If upgrades crawl while interactive Claude sessions stay crisp, consider splitting registry traffic onto DIRECT domestic uplinks while reserving overseas exits strictly for Anthropic inference edges. Conversely, if domestic npm mirrors throttle aggressively, pinning npm through the same overseas selector as Anthropic might trade fairness for simplicity—measure rather than philosophize.
npm view @anthropic-ai/claude-code version while logging connections; snapshot YAML only after you capture real hostnames rather than theoretical lists from stale README forks.
3 Phase two: Anthropic API surfaces, Claude.ai login, and console siblings
Once binaries exist locally, Claude Code expects trustworthy TLS toward Anthropic-controlled endpoints. Observed baseline families typically include api.anthropic.com for programmatic inference aligned with official SDK semantics, broader *.anthropic.com edges for documentation and console workflows, and claude.ai when interactive authentication pathways mirror consumer Claude habits. Exact subdomains evolve—batch tooling, experiments, or regional launches may introduce siblings overnight—so treat published suffix lists as scaffolding while reserving budget for incremental overrides documented from Mihomo logs.
OAuth callbacks and localhost bridges deserve explicit mental modeling: terminal flows frequently spawn privileged loops listening on loopback interfaces while exchanging tokens with remote identity endpoints. Those exchanges rarely require exotic proxy rows beyond ensuring Anthropic’s HTTPS fronts resolve consistently; however, SSH tunnels or reverse proxies layered atop localhost bridges introduce failure modes unrelated to Claude itself. When debugging token stalls, isolate whether packets leaving the workstation reach Anthropic edges without alternating exits mid-handshake rather than chasing phantom sandbox bugs first.
Enterprise SSO stacks often drag identity providers—Okta, Entra ID, Google Workspace—into the graph. Rather than widening Anthropic suffix rows blindly, carve discrete suffix entries per IdP once logs prove necessity; misrouting SSO introduces MFA friction that resembles unreachable APIs even though Mihomo technically forwarded packets somewhere polite.
4 Terminal agents, streaming retries, and proxy stickiness
Claude Code behaves closer to pair-programming companions than single-shot translators: autonomous edits, git-aware prompts, and iterative reasoning amplify sensitivity toward outbound stability. Proxy selectors that rotate exits per TCP connection may appear adequate during synthetic benchmarks yet degrade assistants expecting conversational coherence across bursts. Prefer fallback groups tuned with humane intervals or dedicate stable nodes for Anthropic suffix rows when subscription contracts permit pinning without violating acceptable-use constraints.
Idle timeouts masquerade as product regressions—coffee-shop captive portals, aggressive NATs, or VPN idle timers silently collapse idle CLI tunnels without announcing banner messages. Before rewriting YAML during midnight outages, correlate Mihomo timelines with upstream resets to distinguish routing faults from thermal Wi-Fi fantasies.
Compared with IDE-hosted assistants documented in our Cursor IDE routing guide, Claude Code inherits shell profiles verbatim; exported proxy variables behave inconsistently unless you standardize wrappers or rely on kernel-level interception via TUN. That distinction explains frustrating asymmetry where Cursor tabs thrive while sibling terminals stall—the IDE injected proxy awareness Claude Code never receives automatically.
5 Sandboxed helpers, MCP installs, and occasional Docker bursts
Certain workflows orchestrate supplementary tooling—local MCP servers, git clones, optional containers—for reproducible automation loops. Those pathways reopen npm and GitHub graphs exactly like Codex-heavy setups described in the MCP tooling routing guide. Agents amplify transient failures because retries multiply silently until operators perceive ambiguous CLI freezes rather than discrete HTTP failures.
Container-backed experiments introduce Docker Hub (registry-1.docker.io, docker.io, auth.docker.io) and GHCR (ghcr.io) pulls layered atop inference chatter. Sending multi-gigabyte layer downloads through the same congested overseas exit as latency-sensitive Anthropic streams invites starvation symptoms resembling API timeouts even though inference endpoints remain healthy. Split registry traffic carefully—often DIRECT domestically—after throughput sampling rather than ideological purity debates.
Docker Desktop’s hidden Linux VM frequently ignores host HTTP proxy exports unless daemon-level propagation exists; pairing host-level Mihomo TUN with naive container defaults yields classic “works on metal, dies inside toolbox” dichotomies. Document whichever combination survived verification so teammates inherit reproducible stacks instead of folklore spreadsheets.
6 Copy-pastable Mihomo-style DOMAIN-SUFFIX rows
Below is an intentionally conservative excerpt ordering explicit suffix rows ahead of blunt GEOIP catches. Rename AI to whichever outbound mirrors your subscription semantics (PROXY, ANTHROPIC, etc.), extend npm-related rows using observed tarball hosts, and relocate registry traffic if bandwidth experiments prove DIRECT healthier domestically.
# npm / Node installs for Claude Code CLI
- DOMAIN-SUFFIX,npmjs.org,AI
- DOMAIN-SUFFIX,registry.npmjs.org,AI
# Anthropic / Claude surfaces (validate via logs after upgrades)
- DOMAIN-SUFFIX,anthropic.com,AI
- DOMAIN-SUFFIX,claude.ai,AI
- DOMAIN,api.anthropic.com,AI
# Documentation & developer assets often ride sibling hosts—extend as observed
- DOMAIN-SUFFIX,anthropic.ai,AI
# GitHub when pulling tooling or MCP servers alongside Claude Code
- DOMAIN-SUFFIX,github.com,AI
- DOMAIN-SUFFIX,objects.githubusercontent.com,AI
# Optional container pulls for sandbox workflows (tune DIRECT vs AI after measuring)
- DOMAIN-SUFFIX,docker.io,AI
- DOMAIN-SUFFIX,registry-1.docker.io,AI
- DOMAIN-SUFFIX,auth.docker.io,AI
- DOMAIN-SUFFIX,ghcr.io,AI
Large organizations benefit from migrating volatile fragments into git-backed rule providers with descriptive filenames (“anthropic-terminal.yaml”) merged above noisy community bundles. Keep Anthropic overrides visually adjacent to npm registry rows so reviewers scanning diffs instantly recognize unified Claude Code stacks rather than archaeological merges spanning unrelated geo lists.
DOMAIN-KEYWORD shortcuts silently steer unrelated SaaS traffic through overseas exits—prefer suffix precision harvested from Mihomo histories unless you consciously accept collateral routing.
7 Coexisting with corporate VPN tunnels and Docker engines
Enterprise VPN clients routinely seize default routes while injecting opaque DNS forwards that clash with Mihomo TUN ambitions unless administrators expose thoughtful split tunnel policies. Practical coexistence demands deliberate contracts: enumerate prefixes IT mandates through VPN adapters, reserve Mihomo-owned routes for everything else, and rehearse failover sequences whenever either stack upgrades silently.
Answer explicitly whether api.anthropic.com should traverse VPN-controlled exits versus Mihomo-managed selectors—ambiguous defaults manifest first as flaky OAuth prompts before inference degrades visibly. Docker namespaces amplify uncertainty because bridged containers might bypass host resolver overrides entirely until you propagate proxies consistently across daemon configs or rely on uniform TUN capture where policy permits.
8 DNS alignment, FakeIP trade-offs, and when TUN beats shell exports
Node-powered CLIs intensify FakeIP pitfalls: Mihomo might synthesize ephemeral answers while systemd-resolved or corporate DoH clients simultaneously query unrelated resolvers, producing TLS alerts unfairly blamed on Anthropic infrastructure. Harmonize DNS stories intentionally—either Mihomo anchors recursion end-to-end with documented overrides or OS stubs synchronize without splitting hairs—or expect intermittent handshake ghosts haunting nightly automation jobs.
IPv6-first stacks exacerbate asymmetry when outbound policies silently assume IPv4-only tunnels; disabling IPv6 casually aids triage yet mature posture reconciles routing tables responsibly rather than indefinitely deferring IPv6 literacy.
TUN interception minimizes reliance on polite libraries respecting proxy variables because kernels enqueue packets before user-space debates semantics. Review our DNS leak prevention primer alongside the Clash Verge Rev TUN guide before flipping modes mid-incident—both explain FakeIP interplay beyond Anthropic-specific anecdotes.
9 Verification checklist targeted at misleading timeouts
- npm control plane: Confirm metadata downloads succeed—watch SNIs diverging from textbook suffix lists.
- Authentication surfaces: Complete interactive login flows while verifying Claude.ai and Anthropic console domains traverse consistent outbound selections.
- Anthropic API probes: Issue deliberate lightweight CLI commands mirroring Claude Code handshake patterns without destructive mutations.
- Streaming longevity: Exercise multi-turn automation loops observing Mihomo timelines for RST bursts or oscillating exits.
- Optional MCP tooling: Repeat installs once with MCP stacks disabled to localize slowdown origins.
- Optional containers: Pull trivial images comparing throughput vs host curls sharing identical selectors.
- DNS sanity: Cross-check resolver responses with Mihomo DNS toggled versus bypassed for canonical Anthropic hosts.
10 Frequently asked questions
Why does Claude Code CLI timeout while Claude in the browser works?
Browsers often follow system proxy settings and cached DNS paths that terminal Node processes skip. Claude Code CLI talks directly to Anthropic APIs and npm mirrors from your shell; missing DOMAIN-SUFFIX rows, FakeIP mismatches, or IPv6 leaks commonly produce timeouts that never appear in Safari or Chrome.
Which npm domains matter for installing Claude Code?
Start with npmjs.org and registry.npmjs.org, then extend using Mihomo logs because tarball downloads may redirect to edge nodes under additional suffixes.
Should Anthropic traffic share the same proxy group as npm?
They can share an AI-labeled outbound when latency is acceptable, but large registry pulls may deserve DIRECT or a separate group so streaming Anthropic API responses stay responsive.
Does corporate TLS inspection break Claude Code?
Yes—terminate TLS without distributing the enterprise CA and Node will reject handshakes. Import the trusted bundle via official mechanisms rather than disabling verification.
11 Wrap-up
Claude Code CLI collapses npm installs, Anthropic API chatter, Claude.ai-aligned authentication dances, and occasional MCP or Docker bursts into one terminal-shaped workload—precisely where blunt GEOIP shortcuts hurt most. Ordering explicit DOMAIN-SUFFIX rows ahead of generic MATCH rules, pairing them with disciplined DNS narratives, and rehearsing coexistence stories for VPN plus Docker stacks converts intermittent CLI timeouts into boring infrastructure telemetry instead of mystical vendor outages.
Compared with juggling disconnected remedies—a VPN tab that ignores npm mirrors, hand-edited YAML snippets without revision history, or headless proxies lacking readable logs—a maintained Mihomo profile inside a desktop client keeps npm registry throughput, Anthropic API latency, and audit trails aligned for teams onboarding new terminals weekly. That polish matters because autonomous coding assistants amplify small routing mistakes into expensive confusion faster than legacy shells ever did.
Generic VPN toggles excel at coarse region shifting yet stumble whenever developers need surgical split tunnels that honor npm throughput, Anthropic inference stability, and LAN-direct tooling simultaneously—often forcing brittle per-app overrides that rot between OS upgrades. Likewise, chasing scattered forum snippets without connecting logs to YAML breeds contradictory policies where ChatGPT-centric lists silently starve Claude-specific suffix rows. If you want one auditable stack—TUN-aware routing, Mihomo-grade cores, readable rule surfaces, and ergonomic subscription imports—the maintained builds highlighted on our download hub tend to age far more gracefully than ad hoc YAML archaeology tied to forgotten gist hashes.