Syntax
Mihomo uses yaml as the configuration file format.
yaml is case-sensitive and uses indentation to indicate hierarchical relationships. Tabs are not allowed for indentation; only spaces are permitted. The number of spaces used for indentation is not important, as long as elements at the same level are left-aligned.
Comments
Section titled “Comments”In yaml formatted files, comments start with ”#” and extend to the end of the line. The ”#” must be at the beginning of the line or preceded by a space; otherwise, it is not considered a comment.
port: 7890 # HTTP proxy portsocks-port: 7891# SOCKS proxy portObjects
Section titled “Objects”Key-value pairs in objects are represented using the colon structure key: value, with a space required after the colon. Indentation indicates hierarchical relationships.
Since the yaml format is a superset of json, you can directly use json syntax.
Multi-line
Section titled “Multi-line”tun: enable: true stack: system auto-route: true auto-detect-interface: trueMulti-line JSON
Section titled “Multi-line JSON”tun: { enable: true, stack: system, auto-route: true, auto-detect-interface: true}Single-line JSON
Section titled “Single-line JSON”tun: { enable: true, stack: system, auto-route: true, auto-detect-interface: true }Full JSON
Section titled “Full JSON”{ "tun": { "enable": true, "stack": "system", "auto-route": true, "auto-detect-interface": true }}Arrays
Section titled “Arrays”Lines starting with - indicate the formation of an array, used for multiple values within an object.
Multi-line Array
Section titled “Multi-line Array”a: - b - c - dSingle-line JSON Array
Section titled “Single-line JSON Array”a: [b, c, d]References
Section titled “References”& is used for anchors and * for aliases, allowing for references. & establishes an anchor, while << indicates merging into the current data, and * is used to reference an anchor.
In the following example, since the key p does not exist in mihomo, it will be ignored during configuration parsing.
If there are duplicate items during merging, they will not be merged.
p: &p type: http interval: 3600 health-check: enable: true url: https://www.gstatic.com/generate_204 interval: 300
proxy-providers: provider1: <<: *p url: "" path: ./proxy_providers/provider1.yaml
provider2: <<: *p type: file path: ./proxy_providers/provider2.yamlThis is equivalent to:
proxy-providers: provider1: type: http interval: 3600 health-check: enable: true url: https://www.gstatic.com/generate_204 interval: 300 url: "" path: ./proxy_providers/provider1.yaml
provider2: interval: 3600 health-check: enable: true url: https://www.gstatic.com/generate_204 interval: 300 type: file path: ./proxy_providers/provider2.yamlDomain Wildcards
Section titled “Domain Wildcards”Wildcard *
Section titled “Wildcard *”Clash’s wildcard * can only match one level of domain at a time.
*.baidu.com matches tieba.baidu.com but does not match 123.tieba.baidu.com or baidu.com.
* only matches hostnames without a . such as localhost.
Wildcard +
Section titled “Wildcard +”The wildcard + is similar to DOMAIN-SUFFIX and can match multiple levels at once.
+.baidu.com matches tieba.baidu.com, 123.tieba.baidu.com, and baidu.com.
The wildcard + can only be used for prefix matching of domain names.
Wildcard .
Section titled “Wildcard .”The wildcard . can match multiple levels at once.
.baidu.com matches tieba.baidu.com and 123.tieba.baidu.com, but does not match baidu.com.
The wildcard . can only be used for prefix matching of domain names.
Usage Example
Section titled “Usage Example”When using wildcards, you should wrap the content in quotes ' ' or " ".
fake-ip-filter:- ".lan"- "xbox.*.microsoft.com"- "+.xboxlive.com"- localhost.ptlogin2.qq.comIntroducing Domain Sets
Section titled “Introducing Domain Sets”fake-ip-filter:- "rule-set:xxx"- "geosite:xxx"Port Ranges
Section titled “Port Ranges”Mihomo can use - to match port ranges, and / or , to separate multiple ports/port ranges.
Example
Section titled “Example”Match ports 114 to 514 and 810 to 1919, as well as port 65530.
114-514/810-1919,65530