Why move custom rules into a Mihomo rule provider?

As a Mihomo configuration grows, its rules section can become a long mix of personal exceptions, service-specific domains, LAN exclusions, and broad fallbacks. Editing that list directly works at first, but it makes routine maintenance harder: a small routing change can mean touching the main profile, checking indentation across a large file, and reloading rules that have nothing to do with the change. A malformed line can also prevent the profile from parsing, even when the rest of the configuration is sound.

A rule provider moves a related set of routing rules into a separate file. The main configuration declares where that set comes from, how Mihomo should interpret it, where it should be stored locally, and how often an HTTP copy should be refreshed. It then references the provider with a RULE-SET rule. This separation is useful for rules you update independently, such as a personal domain list, a project’s service endpoints, or a small set of organization-specific routing exceptions.

Providers do not replace the main rules list or decide traffic policy on their own. They supply matchers; the rules section still determines where those matchers sit in evaluation order and what policy to apply when one matches. That distinction matters. A correct provider placed after a catch-all MATCH rule is effectively unreachable, while a well-ordered provider can keep related entries organized without changing the behavior of unrelated rules.

ℹ️
Scope: This guide covers Mihomo rule-provider files and public GitHub hosting. Client interfaces and supported options can vary by Mihomo version, so validate the exact schema against the documentation for the core you run.

Understand provider types, behavior, and file formats

Before writing YAML, separate three concepts that are easy to conflate. The provider type describes how Mihomo obtains the rules: http fetches a remote resource and saves it locally, while file reads a local file. The provider behavior tells Mihomo what kind of entries the set contains: commonly domain, ipcidr, or classical. The format describes the representation of the downloaded or local content, such as YAML or text, when supported by the core version in use.

Choose the behavior to match the entries you actually need. A domain provider is convenient when the source is a list of domain patterns. An IP-CIDR provider is appropriate for networks expressed as CIDR ranges, and may need options such as no-resolve on the referencing rule depending on the matching intent. A classical provider can contain complete rule expressions, such as DOMAIN-SUFFIX or PROCESS-NAME, and is the flexible choice when the set mixes matcher types. Do not put full classical rule lines into a domain-only provider: the file may parse differently than you expect or be rejected.

For a YAML provider, a domain set might look like this:

payload:
  - '+.example.org'
  - '+.service.example'
  - 'api.example.net'

The payload key contains the entries, and each item is a YAML string. A leading +. is commonly used for a domain suffix pattern that includes the base domain and its subdomains; confirm the matcher syntax supported by your Mihomo version before publishing a larger list. If you need a classical set instead, its payload contains complete rule expressions, for example DOMAIN-SUFFIX,example.org. Keep one provider focused on one clear purpose so that both its behavior and its name remain easy to understand.

A practical naming convention uses a short, stable key such as custom-services or work-domains. That key is used by the main configuration, while the provider’s file name and repository path can be chosen independently. Prefer readable names over labels like rules2: when troubleshooting a match months later, a descriptive name saves time.

Write the provider declaration and reference it in rule order

The following example fetches a YAML domain set from a public GitHub repository, stores it under the Mihomo working directory, and refreshes it once per day. Replace the repository owner, branch, and file path with values you control. The raw URL must point to the actual file content, not to the normal GitHub page that displays the file in a browser.

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

rules:
  - RULE-SET,custom-services,MyProxy
  - DOMAIN-SUFFIX,local.example,DIRECT
  - GEOIP,LAN,DIRECT
  - MATCH,MyProxy

Here, custom-services is the provider key and must match the first field in RULE-SET,custom-services,MyProxy. MyProxy must also be a policy group that exists in the active configuration; substitute the exact name of your own group. The path is a local cache location. Use a path that is writable by the Mihomo process and avoid choosing a location that your client routinely deletes or replaces when switching profiles.

Rule order is not cosmetic. Mihomo evaluates rules from top to bottom, so place the provider reference before a broad rule that would otherwise match the same traffic. A final MATCH is commonly used as the fallback and therefore belongs at the end. If your local-network exceptions must always remain direct, put those exceptions before a broader provider that might also include local domains. Conversely, if the provider is intended to override a general domain rule, place its reference earlier. Think through overlaps explicitly rather than assuming a provider has priority because it is a separate file.

For a provider containing complete rule expressions, choose a compatible behavior and format, then use the same reference pattern in rules. For example, a classical provider could contain several matcher types in one set. Keep the destination policy in the main configuration unless there is a specific reason to couple it to the rule data; that makes the same provider reusable with a different proxy group or policy later.

⚠️
Check the core version: Provider fields and accepted formats can differ between Mihomo releases and client builds. If a profile rejects format or another option, consult the documentation for the installed core rather than copying a schema meant for a different version.

Host rule-provider YAML on GitHub safely

A public GitHub repository is a straightforward place to keep a small custom rules file under version control. Create a repository, add a dedicated directory such as rules/, and commit the provider file there. Use the raw-content URL for the committed file, typically following the pattern https://raw.githubusercontent.com/OWNER/REPOSITORY/BRANCH/PATH. Open that URL in a browser before adding it to Mihomo: it should return the file contents directly, not a GitHub HTML page, a sign-in screen, or a 404 response.

For a configuration intended to stay stable, use a predictable branch such as main and a stable file path. Each change to that file can then be reviewed in Git history, and you can revert a bad edit without reconstructing the previous list. If you want deliberate release control, you can instead point the configuration at a versioned path or tag. A pinned version will not automatically include later changes, so update the URL when you intentionally adopt a new revision.

Do not publish credentials, subscription URLs, private hostnames, internal IP ranges, or other information that should not be public. A public rule file is readable by anyone who has its URL, and raw GitHub content is not a secrets-management system. Private repositories may require authentication that a Mihomo HTTP provider cannot use in the way a public raw URL can; avoid putting a personal access token directly into a shareable configuration. If a rule set must remain private, choose an access method supported by your deployment and protect the credentials outside any profile you distribute.

The interval value is expressed in seconds and controls how often Mihomo attempts to refresh an HTTP provider. A daily interval such as 86400 is reasonable for a list that changes occasionally; a rapidly changing list may need a shorter period. Very frequent polling rarely improves routing and can create needless requests or expose you to upstream rate limits. Also, a refresh interval is not a guarantee that every request will retrieve the newest bytes immediately: network errors, upstream caching, or a temporarily unreachable host can delay updates. Keep the last known good provider file available and make changes gradually.

GitHub is a convenient host, not an availability guarantee. Treat it as one dependency in your routing path: if the device cannot reach the raw-content host at startup, the provider may not refresh at that moment. For critical environments, test behavior while offline or while the remote URL is unavailable, and confirm that the locally stored file and the client’s startup behavior meet your needs.

Validate updates and diagnose parsing or matching failures

Validate the main profile after adding a provider, then check the running client’s logs or provider status before assuming the rules are active. A successful profile load confirms only that the configuration passed its checks; it does not prove that the remote file is reachable, that the latest version was downloaded, or that a test request matches the intended entry. When possible, inspect both the provider’s refresh status and the connection’s matched rule in the client’s connection details.

If the profile fails to parse, start with YAML structure. Indentation must use spaces consistently, keys such as rule-providers, behavior, and payload must be spelled correctly, and string values containing punctuation should be quoted when necessary. Check for tabs, duplicate keys, missing colons, and accidental smart punctuation copied from a document editor. If the error names a provider field, verify that the installed Mihomo core supports that field and format.

If the profile loads but the provider remains unavailable or stale, test the raw URL directly and confirm it returns valid file content. Check the branch and case-sensitive path, repository visibility, device connectivity, and whether a proxy or firewall blocks the request. Also inspect the local path: a bad or unwritable path can prevent the provider from being stored or updated. If the provider was renamed, make sure the key in RULE-SET still exactly matches the declaration.

If the provider reports as loaded but traffic takes the wrong route, test with a hostname that should match and examine the connection’s matched-rule information. Confirm that the entry syntax matches the selected behavior, the tested hostname is actually covered by the pattern, and the provider reference appears before any broader matching rule. Check for overlapping rules, a misspelled policy-group name, and DNS behavior that may affect IP-based matching. When diagnosing, temporarily use one unmistakable test domain and one clearly identifiable policy; changing several providers and rules at once makes it difficult to find the cause.

Maintain the rules file like a small software artifact. Review each change, keep entries narrowly scoped, and remove stale rules instead of accumulating exceptions indefinitely. Before committing a large edit, test the syntax and make a small change first. Record why unusual entries exist, especially if they compensate for a service migration or a specific network environment. That context helps future maintainers distinguish an intentional exception from a forgotten workaround.

Compared with hand-editing a large profile or copying an unreviewed rule bundle from a forum, a dedicated GitHub-hosted provider gives you clearer change history and keeps custom routing data separate from client settings. Some graphical clients make provider status and rule matching easier to inspect, while lightweight editors may leave more validation and maintenance to you; Mihomo still provides the consistent rule engine underneath. If you want a more approachable way to manage Mihomo-based profiles and inspect routing behavior, ClashSky is worth trying—download it and compare the workflow with your current setup.

Download ClashSky