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:
This loads ./profiles/config.yaml and sets ./profiles as the working directory (if -d is omitted, the current directory is used).
What Compatibility Mode Changes¶
-
Default GeoData paths (applied only when omitted in YAML; preserved across profile reloads):
YAML Key Default in Compatibility Mode mmdbCountry.mmdbgeositegeosite.dat -
Isolated proxy selection cache:
- With
profile.store-selected: true, compatibility mode stores selections inclash-rs-cache.dbinstead ofcache.db, leaving Mihomo'scache.dbuntouched. -
A hot reload keeps the cache filename selected at startup.
-
Single-dash IPC flag aliases:
- ClashRS automatically rewrites
-ext-ctl-unixand-ext-ctl-pipeto--ext-ctl-unix/--ext-ctl-pipebefore 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):
# 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-configis passed, requires non-empty--controller-ipc(and non-empty--controller-pipe-sddl/LISTEN_NAMEDPIPE_SDDLon Windows). - Automatically enables
--compatibility. - Ignores
SAFE_PATHSandSKIP_SAFE_PATH_CHECK—all config files and assets must live under-d. - Forbids
fd://TUN devices, custom Naivecronet-lib-path, andPOST /restart(returns409 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) |