Skip to content
Edit this page

Mihomo Compatibility & Safe Paths

ClashRS can operate as a drop-in replacement for Mihomo in launchers such as Clash Verge while enforcing strict filesystem path confinement for configuration-supplied assets.

Mihomo Compatibility Mode

Enable compatibility mode when sharing a data directory and GeoData files with Mihomo:

clash-rs --compatibility -d ./profiles -f config.yaml

This loads ./profiles/config.yaml and sets ./profiles as the working directory (if -d is omitted, the current directory is used).

For launchers with a fixed command line, set:

CLASH_RS_COMPATIBILITY_MODE=1   # or "true" (case-insensitive)

To disable it later, unset the variable and omit --compatibility, then restart ClashRS.

What Compatibility Mode Changes

  1. Default GeoData paths (applied only when omitted in YAML; preserved across profile reloads):

    YAML Key Default in Compatibility Mode
    mmdb Country.mmdb
    geosite geosite.dat
  2. Isolated proxy selection cache:

  3. With profile.store-selected: true, compatibility mode stores selections in clash-rs-cache.db instead of cache.db, leaving Mihomo's cache.db untouched.
  4. A hot reload keeps the cache filename selected at startup.

  5. Single-dash IPC flag aliases:

  6. ClashRS automatically rewrites -ext-ctl-unix and -ext-ctl-pipe to --ext-ctl-unix / --ext-ctl-pipe before parsing CLI options.

Safe Paths

By default, ClashRS confines all configuration-supplied paths to the working directory (-d, or current directory when omitted) in both normal and compatibility modes. This applies to:

  • GeoData files (mmdb, asn-mmdb, geosite)
  • Provider files and local caches (proxy-providers, rule-providers, inbound-providers)
  • TLS certificates and keys (tls-cert, tls-key, certificate, private-key, ca-cert)
  • Dashboard directory (external-ui)
  • Explicit profile paths submitted via PUT /configs

Startup profile outside -d

Outside --service-mode, you may pass a startup profile outside -d via -c / -f. Subsequent PUT /configs reloads with an empty path and payload keep that startup file.

Allowing Extra Directories (SAFE_PATHS)

Set SAFE_PATHS in the process environment to allow additional absolute root directories (separated by : on Unix or ; on Windows):

# Linux / macOS
SAFE_PATHS=/srv/providers:/srv/geodata clash-rs -d /etc/clash -c config.yaml
# Windows PowerShell
$env:SAFE_PATHS = "C:\clash\providers;C:\clash\geodata"
clash-rs -d C:\clash -c config.yaml
  • An explicitly listed root directory may be a symlink or Windows junction (resolved once at startup; overlapping roots pick the most specific match).
  • Any symlink or Windows reparse point below an allowed root is rejected.

Disabling Safe Paths (SKIP_SAFE_PATH_CHECK)

To opt out of safe-path checking outside --service-mode, set SKIP_SAFE_PATH_CHECK to 1, t, T, true, TRUE, or True. Both SAFE_PATHS and SKIP_SAFE_PATH_CHECK are read once at startup.


Service Mode (--service-mode)

Designed for privileged background services (such as Clash Verge Service):

  • Requires --directory (-d).
  • Forbids --log-file (-l).
  • Unless --test-config is passed, requires non-empty --controller-ipc (and non-empty --controller-pipe-sddl / LISTEN_NAMEDPIPE_SDDL on Windows).
  • Automatically enables --compatibility.
  • Ignores SAFE_PATHS and SKIP_SAFE_PATH_CHECK—all config files and assets must live under -d.
  • Forbids fd:// TUN devices, custom Naive cronet-lib-path, and POST /restart (returns 409 Conflict).

Quick Migration Checklist (Mihomo → ClashRS)

Mihomo Feature / Key ClashRS Equivalent or Status
fwmark Use routing-mark
tun.inet4-address / tun.inet6-address Use tun.gateway / tun.gateway-v6
tun.auto-redirect: true (Linux) Rejected on Linux; use auto-route: true with so-mark & route-table
dns.enhanced-mode: redir-host Not supported (no-op); use fake-ip or normal
dns.nameserver: ["system"] Not supported (skipped); specify concrete IPs or DoH/DoT URLs
dns.nameserver-policy list values Must be a single upstream string per domain
proxies[].type: http / snell / ssr Not supported (parse error)
hysteria2 without skip-cert-verify Must explicitly specify skip-cert-verify: false or true
vmess without cipher Explicitly set cipher: auto (or concrete cipher)
proxy-groups filter / include-all Not implemented
rules: FINAL, SUB-RULE, IP-ASN, UID Not supported (use MATCH instead of FINAL)
rule-providers format: mrs Supported for domain and ipcidr (classical unsupported)