Rule Providers: Smarter Traffic Routing for Clash

What Is a Rule Provider?

Clash's routing capability comes from its rules list: each rule describes "which policy should handle a given type of traffic." The traditional approach is to write hundreds or thousands of rules directly into the config file – for example DOMAIN-SUFFIX,google.com,PROXY or GEOIP,PRIVATE,DIRECT.

This works well when you have few rules, but as the list grows to thousands of entries the config file becomes unwieldy and keeping up with community-maintained rule updates becomes nearly impossible. Rule Provider was designed to solve exactly this problem: it lets you reference an external rule list (a local file or an online URL), which Clash periodically fetches and caches. Rules are then referenced in the rules section using the RULE-SET keyword.

With Rule Providers, your main config only needs a few dozen core rules. Complex logic like ad blocking, streaming service routing, and direct connection for local/trusted IPs is delegated to professionally maintained rule sets – keeping things lean and sustainably up to date.

Why Rule Sets Are Needed

Internet domains and IP ranges change constantly – new services and new CDN nodes appear continuously. Keeping rules up to date manually is essentially impossible. The community includes many volunteers who maintain open-source rule sets (such as those by Loyalsoldier and blackmatrix7) covering scenarios including ads, trackers, streaming services, gaming, and developer tools.

By referencing these rule sets via Rule Provider, your Clash configuration gains:

  • Automatic updates: Set an interval and Clash will periodically pull the latest rules without any manual config edits.
  • Modular management: Ad blocking, direct-connection for trusted IPs, and proxy routing each live in their own rule set – clean and easy to maintain.
  • Offline availability: Rules are cached to the path specified by path, so the last fetched version is still usable when offline.

Types and Behavior Values

Rule sets are categorized by source into two types: http (online URL, supports auto-update) and file (local file, good for custom rules). By content format (behavior), there are three options:

  • domain: A plain list of domain names, one per line, with optional wildcards. The fastest matching type; ideal for ad domains and tracker domains.
  • ipcidr: A list of IP ranges in CIDR notation, used for IP-based routing, such as direct connection for local/trusted IPs or private subnets.
  • classical: A general-purpose format that can mix complete rule syntax including DOMAIN, DOMAIN-SUFFIX, IP-CIDR, PROCESS-NAME, and more. Offers the most flexibility.

The behavior you choose must match the actual format of the rule set file, or Clash will fail to parse it and the corresponding RULE-SET rule will have no effect. Before setting the behavior, open the rule set file and confirm whether it is a domain list, an IP range list, or full rule syntax. This step looks simple but is one of the most common sources of configuration mistakes.

Configuration Example

Define rule sets in the rule-providers section of your config:

rule-providers: reject: type: http behavior: domain url: "https://example.com/rules/reject.yaml" path: ./ruleset/reject.yaml interval: 86400 localcidr: type: http behavior: ipcidr url: "https://example.com/rules/localcidr.yaml" path: ./ruleset/localcidr.yaml interval: 86400 proxy: type: http behavior: classical url: "https://example.com/rules/proxy.yaml" path: ./ruleset/proxy.yaml interval: 86400

Reference them in the rules section (order matters – rules are matched top-to-bottom and stop at the first match):

rules: - RULE-SET,reject,REJECT - RULE-SET,proxy,PROXY - RULE-SET,localcidr,DIRECT - GEOIP,PRIVATE,DIRECT - MATCH,PROXY

In this example: ad domains are blocked (REJECT), domains needing a proxy go through PROXY, local/trusted IPs go DIRECT via a region-specific IP range set, private IPs also connect directly, and everything else falls back to the proxy.

Rule Ordering Best Practices

Clash matches rules from top to bottom; the first rule that matches wins and subsequent rules are not checked. Therefore:

  • Put more specific and higher-priority rules first, such as REJECT for ads and explicit DIRECT rules for specific domains.
  • Broad catch-all rules like GEOIP and MATCH belong at the bottom as fallbacks.
  • Avoid duplicate or conflicting rule sets, which can cause unexpected behavior.
  • When adding a new rule set for the first time, monitor the connection list in the dashboard to confirm traffic is routing as expected.

You can temporarily set Clash's log level to debug to inspect RULE-SET match events. If a rule set has not been updated for a long time, consider forking it and maintaining your own copy, or switching to a more actively maintained alternative – stale rules will fail to correctly route newer services.

Only use rule set URLs from trusted sources. A malicious rule set could redirect sensitive domains to the wrong policy, or introduce REJECT rules that block legitimate websites. Prefer open-source projects on GitHub with a large number of stars and an active maintenance history.

Frequently Asked Questions

Rule set update fails

Check whether the URL is accessible and whether your network requires a proxy to reach the rule set source. You can also manually download the rule set to a local file and switch to type: file.

Traffic is not routing as expected

Check the connection details in the Clash dashboard to see which rule matched. Adjust the order of entries in rules, or verify that the behavior value matches the actual format of the rule set file.

Config file is getting large

Each Rule Provider only requires a single RULE-SET line in the rules section and will not bloat the main config. The rule set content is stored in a separate cache file.

Difference from Proxy Provider

Clash also has Proxy Provider (node sets), which are used for importing nodes in bulk. Rule Provider handles routing rules. The two work together: node sets provide "which paths are available," while rule sets decide "what traffic takes which path." Proxy subscription services typically include their own nodes, so adding Rule Providers separately is the more common user scenario. Understanding this division of responsibility helps you avoid confusion when building custom configurations.

Practical Starter Combination

Beginners can start with three basic rule sets: ad blocking (reject), direct connection for local/trusted IPs (localcidr), and proxy for geo-restricted or blocked content (proxy). Add more specialized rule sets – streaming services, gaming, developer tools – as needed. Each new rule set requires only one additional RULE-SET line in rules; pay attention to ordering: blocking rules first, then direct, then proxy, with GEOIP and MATCH as the final fallbacks. Building up incrementally is much easier to troubleshoot than dumping a large collection of rule sets in all at once.

Maintenance is simple: just watch the update frequency and community reputation of your rule set sources, while the main config file can remain unchanged for long periods. That is the greatest value of Rule Providers: configure once, benefit continuously. Users who want deep routing customization can fork a community rule set, add or remove entries to match their own needs, host it at a private URL, and reference it via Rule Provider – giving them a fully personalized routing strategy.

Summary

Rule Providers upgrade rule maintenance from "manually writing long lists" to "reference + auto-update," simplifying your config while continuously benefiting from the latest community routing strategies. Match the correct behavior type to each rule set, pay attention to rule ordering, and use only trusted sources – your Clash routing will be both accurate and efficient. The recommended starting point is two rule sets – ad blocking and direct connection for local/trusted IPs – then expand gradually to streaming services, gaming, and other scenarios. As you use Clash more deeply, you will build up a rule set combination that fits your personal habits, turning Clash into a truly personalized network manager. The rule set ecosystem is active, and staying engaged with community developments will continually surface better routing solutions.

Ready to Get Started with Clash?

Download the free Clash client from Clash Official Site, import your subscription, and be up and running in minutes – available for Windows, macOS, Android, iOS, and Linux.

← Back to Blog