Design the ruleset before creating a provider

A custom Mihomo rule-provider is useful when you want a set of routing rules to live outside your main profile. Instead of copying a long list into every configuration, you keep the list in a GitHub repository and let Mihomo load it as a named provider. The profile then refers to that provider with a short RULE-SET rule. This separation makes changes reviewable, reusable across devices, and easier to roll back when a new entry sends traffic down the wrong path.

Think of the setup as two related but independent pieces. The provider file contains matching rules, such as domain suffixes or IP ranges. The profile declares how to fetch and interpret that file, then assigns matching traffic to a policy group such as Proxy, DIRECT, or a group of your own. A repository update does not automatically change the routing policy in the profile, and changing the profile does not edit the provider file. Keeping those responsibilities separate is the main benefit of the design.

Before writing YAML, decide what the ruleset represents and how narrow it should be. A list for development services might contain only the domains required by a specific tool. A list for local network ranges might use IP-CIDR rules. Avoid turning one provider into a miscellaneous collection of unrelated domains: focused files are easier to review, test, and disable independently. Give each provider a stable name that describes its purpose, such as developer-services, rather than a temporary name tied to a particular test or date.

Choose the provider behavior to match the syntax of the rules in the remote file. Mihomo supports behaviors such as domain, ipcidr, and classical. A domain provider is intended for domain-oriented entries; an IP-CIDR provider is for address ranges; a classical provider accepts rule lines that can include multiple rule types. Behavior is not a cosmetic label. It tells the core how to interpret and validate the payload, so a mismatch can cause the provider to fail or rules to behave differently than you expect.

ℹ️
Keep the first version small: Start with a few rules whose expected destination you can verify. A compact provider makes it much easier to distinguish a parsing problem from a rule-order or policy-group problem.

Also decide whether your source will be a plain text list or a structured YAML file. For plain text, use a format supported by your Mihomo version and declare it explicitly in the provider configuration. For YAML, a common structure is a payload list. Do not assume that a file ending in .yaml is automatically interpreted as YAML, or that every consumer accepts the same format. Keep the file format, the provider's format setting, and the provider's behavior consistent.

Create and publish a version-controlled GitHub source

Create a repository for your rules, or place the rules in a clearly named directory within an existing configuration repository. A simple layout can separate domain, address, and classical lists so that each file has one job. Use descriptive filenames, keep the default branch stable, and make changes through commits rather than editing a live copy with no history. Git history gives you a practical audit trail: you can see which rule changed, when it changed, and what the previous value was.

For a public repository, Mihomo can fetch a raw file from GitHub using its raw-content URL. A URL commonly follows this pattern: https://raw.githubusercontent.com/OWNER/REPOSITORY/BRANCH/PATH. Replace each placeholder with the repository owner, repository name, branch, and exact file path. Check the URL in a browser or with a command-line HTTP client before adding it to your profile. The response should contain the rule file itself, not a GitHub HTML page, a sign-in screen, a 404 message, or a redirect to an unrelated page.

Public raw URLs are convenient but should be treated as mutable remote inputs. Anyone who can change the source branch may change the rules Mihomo receives. Protect the repository with appropriate access controls, review pull requests, and avoid accepting rules from untrusted contributors without inspection. A private repository may require authentication that the provider fetcher cannot supply in the way a browser can; do not assume that a URL accessible while signed in will also be accessible to a client running on another device. For private data, choose a delivery method and authentication design that Mihomo actually supports, or keep the rules local.

A minimal YAML rule file for a domain provider can look like this:

payload:
  - DOMAIN-SUFFIX,example.dev
  - DOMAIN,api.example.net
  - DOMAIN-KEYWORD,code-service

Each entry should be a valid rule expression, not merely a bare hostname, unless the selected format specifically expects bare domain values. Use the narrowest rule that expresses the intent. DOMAIN targets one exact domain; DOMAIN-SUFFIX covers a domain and its subdomains; and DOMAIN-KEYWORD matches a substring and can therefore catch more hosts than its name suggests. A broad keyword can accidentally route unrelated services, so prefer explicit domains or suffixes when you know the required hostnames.

For a classical provider, the payload may contain different rule types, for example:

payload:
  - DOMAIN-SUFFIX,example.dev
  - IP-CIDR,192.0.2.0/24,no-resolve
  - PROCESS-NAME,example-app

Use only rule types supported by the Mihomo core version you deploy. A rule that parses on a newer desktop core may not work on an older device. If you share one ruleset across several clients, define a minimum core capability for the team and test upgrades before relying on newer matchers. Keep comments and surrounding documentation in the repository if they help reviewers, but do not assume arbitrary comments or metadata belong inside every accepted rule-file format.

Once the file is committed, inspect the raw response and confirm that it is stable at the intended path. A typo in capitalization or a moved directory is enough to turn a working provider into an unavailable one. When changing the branch name or file location, update the profile URL in the same reviewed change. If you want a change to roll out only after validation, consider publishing it to a staging branch or test file first, then promote the verified content to the branch used by everyday clients.

Configure the provider and connect it to routing rules

In the Mihomo profile, declare the provider under rule-providers, then reference it from rules. The following example illustrates the relationship between the remote source, local cache path, refresh interval, and routing policy. Replace the example URL, path, interval, provider name, and policy group with values that suit your environment.

rule-providers:
  developer-services:
    type: http
    behavior: domain
    format: yaml
    path: ./rules/developer-services.yaml
    url: https://raw.githubusercontent.com/OWNER/REPOSITORY/main/rules/developer-services.yaml
    interval: 86400

rules:
  - RULE-SET,developer-services,Proxy
  - MATCH,DIRECT

The provider key, developer-services, is the identifier used by the RULE-SET rule. Keep the spelling identical in both places. The type describes how the provider is obtained; http means Mihomo fetches it remotely. The behavior describes the kind of rules the provider contains. The format specifies the file representation when applicable. The local path gives Mihomo a place to store the fetched or loaded provider data, while url identifies the remote file. The interval is expressed in seconds, so 86400 requests a daily refresh rather than a refresh every 86,400 minutes.

Provider refresh is not the same as instantaneous synchronization. A commit can be visible on GitHub while a running client continues to use its cached copy until the next update interval, a manual provider update, or a profile reload. Some clients expose provider status and update controls in their interface; others make it easier to inspect the Mihomo configuration or logs. After changing the source, use the client's provider update action if available, then check that the provider reports a successful load. Do not infer success simply because the profile itself was accepted.

Rule order matters just as much as provider correctness. Mihomo evaluates rules in order and uses the first matching rule. Place a provider rule before a broad rule that would otherwise catch the same traffic, such as a general domain rule or MATCH. A valid provider listed after an earlier catch-all rule may never affect the traffic you intended to route. Conversely, putting a broad provider at the top can override more specific exceptions. Plan the order deliberately: specific exceptions first, focused providers next, broad fallback rules later, and a final catch-all at the end.

The policy after RULE-SET must name a policy group or target that exists in the active profile. If the provider matches but the chosen group is missing or misspelled, the profile may fail validation or route incorrectly. Check the group name against the exact spelling in proxy-groups. Where several rule providers need different destinations, use separate RULE-SET lines so each set has an explicit and reviewable policy.

⚠️
Do not replace your fallback blindly: A new provider should usually be added before your existing final rule, not used to remove it. Keep a known-good fallback such as MATCH,DIRECT or the policy appropriate to your profile, and test changes with a reversible commit.

Test from both sides of the configuration. First confirm that Mihomo can download and parse the provider. Then generate traffic to a hostname or address that is definitely covered by one of its entries and inspect the connection or log view to see which rule and policy were selected. A browser page loading successfully is not proof that the intended rule matched: another rule may have produced the same outcome, or the application may have reused an existing connection. Use a fresh request and inspect the actual match when possible.

Validate changes and diagnose stale or unmatched rules

A useful workflow treats every update as a small release. Before publishing, review the diff and check for accidental deletions, malformed commas, unexpected wildcard-like behavior, and duplicated rules. For YAML, check indentation carefully: list items under payload must be aligned consistently. A YAML parser can catch syntax errors, but it cannot tell you whether a domain is too broad or whether the resulting policy is appropriate. Combine syntax validation with semantic review.

For a repeatable process, validate a candidate file locally before committing it. A simple script or continuous-integration job can check that the document parses, that the expected top-level key exists, and that each entry follows the rule grammar your project permits. Add test cases for representative domains and addresses, including at least one exact domain, one subdomain, and one value that should not match. If you use a linter, verify that it understands the Mihomo rule syntax rather than treating every line as a generic string. Automated checks reduce formatting mistakes; human review is still needed to judge routing intent.

If a provider fails to load, start by checking the fetch path rather than rewriting the rules. Open the raw URL without relying on a logged-in browser session and confirm the response code and content. Verify that the client can reach the host through its current network path, that the repository is public if no supported authentication is configured, and that the file has not been renamed. Then inspect Mihomo logs for fetch, parsing, or format errors. A network timeout, an HTTP error, and invalid YAML are different failures and should be investigated separately.

If the provider loads but traffic does not match, verify the active profile first. Many clients allow several profiles or configurations to coexist, and editing one file does not guarantee it is the one currently running. Confirm that the provider is declared in that active profile, that the name in RULE-SET matches the declaration, and that the rule is above any earlier rule that could catch the traffic. Check whether the tested application is using the hostname you expect; cached DNS, redirects, content delivery networks, and auxiliary API hosts can make a service use additional domains not present in a short hand-built list.

For IP-CIDR rules, remember that domain resolution and connection routing can complicate testing. An application may connect to a resolved address rather than expose the original hostname at the point you expect, and an IP rule with no-resolve has different resolution behavior from a rule that allows resolution. Avoid adding broad address ranges just to make one connection work; first identify the actual destination and confirm that the range belongs to the service you intend to match. Overly broad ranges can redirect unrelated applications and make later debugging much harder.

When updates appear stale, check the provider's refresh interval and the client's provider status before assuming GitHub has ignored a commit. The running core may still be using a cached file, may have failed its latest fetch, or may not have reloaded the updated configuration. Trigger a manual update if the client supports it, inspect the reported update time, and compare the downloaded content with the latest raw file. If the source URL points to a different branch or path than the one you edited, correct that mismatch rather than repeatedly restarting the client.

Keep a rollback path. Each meaningful ruleset change should have a commit with a clear message, and a risky change should be tested on a separate branch or profile before becoming the shared default. If users report that a service suddenly stops matching, reverting one commit is safer than making several speculative edits to the live list. Record the reason for additions and removals in commit descriptions or repository documentation; future maintainers need to know whether an entry is still required or was only a temporary diagnostic workaround.

Finally, treat remote rule files as part of your configuration supply chain. A provider can influence where traffic goes, so limit who can modify its source, review changes before merging, and keep the URL and branch under deliberate control. Do not publish private domains, internal IP ranges, credentials, or other sensitive environment details in a public repository. For teams, document who owns the ruleset, how updates are approved, and which clients or Mihomo versions are expected to consume it. These small operational habits make a GitHub-hosted provider dependable rather than merely convenient.

Compared with manually copying rules between profiles, a GitHub-backed provider gives you review history and a single source of truth, but some clients still expose provider errors in terse logs and make remote-file diagnosis less obvious. ClashSky offers a more approachable place to manage a Mihomo-based setup and inspect everyday configuration behavior, helping reduce the friction of testing provider changes across a profile. If you want to try a client workflow that makes these checks easier, you can Download ClashSky.