Guide

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.yaml makes 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:

  1. Where to download the rule collection.
  2. How often to update it.
  3. 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: Usually http for auto-updating remote rules, or file for 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 TypeSyntax ExampleMatching Criteria
DOMAINDOMAIN,api.openai.com,AI-GroupExact hostname match
DOMAIN-SUFFIXDOMAIN-SUFFIX,apple.com,DIRECTSubdomains and root domain
DOMAIN-KEYWORDDOMAIN-KEYWORD,netflix,Media-GroupAny host containing the substring
GEOSITEGEOSITE,youtube,Media-GroupMihomo’s built-in Geosite database
IP-CIDRIP-CIDR,192.168.1.0/24,DIRECT,no-resolveIPv4 subnet range
GEOIPGEOIP,CN,DIRECTCountry-level IP database
RULE-SETRULE-SET,streaming-rules,Media-GroupMatches a declared Rule-Provider
MATCHMATCH,PROXIESCatch-all fallback rule

Pro Tip: Adding ,no-resolve to IP-CIDR or GEOIP rules 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

  1. Open ClashFX and click Config → Edit Current Config.
  2. Paste or edit your rule-providers: and rules: blocks.
  3. Press Cmd + S to save.
  4. ClashFX will immediately begin downloading any newly declared rule-provider files into ~/.config/clashfx/ruleset/.
  5. Once downloaded, routing rules take effect dynamically without requiring an application restart.

Next Steps

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.