Custom Rule Providers & Traffic Routing Rules in ClashFX
The Problem with Static Rules
Most users start by downloading an all-in-one configuration from their proxy provider. While convenient, static rules quickly cause headaches:
- Subscription Overwrites: Every time you refresh your subscription, any custom routing rules or whitelisted domains you manually added are wiped clean.
- Bloated Configurations: Embedding tens of thousands of domain rules directly inside
config.yamlmakes the file difficult to navigate and maintain. - Stale Media Routing: Streaming services (Netflix, Disney+, Spotify, OpenAI) frequently change their CDN IP blocks and subdomains. Static lists quickly become outdated, breaking regional unlocking.
Rule-Providers solve this completely by decoupling the routing rule definitions from your primary configuration file.
What Are Rule Providers?
Rule Providers allow ClashFX (powered by the mihomo core) to download, cache, and automatically refresh modular rule lists from remote repositories (such as GitHub) or local files.
Your main config.yaml simply declares:
- Where to download the rule collection.
- How often to update it.
- Which Proxy Group should handle matching traffic.
ClashFX manages the background downloads, checks cryptographic hashes, and updates the active routing table in memory without interrupting network connections.
Rule Provider Syntax & Behaviors
A rule provider definition is placed under the top-level rule-providers: block in your YAML configuration:
rule-providers:
streaming-rules:
type: http
behavior: domain
url: "https://raw.githubusercontent.com/Loyalsoldier/clash-rules/release/media.txt"
path: ./ruleset/streaming.yaml
interval: 86400
direct-cidr:
type: http
behavior: ipcidr
url: "https://raw.githubusercontent.com/Loyalsoldier/clash-rules/release/cncidr.txt"
path: ./ruleset/cncidr.yaml
interval: 86400
custom-rules:
type: http
behavior: classical
url: "https://raw.githubusercontent.com/example/rules/main/custom.yaml"
path: ./ruleset/custom.yaml
interval: 43200
Explaining Provider Properties:
type: Usuallyhttpfor auto-updating remote rules, orfilefor local static files.behavior: Defines the parsing engine:domain: High-performance matching for domain-only lists.ipcidr: Optimized Radix tree matching for IP subnet ranges.classical: Standard Clash rule syntax allowing mixed rule types.
path: Local caching location relative to~/.config/clashfx/.interval: Update frequency in seconds (86400= 24 hours).
Common Rule Types in ClashFX
When defining individual rules or classical providers, ClashFX supports diverse matching directives:
| Rule Type | Syntax Example | Matching Criteria |
|---|---|---|
DOMAIN | DOMAIN,api.openai.com,AI-Group | Exact hostname match |
DOMAIN-SUFFIX | DOMAIN-SUFFIX,apple.com,DIRECT | Subdomains and root domain |
DOMAIN-KEYWORD | DOMAIN-KEYWORD,netflix,Media-Group | Any host containing the substring |
GEOSITE | GEOSITE,youtube,Media-Group | Mihomo’s built-in Geosite database |
IP-CIDR | IP-CIDR,192.168.1.0/24,DIRECT,no-resolve | IPv4 subnet range |
GEOIP | GEOIP,CN,DIRECT | Country-level IP database |
RULE-SET | RULE-SET,streaming-rules,Media-Group | Matches a declared Rule-Provider |
MATCH | MATCH,PROXIES | Catch-all fallback rule |
Pro Tip: Adding
,no-resolvetoIP-CIDRorGEOIPrules prevents ClashFX from prematurely performing local DNS lookups when evaluating domain names, preserving Fake-IP performance.
Complete Practical Configuration Example
Here is how to combine rule providers into a clean, modular setup within ClashFX:
mixed-port: 7890
allow-lan: false
mode: rule
log-level: info
dns:
enable: true
enhanced-mode: fake-ip
nameserver:
- 223.5.5.5
- 1.1.1.1
proxy-groups:
- name: PROXIES
type: select
proxies:
- AUTO-LOW-LATENCY
- US-Node
- JP-Node
- DIRECT
- name: MEDIA-STREAMING
type: select
proxies:
- US-Node
- SG-Node
- AUTO-LOW-LATENCY
- name: AUTO-LOW-LATENCY
type: url-test
url: http://cp.cloudflare.com/generate_204
interval: 300
proxies:
- US-Node
- JP-Node
- SG-Node
rule-providers:
reject:
type: http
behavior: domain
url: "https://raw.githubusercontent.com/Loyalsoldier/clash-rules/release/reject.txt"
path: ./ruleset/reject.yaml
interval: 86400
media:
type: http
behavior: domain
url: "https://raw.githubusercontent.com/Loyalsoldier/clash-rules/release/media.txt"
path: ./ruleset/media.yaml
interval: 86400
china-domains:
type: http
behavior: domain
url: "https://raw.githubusercontent.com/Loyalsoldier/clash-rules/release/direct.txt"
path: ./ruleset/direct.yaml
interval: 86400
rules:
# 1. Custom high-priority overrides
- DOMAIN-SUFFIX,internal.company.com,DIRECT
# 2. Ad blocking & tracking
- RULE-SET,reject,REJECT
# 3. Media & entertainment streaming
- RULE-SET,media,MEDIA-STREAMING
# 4. Domestic China traffic bypass
- RULE-SET,china-domains,DIRECT
- GEOIP,CN,DIRECT,no-resolve
# 5. Local network bypass
- IP-CIDR,127.0.0.0/8,DIRECT
- IP-CIDR,192.168.0.0/16,DIRECT
# 6. Default fallback
- MATCH,PROXIES
How to Edit and Apply in ClashFX
- Open ClashFX and click Config → Edit Current Config.
- Paste or edit your
rule-providers:andrules:blocks. - Press Cmd + S to save.
- ClashFX will immediately begin downloading any newly declared rule-provider files into
~/.config/clashfx/ruleset/. - Once downloaded, routing rules take effect dynamically without requiring an application restart.
Next Steps
- Check our Clash Meta YAML Template for ready-to-use production configurations.
- Explore the Built-in Config Editor Guide for tips on indentation and syntax shortcuts.
- Read our Troubleshooting Guide if you experience rule matching conflicts.
Get Started with ClashFX
Download and use ClashFX core features for free. Pro is in preparation with final features and pricing to be announced.
Frequently Asked Questions
No. Rule providers are cached locally as binary or plaintext databases on your Mac. ClashFX updates them asynchronously in the background without blocking connection handshakes or slowing proxy speeds.
ClashFX falls back to the locally cached version in ~/.config/clashfx/. Your existing routing logic continues functioning smoothly without interruption.
'domain' rule sets contain only domain and suffix patterns. 'ipcidr' files contain only IP subnet ranges. 'classical' supports mixed rule syntax including DOMAIN-SUFFIX, IP-CIDR, and GEOIP in a single provider file.
If you maintain your own custom configuration file in ~/.config/clashfx, subscription updates do not overwrite your rules. You can reference subscription node lists as proxy-providers while retaining your customized rule-providers.