Most failures are not node outages. They come from rule shadowing. ClashX matches top-down and stops at the first hit, so ordering is part of logic, not formatting.
Why rules look randomly broken
Most failures are not node outages. They come from rule shadowing. ClashX matches top-down and stops at the first hit, so ordering is part of logic, not formatting.
If broad rules like MATCH or GEOIP appear too early, specific business rules will never execute.
Each request uses only the first matched rule. Wrong ordering makes correct rules unreachable.
Typical symptoms
- Unstable routing despite healthy nodes
- Expected policy groups never hit
- Home page works but auth/media fails
- Small edits break unrelated traffic
Placing MATCH in the middle ends evaluation early. Keep it last.
Core model of rule priority
Use a funnel model: precise conditions first, fallback conditions last. Recommended order: DOMAIN โ DOMAIN-SUFFIX โ DOMAIN-KEYWORD โ IP-CIDR โ GEOIP โ MATCH.
- Exact domain rules are predictable
- Critical business domains should be explicit
- Fallback must be unique and final
| Rule type | Priority | Use case | Risk |
|---|---|---|---|
DOMAIN | 1 | Critical hosts | Maintenance cost |
DOMAIN-SUFFIX | 2 | Service family routing | Can overmatch |
DOMAIN-KEYWORD | 3 | Temporary bridge | High false positives |
IP-CIDR | 4 | Network ranges | no-resolve usage |
GEOIP | 5 | Country fallback | CDN mismatch |
MATCH | 6 | Final fallback | Must be last |
DOMAIN handles precision; GEOIP and MATCH handle broad fallback.
Funnel: business-exact rules โ service suffix rules โ keyword bridge rules โ network/geo fallback โ MATCH.
Common conflict scenarios and fixes
Case 1: internal apps routed to proxy. Usually caused by upper GEOIP,CN,DIRECT conflict or missing whitelist. Add exact internal domains first.
Case 2: streaming instability. Split API and media domains into separate rules instead of one broad keyword.
Office systems route incorrectly
Early GEOIP shadows auth callback rules.
rules:
- GEOIP,CN,DIRECT
- DOMAIN-SUFFIX,corp.example.com,DIRECT
- DOMAIN,sso.corp-auth.com,PROXY
- MATCH,PROXY
Move exact SSO/API domains before broad rules.
rules:
- DOMAIN,sso.corp-auth.com,PROXY
- DOMAIN,api.corp.example.com,DIRECT
- DOMAIN-SUFFIX,corp.example.com,DIRECT
- GEOIP,CN,DIRECT
- MATCH,PROXY
Streaming region detection fails
Single keyword rule misses auth/media domains.
rules:
- DOMAIN-KEYWORD,netflix,PROXY
- GEOIP,CN,DIRECT
- MATCH,DIRECT
Separate API/media/main domains explicitly.
rules:
- DOMAIN,api.netflix.com,PROXY_STREAM
- DOMAIN-SUFFIX,nflxvideo.net,PROXY_STREAM
- DOMAIN-SUFFIX,netflix.com,PROXY_STREAM
- GEOIP,CN,DIRECT
- MATCH,PROXY
Domestic CDN accidentally proxied
Broad keyword sends static CDN traffic through proxy.
Keep app domain proxied but force CDN suffix to DIRECT.
UDP games disconnect
Policy group does not provide stable UDP path.
Create a dedicated UDP-capable game group and route game hosts there.
Practical templates
rules:
- DOMAIN,api.example.com,ProxyA
- DOMAIN-SUFFIX,example.com,ProxyA
- DOMAIN-KEYWORD,office,DIRECT
- IP-CIDR,10.0.0.0/8,DIRECT,no-resolve
- GEOIP,CN,DIRECT
- MATCH,ProxyB
Keep hierarchy unchanged and only replace policy-group names.
Basic template
rules:
- DOMAIN,login.company.com,PROXY
- DOMAIN-SUFFIX,company.com,DIRECT
- GEOIP,CN,DIRECT
- MATCH,PROXY
Advanced template (rule-providers)
rule-providers:
direct:
type: http
behavior: classical
url: https://example.org/rules/direct.yaml
path: ./ruleset/direct.yaml
interval: 86400
rules:
- RULE-SET,direct,DIRECT
- GEOIP,CN,DIRECT
- MATCH,PROXY
Streaming-focused template
rules:
- DOMAIN-SUFFIX,netflix.com,PROXY_STREAM
- DOMAIN-SUFFIX,nflxvideo.net,PROXY_STREAM
- GEOIP,CN,DIRECT
- MATCH,PROXY
Template blocks: critical rules, scenario rules, geo fallback, final catch-all.
Modify one layer at a time, then run immediate regression checks.
5-minute troubleshooting flow
- Enable logs and reproduce one request
- Identify matched rule line
- Inspect broad rules above it
- Verify rule-set sync timestamp
- Run regression on key domains
Minute 1 reproduce, minute 2 locate hit, minute 3 inspect shadowing, minute 4 minimal fix, minute 5 regression.
tail -f ~/Library/Logs/ClashX/clashx.log
grep "api.example.com" ~/Library/Logs/ClashX/clashx.log
grep -E "MATCH|GEOIP|DOMAIN" ~/Library/Logs/ClashX/clashx.log | tail -n 50
Usually under ~/Library/Logs/ClashX/ on macOS.
Team collaboration and versioning
For multi-editor setups, split rules into layers: business whitelist, system services, geo-routing, and final fallback. Every change should include intent, impact, and rollback notes.
This structure makes incident triage fast because each layer has a clear responsibility.
config/
base.yaml
rules/
10-business.yaml
20-services.yaml
30-geo.yaml
99-fallback.yamlfeat(rule): add explicit routing for corp SSO callbacks
fix(rule): move MATCH to last line and reduce keyword shadowing
chore(ruleset): bump streaming provider to 2026-02-10
Use rule-providers for team-wide consistency and easier rollbacks.
FAQ: rule priority
Q1: What is no-resolve?
A: It prevents extra DNS resolution for IP rules, useful for LAN CIDRs.
Q2: Where should MATCH be?
A: Last line, once.
Q3: What if local rules and rule-set conflict?
A: Final order decides behavior. First hit wins.
Q4: Why does one service work partially?
A: Different subdomains hit different rules. Split by function.
Q5: DOMAIN-SUFFIX or DOMAIN-KEYWORD?
A: Prefer DOMAIN-SUFFIX; use keyword as temporary bridge.
Q6: Can GEOIP be placed early?
A: Usually no. It may shadow high-priority business rules.
Q7: When do changes apply?
A: After reload, then verify with logs.
Q8: How to avoid team conflicts?
A: Layered files, commit conventions, and order-focused review.
Q9: Should I add more and more rules?
A: Not necessarily. Keep rules minimal and explicit. Too many broad rules increase collisions.
Q10: Should every host be a DOMAIN rule?
A: No. Reserve DOMAIN for critical hosts; use suffix and provider rules for scalable maintenance.
Q11: How often should rule-providers refresh?
A: Daily is a practical default. For sensitive environments, update with release windows and rollback tags.
Q12: Can I optimize and refactor in one commit?
A: Better split changes: first behavior-safe reordering, then optimization. It simplifies incident rollback.
Appendix: priority lab (copy and test)
Use these mini experiments in a test profile to see how ordering changes behavior immediately.
Experiment 1: early MATCH
rules:
- DOMAIN,api.example.com,PROXY
- MATCH,DIRECT
- DOMAIN-SUFFIX,example.com,PROXY
DOMAIN-SUFFIX,example.com,PROXY never runs because MATCH terminates evaluation first.
Experiment 2: keyword overreach
rules:
- DOMAIN-KEYWORD,cdn,PROXY
- DOMAIN-SUFFIX,assets.example.cn,DIRECT
- MATCH,DIRECT
Any domain containing cdn is captured early, so the specific DIRECT rule below is shadowed.
Experiment 3: explicit auth host first
rules:
- DOMAIN,auth.example.com,PROXY
- DOMAIN-SUFFIX,example.com,DIRECT
- GEOIP,CN,DIRECT
- MATCH,PROXY
With explicit auth host first, login and business traffic can be routed independently and remain deterministic.
Experiment 4: GEOIP placed too early
rules:
- GEOIP,CN,DIRECT
- DOMAIN,api.global-service.com,PROXY
- MATCH,PROXY
Requests resolved into CN IP space can be routed DIRECT before the explicit domain rule is reached.
Experiment 5: split media and API domains
rules:
- DOMAIN,api.stream.example,PROXY_STREAM
- DOMAIN-SUFFIX,media.stream.example,PROXY_STREAM
- DOMAIN-SUFFIX,img.stream.example,DIRECT
- MATCH,PROXY
Control plane and data plane can use different routes without random behavior.
Experiment 6: explicit LAN ranges with no-resolve
rules:
- IP-CIDR,192.168.0.0/16,DIRECT,no-resolve
- IP-CIDR,10.0.0.0/8,DIRECT,no-resolve
- MATCH,PROXY
Internal network traffic stays direct and avoids unnecessary DNS lookup overhead.
Experiment 7: fallback only once
rules:
- DOMAIN,critical.example,PROXY
- MATCH,PROXY
- MATCH,DIRECT
The second MATCH is unreachable and should be removed for clarity and safety.
Summary
Stable routing starts with deterministic rule order. Node quality matters, but priority design matters first.
Before release, run three checks: critical-domain hit validation, MATCH-at-bottom validation, and small-scope regression validation.
When ordering is treated as architecture, not formatting, troubleshooting time drops dramatically.