Configuration Reference · mihomo / YAML

Clash Configuration Reference

Installing for the first time, importing a subscription, or getting connected? Start with the Getting Started guide. If you already have a working config and want to change a port, understand routing results, or separate custom rules from a subscription, use this reference. It follows mihomo’s field behavior; interface labels and override options vary by client.

YAML Structure and Load Order

Identify the Config That’s Actually Running

A subscription URL points to remote content, a Profile is a config entry managed by the client, and config.yaml is a common filename. They don’t always correspond one-to-one. A client may keep the downloaded original, then apply local settings at startup to produce a different runtime config. When troubleshooting, first check which entry is selected in the config list, then look for the client’s config preview or logs. If a final-config view is available, trust the values shown there. Finding a new value in the downloaded original alone doesn’t mean the core has loaded it.

Here’s a minimal config that can be loaded on its own. It accepts proxy requests explicitly sent by local apps, then connects directly to the destination. It has no remote nodes, so it can help isolate issues with ports, operating mode, or subscription content. Create a separate test file alongside your current config; don’t overwrite the one in use. If another local process is already listening on the same port, choose an unused port and update the test app’s proxy settings to match.

mixed-port: 7890
allow-lan: false
mode: rule
log-level: info
rules:
  - MATCH,DIRECT

Tell Maps, Lists, and Scalar Values Apart

At the top level, a YAML file contains key-value pairs. In the example above, mode is a string, mixed-port an integer, allow-lan a Boolean, and rules a list. Proxy nodes in later sections contain multiple fields, so each list item is itself a mapping; name, type, and server for a node must be at the same indentation level. Indent with spaces, align sibling fields, and don’t use tabs. For more on the difference between installers and Profiles, see the multi-config management guide.

Quote strings when their literal value matters, especially node names that could be read as numbers or Booleans, identifiers with leading zeros, and values containing special characters. Keep integer ports and Boolean switches in the types expected by their fields. You can put comments on their own lines; when editing an address containing a fragment marker, make sure you don’t accidentally treat the rest as a comment and delete it. Don’t define dns or rules twice at the same level, either: the parser may reject the file or keep only one value. Duplicate keys don’t append to a list.

Break Errors Down into Three Stages

Stage one is parsing. If a log points to indentation, a colon, or a list marker on a particular line, inspect the lines above it too. The reported line is often just where the parser finally gave up. Stage two is core validation of the config and its references. Valid syntax can still reference a missing proxy group or pass a list to a field that expects a mapping. Stage three is runtime behavior: binding a local port, reading source files, connecting remotely, and accepting app traffic. A port conflict, failed remote authentication, or an app that never connects may not show up in a static check.

If you use the mihomo command-line build, run the checks below from the working directory where your test file is stored. The last command shows a normal startup to test listening and forwarding on its own; don’t run it alongside the client. These commands assume the executable is on your PATH. If you run them elsewhere, adjust the config-file and working-directory arguments. If you use a GUI client, start with its built-in check and make sure it uses the same core as the active config.

mihomo -t -d . -f config.yaml
mihomo -d . -f config.yaml

General Options: Local Ports and Operating Mode

Ports Determine Where Traffic Enters

mixed-port accepts both HTTP proxy and SOCKS client connections on the same local port. If you need only one type of listener, set port or socks-port instead. A mixed listener is not a remote server port, so don’t copy a node’s port value here. Seeing the client marked as running doesn’t mean your browser or terminal is using the listener. Check that the app points to the local address and correct port, and that its proxy protocol matches the listener.

OptionPurposeCheck After Editing
mixed-portMixed proxy listenerThe app points to the port the core is currently listening on.
allow-lanAllow proxy connections from your LANLeave off for local-only use.
modeTraffic handling mode after requests enter the coreUse Rule mode to test routing.
log-levelLog verbosityReturn to a normal level after troubleshooting.
mixed-port: 7890
allow-lan: false
mode: rule
log-level: info

Distinguish Ingress, Traffic Capture, and Egress

mode: rule checks rules in order and routes requests accordingly. global sends requests that enter the core to the global policy; the selected option in that policy determines which node is used. direct sends requests that enter the core directly to their destinations. All three modes affect only traffic that has reached the core: switching to Global mode doesn’t automatically route all system apps through it, and switching to Direct mode doesn’t restore system proxy settings. If rule changes seem to have no effect, check the config and the client’s home screen to see whether Global or Direct mode is still selected.

System proxy settings are provided by the OS. Some apps follow them; others use their own settings. TUN captures traffic through a virtual network interface and routing rules, requires additional permissions, and its coverage depends on the OS and client settings. You don’t need to enable both paths for an initial test. Start with an app explicitly configured to use the proxy, verify the port and rules, then test system proxy or TUN separately. To compare traffic capture, use the same destination and request each time.

Troubleshoot listener failures separately from connection failures. If the core log says an address is already in use, identify the local process using it or change the port. If an app reports a refused connection, check that the core is running and that its address and port match the app’s settings. If connection details show a record with a remote timeout, investigate the node and network. For more detail, temporarily set log-level to debug, reproduce the issue once, then switch it back. Logs may include destinations, LAN addresses, and config sources; remove that information before sharing them.

If you haven’t installed a client yet, choose your OS on the client downloads page. If Clash Plus is available for your platform, you can start there. Already installed but unsure which traffic-capture method to use? Follow the first-run setup checklist to check permissions and ports, then come back here to edit the options. An app that ignores the system proxy doesn’t by itself mean there’s a problem with your subscription, node, or rules.

DNS: Upstreams, Resolution Policies, and Fake-IP

First, Find Out What’s Answering DNS Queries

Enabling dns.enable turns on the core’s DNS module; it doesn’t mean every system query goes through it. A browser may use its own encrypted DNS, the system may send queries to a resolver supplied by the network, and TUN behavior depends on DNS capture or hijacking settings. If results aren’t what you expect, start with a test path you know goes through the core. If changing the upstream makes no difference and you still see the same old result, check the traffic path as well as caches in the app, OS, and core.

This example shows only a DNS snippet. When adding it to your main file, replace or edit the existing dns block. Public resolvers are shown to illustrate what each field does; on managed networks, use the upstreams you’re authorized to use. Don’t expose the DNS listener to your LAN just because you enabled DNS. To diagnose an active client config, keep the current upstream in place and confirm the request path before changing it, so you don’t alter two things at once.

dns:
  enable: true
  enhanced-mode: fake-ip
  fake-ip-range: 198.18.0.1/16
  default-nameserver:
    - 223.5.5.5
  nameserver:
    - https://dns.alidns.com/dns-query
  fake-ip-filter:
    - '+.local'

More Upstreams Don’t Necessarily Help

nameserver is a list of regular resolvers. Adding multiple upstreams doesn’t define a strict primary-and-backup order or assign a fixed route to each domain. If an upstream address uses a hostname, it needs a working bootstrap resolver; default-nameserver can resolve hostnames used by upstream services. proxy-server-nameserver lets you specify a resolver for proxy server hostnames. If a node’s server hostname won’t resolve, troubleshoot that chain separately rather than checking only whether a browser can resolve website domains.

nameserver-policy selects resolvers based on matching domains. It’s useful when certain domains must use a specific resolver, such as internal services on a connected corporate network. Before adding a policy, confirm the upstream is reachable on your current network, limit it to the required suffixes, and test both a matching domain and a regular one. Resolver selection and outbound routing are separate: sending a domain to a particular resolver doesn’t automatically send the resulting connection to a proxy group with the same name.

A Fake-IP Address Doesn’t Mean DNS Is Broken

In fake-ip mode, the core can return a reserved address to an app and keep a mapping to the domain. When traffic to that address reaches the core, it can use the mapping to recover the domain for routing. Seeing an address from the example range doesn’t, by itself, mean DNS returned an error. But if the app gets that address and its connection bypasses the core, the OS may treat it as a regular destination and the connection can fail. Check the query and connection paths first; don’t replace the address with a public IP copied from an old log.

fake-ip-filter lets matching domains resolve to real addresses instead of Fake-IP. Start with a narrow exception for a domain with a confirmed compatibility issue, then decide whether to expand it after testing. This doesn’t mean the corresponding connection will bypass the proxy, nor does it replace local service discovery. For a comparison, switch to redir-host while leaving the other fields unchanged. Clear relevant caches and start a new connection in each test, then compare the DNS results and matched rules.

Proxy Nodes and Proxy Providers

A Node Is a Named Outbound You Can Reference

Each item under proxies defines an outbound. name is the label referenced by rules and groups; type tells the core which protocol to use; server and port specify the server address. The name doesn’t change the protocol or location, and the port number alone doesn’t tell you which protocol is in use. Before renaming a node, find every group and rule that references the old name and update them too, or the core may fail to find the target when loading the config.

This example has mihomo connect to another local SOCKS5 service. Use it for testing only if a service is actually listening on 127.0.0.1:1080 and accepts local connections. Don’t point this outbound at mihomo’s own inbound port, or traffic will loop back to itself. The example uses a local test service with no authentication. Credentials for real subscriptions come from the service provider; don’t paste them into public docs, screenshots, or support requests.

proxies:
  - name: Local test outbound
    type: socks5
    server: 127.0.0.1
    port: 1080
    udp: false

Protocol Options, Transport Settings, and What They Actually Do

Authentication and encryption fields vary by protocol. For example, a Shadowsocks node needs the encryption method and credentials configured on the server; for TLS transports, the server name must match the certificate. If a node came from a subscription, first check its original type and whether your current core supports it. Copying a whole set of options from another protocol can leave you with unrecognized fields or a handshake failure at runtime. When troubleshooting certificate errors, check the expected name, certificate chain, and system time; disabling certificate verification isn’t a fix.

udp indicates whether the node enables the relevant forwarding capability; it doesn’t guarantee that UDP works across the entire path. The inbound method, selected policy, and remote server can all affect the result. If web pages load but voice, games, or other UDP-dependent services fail, check whether the affected connection is actually UDP, which group it entered, and which outbound it used. A single successful web request isn’t a substitute for testing the traffic that’s failing.

Manage a Separate Set of Nodes with a Provider

proxy-providers is a mapping of named sources, not another ordinary list alongside proxies. Here’s an example using a local file provider: put the node list from the previous section in providers/local.yaml, use payload as the top-level key for that list, then have a proxy group in the main config reference 本地来源 with use. Relative paths are resolved from mihomo’s working data directory, not necessarily the directory containing the YAML file you’re editing. In a GUI client, use the directory it actually passes to the core.

proxy-providers:
  Local source:
    type: file
    path: ./providers/local.yaml
    health-check:
      enable: false

proxy-groups:
  - name: Provider selection
    type: select
    use:
      - Local source

For a provider with type: http, enter its actual URL, set a unique path for the cached file, and configure interval according to the provider’s terms. The interval controls provider-content refreshes, not how often the client updates the entire Profile or runs speed tests. A URL opening in a browser doesn’t mean its response is in provider format. If it returns a full Clash config, a node share list, or a login page, identify the response type before deciding whether to import it through the client or reference it as a provider. See the subscription URL import guide for format differences.

If a group is empty, check in order whether the source has content, whether the provider file has the correct top-level structure, whether the use name matches the source, and whether the client has applied extra filters. If the group has members but one node is unavailable, go back to the node’s address and authentication. This helps distinguish a provider-wide loading failure from a single outbound issue, without rushing to delete the entire subscription.

Proxy Groups: Manual Selection, Latency Tests, and Failover

Rules Select a Group; Groups Select an Outbound

Proxy groups separate the destination selected by a rule from the individual nodes. A rule can keep pointing to a group called “Service Egress”; when the subscription changes its nodes, there’s no need to rename every rule as long as the group still exists and has usable members. A group can reference built-in outbounds, nodes, or other groups. proxies lists named objects, while use references providers; they aren’t interchangeable. When nesting groups, follow each reference through to a node. Avoid circular references and don’t put every group back into its own parent group just for convenience.

The example builds on the local test node from the previous section and assumes a defined, working Backup outbound is also available. If you’ve defined only one node, remove the reference to the backup. The test URL uses an example domain to show where the field goes; in practice, choose a stable endpoint both routes can reach that allows the probe frequency you plan to use. When adding this to the main config, edit the existing group list; don’t add a second top-level proxy-groups key.

proxy-groups:
  - name: Service egress
    type: select
    proxies:
      - Automatic selection
      - Local test outbound
      - DIRECT
  - name: Automatic selection
    type: url-test
    proxies:
      - Local test outbound
      - Backup outbound
    url: https://example.com/
    interval: 300
    tolerance: 80

Choose a Group Type for Its Purpose, Not Its Name

select is for manual comparison. Open the proxy or group view and select a member in “Service egress,” then check the change with a new connection. It won’t switch to another member just because that one has a faster test result. If your selection resets after switching Profiles, check whether the client saves selections separately for each config or whether profile.store-selected is enabled in the core. A selection that differs from the first item in the YAML list doesn’t necessarily mean the config failed to load; a previous choice may have been restored.

url-test selects an available member based on its probe results. It’s useful when availability and response time to the test URL are what matter. interval sets the test interval in seconds. tolerance is measured in milliseconds and helps avoid frequent switches over small differences; it isn’t a node timeout limit. A route responding faster to the test URL doesn’t mean it’ll be faster for every service or have more download bandwidth. To verify automatic selection, first check that several candidates can reach the same test target, then start a new connection for the service you actually use.

fallback is better suited to groups with a clear primary and backup: it prefers the first available member in list order based on the current probe, rather than always choosing the lowest latency. For example, use this type when you want to stay on the first of two routes and switch to the second only if the first becomes unavailable. Don’t casually add DIRECT to a backup group that must use a specific egress; if probes fail, that could send traffic direct against your routing intent. If direct access is needed, make its purpose explicit.

Test the Switch, Not Just One Speed-Test Number

First, confirm the members actually exist in the group view, then manually select a known-good member as a baseline. Open the connection details and note the rule, matched group, and actual outbound. After switching to an automatic group, close the old tab or end the existing connection and retry the same destination; established sessions may not move when the selection changes. If probe results differ but the service behaves the same, rule out connection reuse and app caching before shortening the test interval.

Routing Rules: Matching, Order, and Fallback

Start by Defining What the Rule Matches

In Rule mode, the core checks rules in config order and uses the first match. A typical rule contains a type, a match value, and a target; some rules also accept optional parameters. DOMAIN matches a complete domain, DOMAIN-SUFFIX matches a domain suffix, and IP-CIDR matches an IPv4 range. URL paths, query parameters, and page titles aren’t match values for these rules. To route a specific page on a site differently, you can’t just put the page URL in a DOMAIN rule.

The example puts the exact domain before the broader suffix. Service egress uses the group name from the previous section; for a direct-connection test, you can replace it with the built-in outbound DIRECT. The CIDR rule only illustrates matching connections whose actual destination falls within that IPv4 range; it doesn’t change system routing or access permissions. The example uses a reserved example domain. In practice, use the destination shown in connection details.

rules:
  - DOMAIN,docs.example.com,Service egress
  - DOMAIN-SUFFIX,example.com,DIRECT
  - IP-CIDR,192.168.0.0/16,DIRECT,no-resolve
  - MATCH,DIRECT

Why Changing Rule Order Changes the Result

If you move DOMAIN-SUFFIX,example.com,DIRECT to the first line, it will match docs.example.com first, so the exact-domain rule below it won’t run. When you have many rules, define exceptions and their scope before choosing where to insert them. Prefer narrow domains or IP ranges, followed by category rules and a fallback. MATCH needs no match value and belongs at the end; ordinary rules after it will never see requests that haven’t already matched.

IP rules and domain rules rely on different information. If a connection has only a destination hostname, the core may need to resolve it to determine whether it belongs to a CIDR range. Adding no-resolve to a rule that supports it tells the core not to resolve a hostname just to match that rule. It doesn’t prevent DNS for the entire connection or ignore a destination that’s already an IP address. When troubleshooting a request made with a domain but shown only as an IP in connection details, first find out whether the app, OS, or core resolved it, then decide whether to add a domain or IP rule.

GEOIP matches an IP’s geographic classification based on the geo data currently in use; it isn’t a substitute for precise rules for a corporate network. RULE-SET references a ruleset defined under rule-providers. Before adding one, check the source’s behavior, format, and actual contents: a domain-only list is different from a mixed-rule set. You still need to add the reference target to the rules list; defining a provider alone doesn’t route all matching traffic.

Use Connection Details to Explain an Unexpected Match

Close the existing connection, then reproduce the issue once. Break it into three questions: Did the app actually send the request to the core? What destination did the core see? Where did the first matching rule send it? Some sites use separate domains for assets, APIs, and login services, so a correct route for the main page proves only that one connection matched as expected. If the expected rule matched but the wrong node was used, check the current group selection instead of adding an even longer domain rule.

Overrides, Merging, and Post-Update Regression Checks

Keep Remote Originals Separate from Local Changes

Subscription updates usually refresh a Profile’s remote original. If you edit that original directly, the next update may replace your changes with upstream content. For long-term use, sort changes into three categories: client-managed connection settings, overrides specific to this config, and standalone local test configs. If the client already manages ports, system proxy, and TUN switches, change them in its interface. Put rules that need to persist for a particular subscription in that Profile’s supported local override, or maintain them in a separate local config.

Override features aren’t standardized mihomo fields. Some clients merge mappings, some replace fields with the same name, some can insert items at the start of a list, and others only let you edit a full copy. Before adding rules, check how the interface describes the operation and save the existing rules for comparison. If there’s no matching feature, save a local copy and move your changes there manually. The tradeoff is that the copy won’t automatically pick up new nodes from the subscription; don’t treat it as a remote Profile that still syncs.

Distinguish Mapping Merges, List Insertions, and Full Replacements

When you edit dns, a recursive mapping merge may preserve other existing child fields, while a full replacement keeps only the fields in the new block. So if you want to change one upstream, don’t assume the other DNS options will remain. The example shows how the merged result should appear in the preview. For local rules, put an exception before any regular rule that would already match it. Appending it after MATCH won’t change any traffic.

dns:
  enable: true
  enhanced-mode: fake-ip
  nameserver:
    - https://dns.alidns.com/dns-query

rules:
  - DOMAIN,docs.example.com,DIRECT
  - DOMAIN-SUFFIX,example.com,Service egress
  - MATCH,DIRECT

The Service egress group from the example must still be defined in the final config. If an update renames the group in the source, an override rule may still point to the old name and stop working even though the rule itself hasn’t changed. Don’t assume proxy groups are automatically deduplicated by name, either. Check the client preview to see whether the old group was replaced, a new one appended, or the entire list shortened. YAML anchors and aliases reuse content within a single document parse; they aren’t an update mechanism across subscriptions or files.

Run a Minimal Comparison Before and After an Update

Before updating, note the active Profile, Rule mode setting, the result for one commonly used destination, and the selected outbound. Afterward, don’t reset every switch right away. Compare the final config’s ports, rule order at the top, fallback rule, and group names first. Then start new connections to two destinations that behaved differently before and check which rule each one matches. Checking only that the home page loads can miss an overridden exception or an automatic group switching to a different outbound. If the update itself failed, check whether the client is still using an old cached config.

If the new config won’t start, switch back to a saved working config, restore connectivity, and then check the logs. If the error appears only after applying an override, disable it and compare against the same subscription original, then restore local changes one at a time. When reporting an issue, preserve field names, indentation, and references; replace sensitive values with example addresses and specify whether you’re sharing the subscription original, an override layer, or the final runtime config. Command-line users can also see Deploying mihomo on Linux to compare the config paths used by the CLI and service.

Why Aren’t My Custom Rules Working After a Successful Update?

A successful update only means the update process completed. First confirm the override is still attached to the active config, then check where its rules appear in the final list. If an exception is below a category rule or fallback that already matches it, the earlier rule wins. If the order is correct, check that the client is in Rule mode and the test app has started a new connection.