Clash YAML
Configuration Reference
Start with the top-level structure, then reference ports, operating modes, DNS, proxies, proxy groups, routing rules, and overrides. Examples use mihomo-compatible syntax and explain dependencies between fields and common edge cases.
User Guide covers the main path—installation, subscription import, proxy selection, and enabling the system proxy. This page explains why configuration is written this way and what to check when a field causes problems. First-time users should complete the quick start before consulting this reference for a specific issue. To switch clients, visit the Download Center to verify the platform and architecture; Clash Plus is the recommended graphical client.
Configuration files follow YAML indentation rules. Server domains, passwords, and tokens in these examples are intentionally demonstrative; replace them with your own valid values before use. Keep the original file before editing, then validate or reload immediately after changing one section. Do not modify several unrelated modules at once.
YAML structure and indentation
Understand the load order through the top-level keys
A working Clash configuration usually includes general settings, DNS, proxies, proxy providers, proxy groups, rule providers, and a rule list. All of these live at the YAML top level and reference one another by name. When the core reads the file, it parses the YAML first, builds proxies and groups, and then checks whether rule targets exist. The order usually does not affect parsing, but arranging sections as “general settings, DNS, proxies, proxy groups, rules” makes manual review easier and reduces confusion when an object is referenced before it is defined.
A minimal configuration does not mean having only one port. If rule mode is enabled, you also need usable policy targets and a final catch-all rule; if a proxy group references a proxy name, that proxy must exist; if a rule uses RULE-SET, the corresponding rule-providers entry must exist. Subscription generators often fill in these modules, but a hand-written configuration must keep every reference resolvable. Names are case-sensitive. Chinese characters, spaces, and symbols are allowed, but keep them stable so override scripts can match them reliably.
mixed-port: 7890
allow-lan: false
mode: rule
log-level: info
ipv6: false
dns:
enable: true
enhanced-mode: fake-ip
nameserver:
- https://dns.example/dns-query
proxies:
- name: "Demo Proxy"
type: ss
server: proxy.example.com
port: 443
cipher: aes-128-gcm
password: "your-password"
proxy-groups:
- name: "Proxy Selection"
type: select
proxies:
- "Demo Proxy"
- DIRECT
rules:
- DOMAIN-SUFFIX,example.com,Proxy Selection
- MATCH,DIRECT
Indentation, lists, and data types
YAML uses spaces to express hierarchy. Two spaces per level is recommended; do not mix tabs into indentation. Keys at the same level must align, and list items begin with a hyphen and a space. In the example above, dns is a mapping, nameserver is a list, and proxies is a list of node mappings. One extra space can move a field into the wrong object, while a missing hyphen can turn a list into an ordinary string. If the editor can display whitespace, enable that feature while troubleshooting.
Write Boolean values as true or false, and ports as unquoted integers. Proxy names, policy names, and passwords should be wrapped in double quotes, especially when they contain colons, hashes, commas, asterisks, leading or trailing spaces, or words that resemble Boolean values. A hash starts a comment; an unquoted password containing one will be truncated at that point. Quote numeric-only passwords as well to prevent leading-zero handling. Do not casually write empty values as empty strings; remove optional fields you do not need.
Quotes, anchors, and duplicate keys
Double quotes process backslash escapes, while single quotes largely preserve their contents. Double quotes are the clearest choice for ordinary names; regular expressions, Windows paths, and strings containing many backslashes require careful escape checking. YAML anchors can reuse a mapping, but preprocessing may change anchor behavior between clients. For subscription files shared across clients, prefer complete fields over complex anchors and merge keys.
Duplicate keys in the same mapping are dangerous. For example, if dns appears twice at the top level, some parsers keep the latter value while others fail outright; the result is not portable. A common subscription-override failure is appending a new module at the end without removing the original. During validation, search for duplicate top-level keys and inspect the final generated runtime configuration rather than the override fragment alone.
Configuration files usually use the .yaml or .yml extension; both have the same syntax. UTF-8 is recommended to prevent non-ASCII proxy-group names from becoming garbled across systems. Clients generally handle line endings, but files edited on Windows and run by a Linux service should still be checked for invisible control characters. Make sure the file parses as YAML before investigating connectivity or rule matching; parsing is the first gate in troubleshooting.
General fields: ports, mode, and the control interface
How listening ports are assigned
port provides an HTTP proxy listener, socks-port provides a SOCKS5 listener, and mixed-port accepts both HTTP and SOCKS5 on one port. Desktop graphical clients usually need only one mixed-port, which the system proxy can target automatically. If another application specifically requires a SOCKS5 endpoint, configure socks-port separately. Listening ports must not share a port number or conflict with other services on the system.
redir-port and tproxy-port are mainly for Linux gateways, routers, and transparent-proxy rules. Desktop users should not enable them casually just to “cover more traffic.” TUN mode uses a separate virtual network interface and routing path; it is not simply another listening port. To compare the two interception mechanisms, read TUN Mode vs. the System Proxy, identify where traffic enters the core, and then choose the relevant fields.
mixed-port: 7890
allow-lan: false
bind-address: "*"
mode: rule
log-level: info
ipv6: false
external-controller: 127.0.0.1:9090
secret: "your-controller-secret"
profile:
store-selected: true
store-fake-ip: true
| Field | Purpose | Common setting | What to check |
|---|---|---|---|
mixed-port |
Accept HTTP and SOCKS5 requests on one port | Keep one local port for desktop clients | Make sure no other process is using it |
allow-lan |
Allow devices on the local network to connect | Set to false for local-only use | Check the firewall after enabling it |
bind-address |
Restrict the listening address | Use it when sharing access on the local network | Do not confuse the control interface with a proxy port |
mode |
Choose rule, global, or direct handling | rule is typical for everyday use | The client interface may override the file value |
LAN access and bind addresses
allow-lan determines whether other devices can connect through this device’s proxy ports. Set it to false for single-device use; after setting it to true, also check the operating-system firewall, listening address, and LAN isolation settings. Allowing LAN access does not automatically configure a phone or TV to use the proxy: enter the LAN address of the device running Clash and its listening port on the target device. Address changes will break connections, so assign the host a stable LAN address for long-term sharing.
bind-address limits the interfaces on which the service listens. Some clients generate this field from an “allow LAN connections” switch, so the file value may be overridden at startup by the UI. During troubleshooting, inspect the actual listening address: if it listens only on 127.0.0.1, other devices cannot connect; if it listens on all interfaces, ensure the control interface and proxy ports are not exposed to untrusted networks. Proxy listeners and the external control interface are separate services and should not be confused.
Mode, logging, and state persistence
mode: rule matches rules from top to bottom and is the basis of everyday configurations. global sends traffic to the global policy and is useful for temporarily checking whether a proxy works; direct connects without a proxy and helps determine whether the proxy path is the cause. Graphical clients usually switch modes at runtime, without necessarily writing the state back to the original subscription. Do not inspect only the file’s mode; check the current client UI as well.
log-level is commonly set to info. Temporarily raise it to debug while troubleshooting, then restore it to avoid excessive logs obscuring the diagnosis. ipv6 controls whether the core handles IPv6 capabilities, but it cannot fix a local network that lacks an IPv6 route. If connections hang after enabling it, check whether DNS returns IPv6 addresses, whether the system has usable IPv6 egress, and whether rules cover those addresses.
external-controller provides the control address used by the UI to communicate with the core and is normally bound to the local loopback address. secret authenticates access to the control interface; replace the example value. It is not a proxy-node password and is not used for remote connections. profile.store-selected saves proxy-group selections, while profile.store-fake-ip saves Fake-IP mappings. If selections reset after a subscription update, also check the client’s own persistence settings instead of editing YAML alone.
DNS configuration: resolution paths and Fake-IP
First identify what is making the DNS request
DNS configuration determines how domains become addresses and affects whether rules can identify them at the right stage. A browser may use the system DNS, secure DNS, or its own cache; the operating system may retain old results; and TUN mode may send more DNS requests to the core. When a proxy works but a website does not open, do not immediately replace every proxy. First confirm whether the request enters Clash DNS, whether the result is reachable, and which policy the rules ultimately select.
dns.enable turns on the built-in DNS module. listen specifies the DNS service’s listening address and is usually managed by graphical clients; understand the firewall implications before exposing it to the LAN manually. nameserver contains the primary resolvers and can hold ordinary addresses or DoH URLs. Avoid adding resolvers indiscriminately, because differing responses make troubleshooting harder.
dns:
enable: true
ipv6: false
enhanced-mode: fake-ip
fake-ip-range: 198.18.0.1/16
use-hosts: true
respect-rules: true
default-nameserver:
- 223.5.5.5
- 1.1.1.1
nameserver:
- https://dns.example/dns-query
proxy-server-nameserver:
- https://resolver.example/dns-query
direct-nameserver:
- 223.5.5.5
fake-ip-filter:
- "*.lan"
- "*.local"
- "time.*.com"
- "+.stun.*.*"
The roles of different nameservers
default-nameserver primarily resolves the hostnames of DoH or DoT servers and can serve as a bootstrap resolver during startup. To avoid the loop of needing to resolve a resolver’s hostname before using that resolver, use directly reachable IP addresses here in most cases. It is not the default egress for every business domain, and adding many addresses is not a substitute for a correct primary DNS configuration.
nameserver handles ordinary domain queries. proxy-server-nameserver can resolve proxy-server hostnames separately, preventing node resolution from depending on a proxy connection that has not been established. It matters less when a node address is already an IP; if a hostname repeatedly fails to resolve during startup, inspect this field closely. direct-nameserver can resolve direct-connection domains and, together with rule-aware DNS routing, apply different resolution strategies to direct and proxied targets.
respect-rules makes DNS queries follow routing rules more closely, but it depends on valid policy groups and resolver settings. Invalid rule targets, unavailable proxy resolvers, or circular references may make DNS wait for a proxy before the node is usable. If all domains stop resolving after enabling it, temporarily simplify the setup: keep one reachable nameserver, disable complex routing, confirm basic resolution, and then add dedicated resolvers one at a time.
Fake-IP vs. redir-host
enhanced-mode: fake-ip returns temporary addresses from a reserved range for domains, while the core maintains a mapping from each temporary address back to its original domain. This preserves domain information early, makes rule evaluation more direct, and can prevent some applications from bypassing domain rules. Use a dedicated reserved range for fake-ip-range; do not overlap it with real LAN, corporate, or virtual-machine subnets. An address conflict may make some internal services unreachable while ordinary public websites continue to work.
redir-host returns real resolved addresses and follows a more traditional compatibility path, but transparent interception may lose the original domain earlier. Choose the mode based on application compatibility and interception method, not on the assumption that one is always faster. If a desktop client using Fake-IP has problems only with printers, LAN devices, time synchronization, or game LAN discovery, add precise entries to fake-ip-filter first instead of disabling the entire DNS module.
Domains listed in fake-ip-filter bypass Fake-IP and receive their real addresses. Keep the filter as precise as possible. A broad wildcard can remove Fake-IP handling from many domains and lead to unstable rule matches. After adding an entry, clear the client DNS cache or restart the core because old mappings may remain. The operating system and browser have separate caches and may need to be refreshed independently.
Layered DNS troubleshooting
First check whether the configuration loads. Second, check whether resolver addresses are reachable from the current network. Third, check whether the proxy server’s hostname resolves. Fourth, check the rules for the target domain. Only then inspect application caches. If logs show a timeout, distinguish between UDP DNS, establishing DoH, and connecting to the proxy node. If an address is returned but the connection fails, the issue has moved from resolution to routing, rules, or the node.
Do not change DNS, enable TUN, alter the Fake-IP range, and replace rule sets all at once. Keep a known-working baseline and change one module at a time. For a deeper, layered approach to diagnosing slower connections, see How to Troubleshoot Slow Clash Connections. DNS controls the resolution path; it cannot improve a poor remote route or replace the correct proxy and policy selection.
Proxy fields and proxy providers
The common structure of a proxy object
proxies is a static list of nodes. Each item needs at least a name, type, server address, and port, followed by protocol-specific authentication and transport fields. name is the reference identifier used throughout the configuration, and proxy groups use it to locate a node. Duplicate names make selection and override results unpredictable, so check uniqueness after merging a subscription. server may be a hostname or IP address, while port must match the service’s actual listening port.
The protocol type determines which fields are valid; do not mechanically copy parameters from one protocol to another. Encryption, user identifiers, transport, TLS, and the server name must match the server configuration. A client loading the YAML only means the syntax and basic field structure are valid, not that remote authentication will succeed. Handshake failures, authentication failures, connection refusals, and timeouts point to different stages and should be handled accordingly.
proxies:
- name: "SS Demo Proxy"
type: ss
server: ss.example.com
port: 443
cipher: aes-128-gcm
password: "your-password"
udp: true
- name: "Trojan Demo Proxy"
type: trojan
server: trojan.example.com
port: 443
password: "your-password"
sni: service.example.com
skip-cert-verify: false
udp: true
- name: "Hysteria2 Demo Proxy"
type: hysteria2
server: hy2.example.com
port: 443
password: "your-password"
sni: service.example.com
skip-cert-verify: false
Authentication, TLS, and transport fields
Common Shadowsocks fields include cipher, password, and udp. The cipher must exactly match the server; similar names are not interchangeable. Trojan-style nodes rely on TLS and often require sni in addition to a password. SNI is the server name used during the handshake. It may match the connection address or be specified separately by the provider. With an incorrect value, the TCP connection may succeed while the TLS handshake fails.
skip-cert-verify controls certificate verification. A normal configuration should keep it at false; fix the server name, system clock, and certificate chain first. Setting it to true is useful only to determine whether certificate verification is the failure point, not as a general fix. Clock drift, interception on restricted networks, and an incorrect SNI can all cause certificate errors. “Connection failed” alone is not enough; use the handshake stage shown in the logs.
VMess, VLESS, TUIC, Hysteria2, and other types may also include user identifiers, network types, WebSocket paths, HTTP headers, flow control, or congestion-control fields. The available set changes with core capabilities and server deployment. When migrating a node manually, use the original subscription and current core documentation rather than copying fields based on another node’s appearance. For naming and compatibility across the original Clash, Meta, and mihomo, read Choosing a Core Version.
On-demand loading with proxy-providers
For many nodes or remote updates, use proxy-providers. A provider is a collection of nodes, and a proxy group references it through use. Common types are HTTP and local files. Remote providers include a URL, update interval, save path, and health check. The save path must be writable by the client; container and service deployments also require the directory permissions to be checked. Query parameters in remote URLs may contain credentials and should not appear in public logs or examples.
proxy-providers:
provider-main:
type: http
url: "https://subscription.example/config?token=xxxx"
path: ./providers/provider-main.yaml
interval: 3600
health-check:
enable: true
interval: 600
url: https://www.gstatic.com/generate_204
proxy-groups:
- name: "Subscription Proxies"
type: select
use:
- provider-main
proxies:
- DIRECT
interval sets the refresh interval; it does not mean the client will always download immediately at startup. The client may also have its own update button and caching policy. health-check tests reachability through a fixed URL and uses the result for display or automatic policy selection, but one test URL cannot represent access to every website. When a test fails, first confirm that the test URL is reachable from the current network before blaming the node.
proxies and use can appear together in one proxy group: the former lists fixed nodes or built-in actions, while the latter imports provider collections. Override tools may handle these fields differently, and adding a static node does not necessarily add it to a provider. If nodes disappear after an update, check whether the remote provider refreshed successfully, whether its save path is writable, and whether the group still references the correct provider name.
Proxy groups: manual selection and automatic testing
Proxy groups form the middle layer between rules and nodes
proxy-groups combines multiple nodes, other proxy groups, and built-in actions into selectable targets. Rules usually point to a group such as “Proxy Selection,” “Streaming,” or “Downloads,” rather than to a specific node. This lets you change nodes without rewriting rules. Group names are case-sensitive too; rule targets, parent-group references, and UI labels must remain consistent.
Groups can be nested, but they must not form cycles. If A references B and B references A, validation may fail or runtime behavior may be unpredictable. Keep the hierarchy one-way: top-level service groups reference region groups, and region groups reference individual nodes. Do not let a lower-level group point back to a top-level service group. Two or three levels are usually enough; deeper hierarchies make selection harder.
proxy-groups:
- name: "Proxy Selection"
type: select
proxies:
- "Auto Select"
- "Failover"
- "SS Demo Proxy"
- DIRECT
- name: "Auto Select"
type: url-test
proxies:
- "SS Demo Proxy"
- "Trojan Demo Proxy"
url: https://www.gstatic.com/generate_204
interval: 300
tolerance: 50
lazy: true
- name: "Failover"
type: fallback
proxies:
- "SS Demo Proxy"
- "Trojan Demo Proxy"
url: https://www.gstatic.com/generate_204
interval: 300
lazy: true
select, url-test, and fallback
select is a manual selection group. The client UI displays its nodes and child policies, but it does not determine which one is fastest. It suits situations where you need a stable, explicitly chosen egress. Adding DIRECT allows a quick comparison, but accidentally selecting it makes every related rule use a direct connection. Enable state persistence for frequently used groups if you want the client to restore the previous selection after a restart.
url-test periodically visits a test URL and chooses a candidate with a relatively suitable response. It measures the connection to that URL, not the real speed of every service. interval controls the test cycle; setting it too low increases network and battery usage. tolerance reduces unnecessary switching when results are close. A value that is too small causes changes from minor fluctuations and may affect long-lived connections.
fallback prioritizes availability and candidate order. It switches through the list when the current node is unavailable, making it suitable when a fixed egress is preferred and failover should happen only when necessary. Its goal is not the same as “always choose the lowest latency.” When a service depends on a stable source address, manual selection or failover is usually more controllable than frequent speed-based switching.
load-balance and health-check boundaries
load-balance distributes connections among available nodes. Depending on core support, it may preserve consistency for the same target or rotate connections. It suits many independent connections, not services that require an entire session to keep the same egress. If login state breaks, CAPTCHAs increase, or the same service sees changing egress addresses, switch to a fixed node first rather than shortening the test interval.
Automatic policies depend on a health-check URL. It should be stable, return a small response, allow frequent requests, and not be handled specially by the local network. If every node suddenly appears to fail while normal access still works, the test URL itself may be unreachable. Conversely, a successful test proves only that one URL is reachable; it says nothing about DNS, the target website, UDP, or a particular protocol. Automatic selection is an aid, not a complete quality score.
| Policy type | Primary purpose | Best for | Common misconception |
|---|---|---|---|
select |
Manual fixed selection | Stable egress with on-demand switching | Assuming it tests speed automatically |
url-test |
Automatic selection based on test results | Everyday browsing with many candidates | Treating test latency as download speed |
fallback |
Prefer one option and switch on failure | Primary and backup routes | Ignoring list order |
load-balance |
Distribute connections across multiple nodes | Multi-connection tasks | Using it for sessions that require a fixed egress |
Keep rules maintainable with service groups
A maintainable configuration usually keeps one main entry group and a small number of service groups. Rules point to service groups, which then reference the main entry, an automatic group, or a regional group. When subscription nodes change, you only need to adjust group members. Do not create a group for every domain; the UI will fill with duplicate choices and overrides will become difficult to maintain.
After adding or renaming a proxy group, search the entire file for its old name. Rules, other groups, and override scripts may reference it. When the client reports that a policy does not exist, first check spaces, full-width punctuation, and letter case, then verify that the group was not removed by override order. If displayed latency differs greatly from actual performance, use a layered check of nodes, routes, and local settings to verify DNS, handshakes, and sustained transfer separately instead of relying on one health check.
Rule syntax, match order, and rule sets
Rules are matched from top to bottom
rules is an ordered list. Once a request matches the first applicable rule, matching stops, so specific rules must come before broad ones and MATCH should handle the remainder at the end. If MATCH is placed at the top, later rules never take effect. If a broad domain suffix comes before a special rule for one of its subdomains, that subdomain will be captured by the earlier rule.
A rule usually consists of a type, a match value, and a policy target; some rules accept additional parameters. Commas separate fields. The policy name must exist in proxy-groups, or be a built-in action such as DIRECT or REJECT. Extra spaces in a rule line may become part of a value, so keep formatting consistent when editing manually.
rules:
- DOMAIN,api.example.com,Proxy Selection
- DOMAIN-SUFFIX,example.com,Proxy Selection
- DOMAIN-KEYWORD,example,Proxy Selection
- IP-CIDR,192.168.0.0/16,DIRECT,no-resolve
- IP-CIDR6,fc00::/7,DIRECT,no-resolve
- PROCESS-NAME,example-app.exe,DIRECT
- GEOIP,CN,DIRECT
- RULE-SET,private-domain,DIRECT
- RULE-SET,service-domain,Proxy Selection
- MATCH,Proxy Selection
Domain, address, and process rules
DOMAIN matches only the complete domain and suits one host. DOMAIN-SUFFIX matches the specified domain and its subdomains, making it suitable for an entire site. DOMAIN-KEYWORD may match any domain containing the keyword, giving it the broadest scope and the highest risk of false positives. Use a complete domain whenever possible, and use a clear suffix rather than a very short fragment.
IP-CIDR and IP-CIDR6 match destination address ranges. LAN, container, and corporate networks should usually go direct, but the ranges must reflect the actual network. no-resolve prevents an extra domain lookup when trying to obtain an IP for matching. It does not block traffic that already has an IP and does not change a resolution the application has already performed.
PROCESS-NAME and process-path rules depend on platform capabilities, permissions, and the interception method. In system-proxy mode, not all traffic provides reliable process information, and mobile platforms may not support the same process rules. Cross-platform configurations should use domain and address rules as the foundation, with process rules as device-specific additions. If a rule matches on desktop but not on a phone, first check whether the rule type is portable across platforms.
GEOIP classifies addresses using an IP database, while GEOSITE and rule sets classify domain collections; availability depends on the core and its data files. Database rules conveniently cover broad targets, but their data changes on an update cycle and cannot replace explicit service rules. To force a specific domain through a policy, place its precise rule before the database rule.
Managing large rule sets with rule-providers
Large rule collections belong in rule-providers. Each provider needs a name, type, behavior, source, save path, and update interval. behavior determines the content format: domain collections, IP ranges, and classical rule lines are not interchangeable. A successful provider download does not mean it is routing traffic; you must also reference the same name with RULE-SET in rules.
rule-providers:
private-domain:
type: http
behavior: domain
format: yaml
url: "https://rules.example/private-domain.yaml"
path: ./rules/private-domain.yaml
interval: 86400
service-domain:
type: file
behavior: classical
format: yaml
path: ./rules/service-domain.yaml
rules:
- RULE-SET,private-domain,DIRECT
- RULE-SET,service-domain,Proxy Selection
- MATCH,Proxy Selection
The domain behavior is for domain or domain-suffix collections, ipcidr is for address ranges, and classical accepts traditional rule expressions. The remote content must match the declared format. If the provider file already contains a complete payload structure, the core reads it in that format after saving. Treating an ordinary subscription file as a rule set causes a parsing error.
When a rule-set refresh fails, check the network request first, then the save-directory permissions and file format. An old cache may continue to work, so current access does not prove that the update succeeded. In service mode, relative paths are based on the working directory or client configuration directory, not necessarily the directory containing the YAML file. After moving to another device, path differences are a frequent cause of failed rule providers.
Verify rule matches instead of guessing from outcomes
Connection logs usually show the destination domain, matched rule, and final policy. Before testing, clear existing browser connections or make a new request; a reused connection may continue using the old policy. Reload the configuration after changing rules, then check whether a new connection matches the new rule. A page opening alone cannot tell you whether it used a direct or proxied connection.
Start custom rules with a few precise entries. Add one clear domain rule, confirm the match, and then expand to a suffix or rule set. If a new rule breaks many websites, immediately check for an overly short keyword, an overly broad address range, or an early MATCH. Effective routing depends not on rule count but on clear order, existing targets, and explainable scope.
Subscription overrides, YAML merging, and update boundaries
The original subscription and runtime configuration are different files
After a graphical client imports a subscription, it usually downloads, parses, applies overrides, injects client settings, and loads the result into the core. The subscription shown in the UI may be the original file or a processed cache; the configuration actually running may also contain ports, the control interface, and TUN settings written automatically by the client. When troubleshooting overrides, identify which stage’s file you are viewing.
A subscription update downloads the remote content again. Edits made directly to a cache file may disappear at the next update; that is expected and does not mean the client failed to save them. Put local rules, groups, or DNS settings that must persist into the client’s supported override, extension-script, or local-configuration layer. Override capabilities and field names differ between clients, so export and compare the final configuration before migrating.
How mappings, lists, and scalars merge
YAML defines data structures but does not prescribe one universal deep-merge algorithm for subscription tools. Scalar fields such as mode are usually replaced by the later value; mappings such as dns may be merged key by key or replaced entirely; lists such as rules and proxy-groups may be replaced, appended, prepended, or processed by name. Do not assume that every client uses the same algorithm.
Rule overrides are especially sensitive to order. If custom rules are appended after remote rules and the remote configuration already contains MATCH, the new rules will never match. You need prepended rules rather than ordinary appends. If a proxy group is replaced wholesale, subscription-generated node references may be lost; if a same-named group is merely appended, duplicate names may result. Confirm the merge result separately for each data type.
# Fragment from the base configuration
mode: rule
dns:
enable: true
enhanced-mode: fake-ip
rules:
- DOMAIN-SUFFIX,example.com,Proxy Selection
- MATCH,Proxy Selection
# Local rule fragment intended to be prepended
rules:
- DOMAIN,internal.example.com,DIRECT
# The merged order should look similar to this
rules:
- DOMAIN,internal.example.com,DIRECT
- DOMAIN-SUFFIX,example.com,Proxy Selection
- MATCH,Proxy Selection
Using YAML anchors safely
Anchors reduce repeated fields. For example, several automatic groups can share a test URL and interval through a common mapping and a merge key. Anchors are valid only within the same YAML document. If a remote subscription and local override are merged after parsing, the override fragment may not be able to reference an anchor from the original file. Some conversion tools expand or discard anchors, so do not base cross-file compatibility on them.
group-test-common: &group-test-common
type: url-test
url: https://www.gstatic.com/generate_204
interval: 300
tolerance: 50
proxy-groups:
- name: "Auto Select"
<<: *group-test-common
proxies:
- "SS Demo Proxy"
- "Trojan Demo Proxy"
Anchor names are used only by the YAML parser and do not become Clash configuration fields. If a client’s strict validation rejects extra top-level keys, place shared structures where the tool supports them or expand the fields directly. For cross-device transfer, the final export should ideally be a complete, expanded file that loads independently. Reducing duplication is convenient, but readability and compatibility come first.
Build an override workflow with a rollback path
For the first override, change one easy-to-verify field, such as the log level or one precise rule. Reload the configuration, inspect the final output and connection records, and confirm that the override layer took effect. Add DNS or proxy groups only in the next step. If you replace ports, DNS, groups, and rules simultaneously, you cannot tell which layer caused the failure.
Use clear names for local extensions: keep proxy-group names stable and give rule providers a prefix that will not collide with the subscription. Compare the number of top-level keys, group names, and rule order in the final configuration before and after an update. Do not compare only line counts, because changing node counts creates lots of irrelevant differences. Focus on whether local fields remain, references resolve, and there is exactly one final catch-all rule.
When moving between clients, import the original subscription into the new client first, then migrate local overrides; do not copy the entire runtime directory. Configuration management and persistence may differ between graphical clients such as Clash Plus, Clash Verge Rev, FlClash, and Clash Nyanpasu. Core compatibility does not mean their UI settings are identical. See Client Selection for how the clients differ, then get the matching platform installer from the Download Center.
Diagnosing problems after a subscription update
If the configuration will not load after an update, temporarily disable local overrides and validate the original subscription. If the original works but the overridden version fails, the problem is in the merge layer; if the original also fails, inspect the remote content, subscription status, or core compatibility. If the file loads but groups are empty, check provider names and filters. If custom rules disappear, determine whether the override replaces or appends. If the port returns to its default, check whether client settings take precedence over file fields.
Keep the most recent working final configuration so you can quickly distinguish an upstream subscription change from a local edit. After rolling back, do not immediately overwrite everything again; restore modules starting with the smallest difference. For general installation and subscription-import guidance, see Cross-Platform Setup and Common Errors.
Configuration validation, loading, and layered troubleshooting
Validate syntax before checking the network
Handle configuration problems in a fixed order: file encoding and YAML syntax, field structure and references, listening ports, DNS, node connections, proxy groups, rule matches, and application interception. Do not move to the next layer until the previous one passes. A syntax error prevents the entire configuration from loading; a node error affects one connection; a rule error may send traffic through the wrong policy. Identifying the scope prevents aimless changes to every setting.
Graphical clients usually provide a configuration check or reload button. On servers and in command-line environments, use the test options provided by the installed core, but follow the package documentation for the exact executable and arguments. The check command must point to the actual configuration directory; a wrong relative path may test another file with the same name. Even after “configuration valid,” inspect startup logs because port conflicts, directory permissions, and network connections are runtime issues.
# Example: enter the actual configuration directory, then call the current core's configuration-check option
cd /path/to/clash-config
mihomo -t -d .
# To check whether a local port is already in use, use the appropriate tool for the operating system
# Linux
ss -lntup
# Windows PowerShell
Get-NetTCPConnection -State Listen
Common locations for parsing errors
When an error includes a line number, inspect that line and the several lines above it. YAML parsers often report the error only when they can no longer continue; the real problem may be a missing quote on the previous line, a missing space after a colon, or broken list indentation. If a duplicate mapping key is reported, search for the same field at that level. If the type is wrong, check whether a list is missing a hyphen or an integer was accidentally written as an object.
Content copied from chat apps or rich text may contain full-width colons, curly quotes, non-breaking spaces, and invisible characters. The safest fix is to retype the problematic line in a plain-text editor. Chinese proxy-group names work normally, but punctuation should use standard half-width YAML separators. Comments must begin with a hash and be separated appropriately from the value.
If the configuration parses but reports a missing target, check the proxy name, provider name, proxy-group name, and rule-set name. Common causes include a group referencing a node renamed by a subscription update, a rule pointing to a group removed by an override, or a RULE-SET name that differs from the provider key. Search for the complete text inside the quotes and watch for trailing spaces or look-alike characters.
Branches for ports, the system proxy, and TUN
If the client appears to be running but an application cannot connect, first confirm that the listening port exists, then verify the system-proxy address. If mixed-port has been changed to a new value while the system proxy still points to the old one, the browser will fail immediately. If only applications that ignore the system proxy cannot be intercepted, the basic proxy path may be working; evaluate TUN instead of continuing to change the node protocol.
If enabling TUN cuts off all network access, check permissions, the virtual interface, routes, DNS interception, and conflicts with other network software. Disable TUN first and confirm that the system-proxy path works, then handle TUN separately. If access remains unavailable after closing the client, check whether the system proxy is still enabled and whether virtual-interface routes were restored. Do not enable multiple proxy clients during one test; they may compete for the system proxy, ports, and routes.
Verifying node availability and rule matches
When a node test fails, distinguish DNS resolution failure, TCP timeout, connection refusal, TLS handshake failure, and authentication failure. For resolution failures, check the node hostname and proxy-server-nameserver; for timeouts, check the network and remote address; a refusal usually means the destination port is not accepting connections; for handshake failures, check the system clock, SNI, and certificate; for authentication failures, check the password, user identifier, and protocol fields. Different errors require different fixes.
If the node test succeeds but the target website fails, inspect the matched rule and policy in the connection log. If it matched DIRECT, investigate rule order or mode. If it matched the expected node, continue with target-domain resolution, the node’s egress, and site-side restrictions. Temporarily switching to global mode can separate a rule problem from a connectivity problem, but restore rule mode afterward. Global mode working proves only that one proxy path is available, not that the original rules are correct.
| Symptom | Check first | Next step |
|---|---|---|
| Configuration will not load | Indentation, duplicate keys, and field types | Reduce it to the smallest parseable configuration |
| Client runs but the browser disconnects | Listening port and system-proxy port | Confirm that the local port is not in conflict |
| Domain fails but the IP connects | DNS listener, resolvers, and cache | Simplify DNS, then restore settings one by one |
| Global mode works but rule mode fails | Rule order and policy targets | Inspect the matched entry in the connection log |
| Local rules disappear after a subscription update | Override method and merge order | Compare the final runtime configuration |
Build the smallest working configuration
When a complex configuration is hard to diagnose, start with one port, one node, one manual proxy group, and two rules. Confirm that it loads and connects, then add DNS, automatic policies, rule providers, and TUN in sequence. Save a working copy after each layer. This is faster than guessing inside a subscription thousands of lines long and makes the fields actually supported by the client and core clear.
The node used for minimal-configuration testing must have complete, verified details, and the test domain should be stable. If the minimal configuration still fails, the issue is probably with the node, system network, permissions, or client installation rather than the rule set. Return to the User Guide to review initialization, or read Ten Questions About Subscriptions, Modes, and Connection Status. If you need to reinstall, choose the platform from the Download Center; Clash Plus is the first desktop and mobile option to check.
After troubleshooting, restore temporary debug logging, broad test rules, and certificate-verification changes to normal settings. Remove unused ports, duplicate groups, and inactive providers, and add short comments to custom sections. Long-term maintainability depends on each module having a clear responsibility, not on the number of fields. A configuration remains sustainable when you can explain why each rule exists, what each group references, and what each DNS resolver handles.
Continue from a working configuration
If the client is not installed yet, get the installer for your platform first. If installation is complete but the interface is unfamiliar, follow the quick-start flow to import a subscription, choose a policy, and verify the connection.