Core Architecture
Clash (Mihomo) is a high-performance rule-based routing proxy core engine developed in Go. Understanding its architecture helps write more accurate and efficient configurations.
Architecture Overview
The Mihomo (formerly Clash.Meta) core consists of the following core subsystems working together:
mixed-portcan provide HTTP+SOCKS5 mixed port simultaneously.rules list in the config file, deciding whether each connection goes through proxy or direct connection. Supports 20+ match conditions like DOMAIN, IP-CIDR, GeoIP, PROCESS-NAME, etc., stopping upon a hit.external-controller, allowing real-time proxy node switching, traffic statistics viewing, and configuration refreshing. Compatible with Web control panels like Clash Dashboard, Yacd, MetaCubeXD.Traffic Processing Flow
From the application sending a network request to its final forwarding by Clash, it goes through the following processing chain:
198.18.x.x) to each domain. When the app initiates a connection, it carries this fake IP. Clash inbound recognizes and restores the domain name, then goes through the rule engine to match, completely preventing the real IP from being exposed to local apps, fundamentally eliminating DNS leaks.Proxy Modes
Clash supports four working modes, switched via the mode field in the config file or the client interface:
Match sequentially according to the rules list, deciding whether each connection goes through proxy or direct connection.Direct connection for domestic sites to maintain speed, automatic proxy for overseas sites, balancing speed and privacy, is the best choice for most users.
mode: ruleAll traffic (including domestic) is forwarded through the proxy server. Suitable for scenarios requiring complete exit IP consistency (like operating overseas accounts), but will cause domestic access speed to drop.
mode: globalAll traffic is sent directly without passing through any proxy, equivalent to turning off the proxy function. Usually used to troubleshoot whether the proxy itself affects the connection, or temporarily close the proxy without exiting the client.
mode: directWrite fully customized routing logic in JavaScript, accessing all attributes like requested domain, IP, port, process name, etc., achieving flexible control far beyond rule lists.
mode: script| Feature | System Proxy | TUN Mode |
|---|---|---|
| Working Layer | Application Layer (Layer 7) | Network Layer (Layer 3) |
| Coverage | Only proxy-supported apps (browsers, etc.) | All traffic (games, command line, all APPs) |
| Required Permission | Normal user permission | Needs Admin / root permission |
| Config Complexity | Simple, one-click enable in client | Needs network driver installation (automatic) |
| Recommended Scenario | Daily browser surfing | Game acceleration, Steam, Global Proxy |
DNS Mechanism
Clash has a built-in DNS resolver to prevent leaks and achieve more accurate routing through precise DNS query control:
dns: enable: true enhanced-mode: fake-ip # fake-ip | redir-host fake-ip-range: 198.18.0.1/16 listen: 0.0.0.0:1053 nameserver: - https://doh.pub/dns-query # DoH Domestic - https://dns.alidns.com/dns-query fallback: - https://1.1.1.1/dns-query # DoH Overseas Backup - tls://8.8.8.8:853 fallback-filter: geoip: true geoip-code: CN
Rules Syntax
The Clash rule system is one of its most powerful features, precisely controlling the direction of every traffic flow via YAML format.
Rules Format
Each rule consists of three parts, separated by English commas ,:
Rules are matched sequentially from top to bottom. It stops upon the first hit. If no rule is matched, the last rule is used as a MATCHfallback.
Rule Types Detailed
DOMAIN,www.google.com,PROXYDOMAIN-SUFFIX,google.com,PROXYDOMAIN-KEYWORD,googleapis,PROXYDOMAIN-REGEX,^(www\.)?google\.com$,PROXYno-resolve parameter to skip DNS resolution.IP-CIDR,192.168.0.0/16,DIRECT,no-resolveIP-CIDR6,2400:3200::/32,DIRECTGEOIP,CN,DIRECTGEOSITE,cn,DIRECTPROCESS-NAME,steam.exe,DIRECTPROCESS-PATH,/usr/bin/curl,PROXYtcp or udp。NETWORK,udp,REJECTDST-PORT,443,PROXYRULE-SET,gfw,PROXYMATCH,🚀 Node Selection🚀 Proxy Node Selection), the target policy of a rule has three built-in keywords:DIRECT— Direct connection, no proxyPROXY— Go through default proxy (equivalent to using the first node inproxies)REJECT— Reject connection (commonly used for ad filtering)
Proxy Groups
Proxy groups are the core of the Clash rule system, combining multiple nodes into logical groups with different routing behaviors:
type: selectinterval sets test interval (seconds), tolerance sets switching tolerance (ms).type: url-testtype: fallbackconsistent-hashing (fixed node for the same domain) and round-robin (round-robin) strategies.type: load-balancetype: relayComplete Config Example
Below is a complete config.yaml example including core config, proxy nodes, proxy groups, and rule list:
# ── Basic Config ────────────────────────────────────── mixed-port: 7890 # HTTP + SOCKS5 Mixed Port allow-lan: false mode: rule log-level: info external-controller: 127.0.0.1:9090 # ── DNS ────────────────────────────────────────── dns: enable: true enhanced-mode: fake-ip nameserver: - https://doh.pub/dns-query # ── Proxy Nodes ──────────────────────────────────── proxies: - name: Hong Kong 01 type: vmess server: hk1.example.com port: 443 uuid: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx alterId: 0 cipher: auto tls: true network: ws ws-opts: path: /ws headers: Host: hk1.example.com # ── Proxy Groups ────────────────────────────────────── proxy-groups: - name: 🚀 Proxy Node Selection type: select proxies: - ♻️ Auto Select - Hong Kong 01 - DIRECT - name: ♻️ Auto Select type: url-test url: https://www.gstatic.com/generate_204 interval: 300 tolerance: 50 proxies: - Hong Kong 01 # ── Rule List ──────────────────────────────────── rules: - GEOSITE,cn,DIRECT # Domestic Domain Direct - GEOIP,CN,DIRECT # Domestic IP Direct - DOMAIN-SUFFIX,local,DIRECT # LAN Direct - IP-CIDR,127.0.0.0/8,DIRECT,no-resolve - IP-CIDR,192.168.0.0/16,DIRECT,no-resolve - MATCH,🚀 Node Selection # Other Traffic via Proxy
Protocol Support List
Clash (Mihomo) natively supports 20+ mainstream proxy protocols, compatible with the vast majority of proxy subscriptions and self-built node solutions.
Supported Protocols Overview
Transport Layer Options (Transport)
Protocols like VMess, VLESS, and Trojan support overlaying multiple transport methods on top of the underlying protocol, further enhancing traffic camouflage capabilities:
Mainstream Protocols Comparison
Comprehensive comparison based on speed, anti-blocking capability, and configuration complexity to help you choose the most suitable protocol:
| Protocol | Speed | Anti-blocking | Config Difficulty | Suitable Scenarios | Recommendation |
|---|---|---|---|---|---|
| VLESS + Reality | Medium | First choice for self-built | Highly Recommended | ||
| Hysteria2 | Simple | Weak Network / High Latency | Highly Recommended | ||
| Trojan | Simple | Daily Proxy Mainstay | Recommendation | ||
| VMess + WS + TLS | Medium | CDN Relay Scenario | Recommendation | ||
| TUIC v5 | Medium | Low latency small packet | Recommendation | ||
| Shadowsocks | Minimalist | Proxy Subscription / Beginner | Common | ||
| WireGuard | Harder | Enterprise VPN / Warp | Scenario Specific |
Ready to get started?
Download the Clash client, configure the subscription according to the tutorial, and you can start using it within 5 minutes.