Skip to content

About

Route rules for mihomo.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

17 stars

Watchers

1 watching

Forks

Repository files navigation

route-rules

route-rules builds compact Mihomo rule providers from maintained upstream domain and IP-CIDR lists. The generated files are published daily to the mihomo branch; current counts, sizes, update time, and download links are shown on GitHub Pages.

Policy and evaluation order

Mihomo must evaluate these sets in this order:

  1. tailscale → the outbound that reaches the Tailscale tailnet
  2. lan → DIRECT
  3. cn → DIRECT
  4. crypto → a globally supported non-US region
  5. openai → the proxy selected for OpenAI services
  6. anthropic → the proxy selected for Anthropic services
  7. us → a United States proxy
  8. global → the normal proxy pool
  9. unmatched traffic → the normal proxy pool

The dedicated openai and anthropic sets let you select a separate outbound for each service. us retains its existing coverage of both services, so configurations using only us continue to work.

anthropic also includes shared telemetry, feature-flag, fraud-detection, support-widget, and analytics destinations from the supporting-service list. Requests from other applications to these shared services follow the Claude outbound too. Keep openai first so its known Sentry endpoint retains the OpenAI outbound. For one consistent Claude egress address, select a fixed proxy rather than a load-balancing group.

Evaluate both tailscale providers before lan: Tailscale's IPv4 range overlaps the shared-address space and its IPv6 range is inside the broader ULA space. Keep domain and classical providers ahead of public IP-CIDR providers after these private-destination rules. This lets an explicit service decision such as us or crypto take precedence over the geographic location of a CDN address.

The set exclusions in config/rulesets.json are applied during generation. IP exclusions are exact CIDR set subtraction. A domain rule is removed only when an earlier rule covers its entire match space; partial domain differences cannot be represented by Mihomo and are resolved by the evaluation order above.

Generated files

For each non-empty behavior, the mihomo branch contains:

  • <name>.domain.mrs and its auditable <name>.domain.list input.
  • <name>.ipcidr.mrs and its auditable <name>.ipcidr.list input.
  • <name>.classical.list when an upstream contains keyword, regular-expression, or partial-wildcard rules that MRS cannot represent faithfully.

tailscale and anthropic have both domain and IP-CIDR artifacts. crypto and openai currently have no IP source, so no empty IP-CIDR artifacts are fabricated for them. The build fails instead of silently dropping malformed input, unsupported source syntax, missing selected V2Fly lists, assertion failures, or MRS round-trip differences.

The GitHub Pages site lets you browse each generated ruleset and test a literal domain or IP address against them. It uses the generated lists in the browser and does not perform DNS lookups. Results are displayed in the configured evaluation priority; unsupported regular-expression classical rules are listed as unevaluated.

Example provider:

rule-providers:
  cn-domain:
    type: http
    behavior: domain
    format: mrs
    url: https://raw.githubusercontent.com/liblaf/route-rules/mihomo/cn.domain.mrs
    path: ./ruleset/cn.domain.mrs
    interval: 86400
  cn-ipcidr:
    type: http
    behavior: ipcidr
    format: mrs
    url: https://raw.githubusercontent.com/liblaf/route-rules/mihomo/cn.ipcidr.mrs
    path: ./ruleset/cn.ipcidr.mrs
    interval: 86400
  cn-classical:
    type: http
    behavior: classical
    format: text
    url: https://raw.githubusercontent.com/liblaf/route-rules/mihomo/cn.classical.list
    path: ./ruleset/cn.classical.list
    interval: 86400

Use all non-empty companions for full source fidelity. GitHub Raw and jsDelivr links for every MRS artifact are generated on the statistics page.

Sources

The declarative source map is in config/rulesets.json. It combines:

Add reviewed CN exceptions to config/overrides/cn.domain.txt. An override is omitted automatically when another CN source already covers it.

Build locally

Requirements: Go 1.25 or newer, Node.js 22 or newer for browser-module tests, and Mihomo 1.19.30 or newer on PATH.

go test ./...
node --test internal/output/web/*.test.mjs
go run ./cmd/route-rules

The generator writes dist/ atomically. It validates the requested domain decisions, compiles every non-empty MRS with Mihomo, decodes it again, and compares the decoded rules with the optimized text input. Mihomo also loads every classical companion in an isolated validation configuration.

The GitHub Actions workflow runs on changes to main, pull requests, manual dispatch, and daily at 16:23 UTC. Non-PR builds replace the mihomo branch contents and deploy the same output to GitHub Pages.

About

Route rules for mihomo.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

17 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages