Configuration Featured Clash Beginner Guide Clash vs VPN Proxy Basics

Build Clash Rule Providers: GitHub Hosting And YAML Best Practices

November 21, 2026 Updated November 21, 2026 Approx. 12 min read

Before You Build a Rule Provider

A Clash rule provider is a separately stored collection of matching rules that your configuration can download and refresh. Instead of copying a long list of domains into the main YAML file, you keep the list in its own file, give it a name, and reference that name from the rules section. This makes a configuration easier to maintain, share, review, and update without changing the structure of your proxy groups.

Providers are especially useful when a rule list is large, changes frequently, or is used by more than one profile. For example, you might keep rules for AI services, streaming platforms, advertising domains, or internal company services in separate files. A small configuration can still benefit: separating policy from rule data makes it easier to see what the profile does and to identify which list caused an unexpected routing decision.

This guide uses Mihomo, the actively maintained Clash-compatible core used by many current clients, including Clash Verge Rev. Some older Clash cores and clients may not support every provider option shown here. Before relying on a setting such as format or a particular behavior type, confirm that the core selected by your client supports it. The client interface manages profiles; the core is what ultimately parses the YAML and applies the rules.

What You Will Build

A small YAML rule list hosted in a GitHub repository, a provider definition that downloads it, and a rule that sends matching traffic to the policy you choose.

Keep the provider focused. A file named ai-services.yaml should contain a clearly defined set of AI-related matches, not unrelated ad blocking, local network exceptions, and fallback rules. Smaller, purpose-specific lists are easier to test and safer to change. They also make it simpler to explain why a domain matches a particular policy when you review a connection in the client.

1Write a Valid and Maintainable YAML File

Create a repository on GitHub and add a file such as rules/ai-services.yaml. For a YAML provider, the file should have a top-level payload key containing a list of rule patterns. A domain-oriented provider is suitable for domain matches such as DOMAIN, DOMAIN-SUFFIX, and DOMAIN-KEYWORD. The following example uses suffix matches so that related subdomains are included without matching unrelated names that merely contain the same word.

payload: - DOMAIN-SUFFIX,openai.com - DOMAIN-SUFFIX,chatgpt.com - DOMAIN-SUFFIX,anthropic.com - DOMAIN-SUFFIX,claude.ai

Indentation is structural in YAML: use spaces, not tabs, and keep each list item aligned beneath payload. Do not put a policy such as PROXY or DIRECT at the end of a provider entry. The provider supplies match patterns; the main configuration decides what action to take when a pattern matches. This separation lets the same list be reused with different policies in different profiles.

Choose the Behavior That Fits the Data

The provider's behavior tells Mihomo how to interpret its entries. Use domain for domain match rules, ipcidr for IP network rules, and classical when the list needs a broader range of rule types, such as process-name or port matches. Do not choose classical simply because it sounds more flexible: a more specific behavior documents the data's purpose and helps catch mistakes.

For an IP CIDR list, use the corresponding IP rules and choose ipcidr. IP rules may have additional matching options, and behavior support can differ between core versions. Check the Mihomo documentation for the version you actually run before combining rule types or adding optional arguments. In particular, avoid pasting a provider written for another proxy core without checking its syntax and supported behaviors.

Keep Changes Reviewable

Use one rule per line, keep the file focused, and remove duplicate or obsolete entries. Add comments only when the provider format and core version you use support them; do not assume arbitrary comments or metadata are accepted inside every rule list. Prefer precise suffixes over broad keywords. For example, a keyword like chat could match many unrelated domains, whereas a suffix such as chatgpt.com is easier to reason about.

Before publishing a change, review it as if another person will need to understand it months later. Ask what the rule matches, whether the match is broader than intended, and whether it should be in this provider at all. If a service uses multiple documented domains, list them explicitly rather than adding a very broad keyword to compensate for incomplete testing. Keep a short repository README describing the provider's scope, owner, update process, and any known limitations.

Pro Tip: Test One Change at a Time

When a service stops routing as expected, temporarily add or remove one candidate domain, refresh the provider, and inspect the connection's matched rule. Changing several entries at once makes it much harder to identify the cause.

2Host the File and Reference It in Clash

For a public repository, GitHub's raw file endpoint is a straightforward way to serve a provider. Once the file is committed, open it on GitHub and use its raw URL. A typical URL has this form:

https://raw.githubusercontent.com/OWNER/REPOSITORY/main/rules/ai-services.yaml

Replace the owner, repository, branch, and file path with your actual values. The repository and file must be public for a configuration to fetch them without authentication. Test the URL in a private browser window or another environment where you are not signed in: it should return the raw YAML content, not a GitHub HTML page, a sign-in prompt, or a 404 response. Do not use the ordinary repository page URL as the provider URL; that page contains HTML rather than the rule file.

Add a provider entry to your main configuration under rule-providers, then reference its name in the rules section. The local path gives the core a place to cache the downloaded file. Keep it inside a directory that the client can write to and that will persist when the profile reloads. Relative paths are generally resolved in relation to the configuration or profile location, so verify the active profile's storage behavior if you use a GUI client.

rule-providers: ai-services: type: http behavior: domain url: https://raw.githubusercontent.com/OWNER/REPOSITORY/main/rules/ai-services.yaml path: ./providers/ai-services.yaml interval: 86400 format: yaml rules: - RULE-SET,ai-services,AI - MATCH,PROXY

In this example, AI must be the name of an existing policy group in your configuration. Replace it with a real group or policy, such as a group that lets you choose a node, if that better fits your setup. The provider name in RULE-SET,ai-services,AI must match the key under rule-providers exactly. YAML keys and rule references should be treated as case-sensitive for reliable configuration, even if a particular interface appears to accept variations.

Understand Update Intervals and Rule Order

The interval value is expressed in seconds. A value of 86400 requests an update about once per day; it does not mean that the provider is checked on every connection. Choose an interval based on how often the data genuinely changes. Very short intervals can cause unnecessary requests, create avoidable dependence on the host, and make troubleshooting less predictable. For a stable personal list, daily or weekly refreshes are usually more practical than frequent polling.

Rule order matters because Clash evaluates rules from top to bottom and uses the first matching rule. Put a provider before a broader rule that would otherwise catch the same traffic, such as a general domain rule or the final MATCH rule. If a domain is matched by an earlier rule, the provider may load correctly but never get a chance to decide its route. When debugging, inspect the complete rules list, not only the provider definition.

A single rule provider can be referenced more than once if you deliberately want different actions in separate parts of the rule list, but overlapping rules are easy to misunderstand. Start with one clear reference and one intended policy. If you later need exceptions, add them explicitly before the broad provider rule and document why they take precedence.

3Version Changes and Diagnose Loading Errors

Git history gives a rule provider an important advantage over an undocumented list copied into a profile: every change can be reviewed and reversed. Commit focused updates with descriptive messages, such as “Add documented service domain” or “Remove retired endpoint.” For a personal list, the main branch URL is convenient and automatically receives updates. For a shared or production configuration, consider referencing a release tag or a commit-specific URL so that an unreviewed edit cannot silently change routing for every user.

There is a trade-off. A fixed commit is reproducible, but it will not receive new rules until you update the URL. A branch URL is more convenient, but its content can change at any time. Choose deliberately, keep a record of the expected revision, and test provider changes before distributing them. If you need dependable availability, maintain a backup copy and ensure the repository is controlled by an account with appropriate access protection. Never put subscription links, credentials, private IP details, or other secrets in a public repository.

Check Whether the Provider Loaded

If the client reports a provider error or the expected traffic uses the wrong policy, work through the failure from the outside in. First open the raw URL and confirm that the response is the current YAML file. Then confirm that the repository is public, the branch and path are correct, and the filename's capitalization matches the URL. A typo in a path or branch can produce a 404 even when the repository page itself opens normally.

Next inspect the downloaded file's structure. Confirm that payload is at the top level, list items are indented consistently, and each entry is valid for the selected behavior. Look at the client's core log for details such as a failed HTTP request, a YAML parsing error, or an unsupported provider setting. These are different problems: a network failure will not be fixed by changing indentation, and a parse error will not be fixed by waiting for the next scheduled refresh.

  • HTTP or 404 error: Verify the raw URL, public access, repository name, branch, and exact path. Check whether the host is reachable from the network currently used by the client.
  • YAML parse error: Check indentation, the top-level payload key, punctuation, and whether the file contains a copied HTML error page instead of YAML.
  • Provider loaded but no match: Check the behavior type, the spelling of the domain, and whether the actual request uses another subdomain. Confirm that no earlier rule captures the traffic first.
  • Provider loaded but wrong policy: Confirm that the policy group exists, the provider name is referenced exactly, and the provider rule appears before broader matching rules.
  • Old behavior after an edit: Trigger a manual provider update in the client if available, confirm the fetch succeeds, and check the profile's cached provider file. A committed change is not necessarily downloaded immediately.

After correcting an error, refresh the provider from the client rather than repeatedly restarting the entire application. Once it reports a successful update, generate a test connection to a domain that should match and inspect the connection details or rule trace. Test a domain that should not match as well; this catches overly broad patterns. Finally, restart or reload only if the client requires it for the new profile settings to take effect.

Do Not Treat a Remote List as Automatically Safe

Anyone who can change the hosted file may influence how matching traffic is routed. Review repository permissions, protect important branches, and only reference providers you trust. A rule provider changes routing decisions; it does not make a proxy policy secure or guarantee that a destination is trustworthy.

A reliable provider is not just syntactically valid; it is understandable, scoped, and maintainable. Keep the source in version control, use a URL that returns raw content, set a reasonable refresh interval, place the reference at the correct point in the rules list, and test both matching and non-matching traffic after updates. These habits make a provider easier to share and much less likely to become a hidden source of unexpected routing.

Download Clash for Free – Get Started Now →