Skip to content
Edit this page

CLI & Environment Variables

This page documents every command-line flag and runtime environment variable recognized by clash-rs.

Command-Line Options

Usage: clash-rs [OPTIONS]
Flag Short / Aliases Default Description
--directory <DIRECTORY> -d Current working directory (.) Sets the working directory ($CWD). Config-relative paths resolve from here. In --compatibility (non-service) mode, also changes the process working directory via set_current_dir.
--config <FILE> -c, -f config.yaml Configuration file path. Outside --service-mode, resolved as <directory>/<FILE> (absolute paths outside -d are accepted at startup) and auto-created with port: 7890 if missing. Inside --service-mode, confined by SafePaths and never auto-created.
--test-config -t false Parse and validate the configuration, then exit (0 on success, 1 on failure).
--version -v, -V false Print version string (clash-rs <version>) and exit.
--log-file <LOG_FILE> -l None Append logs to a file (relative to $CWD) in addition to standard output. Cannot be combined with --service-mode.
--controller-ipc <IPC_PATH> --ext-ctl-unix, --ext-ctl-pipe (single-dash -ext-ctl-unix / -ext-ctl-pipe also accepted) None Overrides external-controller-ipc in config. Preserved across config reloads.
--controller-pipe-sddl <SDDL> Windows only (env: LISTEN_NAMEDPIPE_SDDL) None Sets the Windows Named Pipe SDDL security descriptor for the IPC controller. CLI flag overrides the environment variable. Preserved across reloads.
--compatibility — false Enables Mihomo compatibility mode (default Country.mmdb / geosite.dat, separate clash-rs-cache.db). See Mihomo Compatibility.
--service-mode — false Restricted mode for privileged system services (e.g., Clash Verge Service). Requires --directory, forbids --log-file, requires non-empty --controller-ipc (and --controller-pipe-sddl / LISTEN_NAMEDPIPE_SDDL on Windows) unless --test-config is passed, implies --compatibility, disables SAFE_PATHS / SKIP_SAFE_PATH_CHECK, forbids fd:// TUN, forbids custom Naive cronet-lib-path, and disables POST /restart.
--strict-config — false Rejects any unknown YAML keys at any nesting depth. By default, unknown keys are silently ignored for Mihomo / Clash compatibility. (Note: hot reloads via PUT /configs do not apply --strict-config.)
--help-improve — false Enables opt-in crash reporting (Sentry).
--help -h — Prints CLI help.

Clash Verge Service Enforcement

If the executable path resides under .../clash-verge-service/cores/, ClashRS refuses to start unless --service-mode is passed.

Common CLI Examples

# Run with explicit working directory and config file
clash-rs -d /etc/clash -c config.yaml

# Test configuration in strict mode
clash-rs -d /etc/clash -c config.yaml -t --strict-config

# Run in Mihomo compatibility mode with a Unix socket controller
clash-rs --compatibility -d ~/.config/mihomo -f config.yaml --ext-ctl-unix /tmp/clash-rs.sock

# Additionally write logs to a file
clash-rs -d ./data -c config.yaml -l clash.log

Runtime Environment Variables

Variable Format / Values Default Effect
CLASH_RS_COMPATIBILITY_MODE 1 or true (case-insensitive, trimmed) Disabled Equivalent to passing --compatibility. Useful for launchers with fixed command lines.
SAFE_PATHS OS path list (: on Unix, ; on Windows) of absolute directories Empty Additional root directories allowed for config-referenced assets (GeoData, providers, certificates, external-ui, API reload paths). Ignored in --service-mode. See Safe Paths.
SKIP_SAFE_PATH_CHECK 1, t, T, true, TRUE, True Disabled Disables safe-path confinement. Ignored in --service-mode.
LISTEN_NAMEDPIPE_SDDL Windows SDDL string D:(A;;GRGW;;;BU)(A;;GRGW;;;SY) Default SDDL applied to the Windows Named Pipe IPC controller when --controller-pipe-sddl is not passed.
CLASH_RS_MEM_LIMIT_MB <MB>, <MB>:soft, or <MB>:hard (MB > 0) 0 (unlimited) Enables memory limit management. When built with jemallocator and MALLOC_CONF is unset, also lowers jemalloc arena dirty_decay_ms and muzzy_decay_ms to 1000 ms for faster RSS reclamation.
CLASH_RS_MEM_HARD_RATIO Float (>= 1.0, or 0 to disable hard eviction) 2.0 Multiplier above CLASH_RS_MEM_LIMIT_MB that triggers hard connection eviction (closes 20% of connections).
MALLOC_CONF Standard jemalloc config string Unset If set, prevents ClashRS from overriding jemalloc decay settings when CLASH_RS_MEM_LIMIT_MB is used.
RUST_LOG tracing_subscriber filter directives warn,clash=<log-level> Overrides default log filtering when valid.
CLASH_RS_BACKOFF_ROUNDS Positive integer 12 Health-check backoff interval (in rounds) for proxies that fail 3+ consecutive checks.
CLASH_RS_HEALTHCHECK_CONCURRENCY Positive integer 8 Maximum concurrent proxy health checks.
SSLKEYLOGFILE File path Unset When present, enables rustls::KeyLogFile TLS key logging for packet inspection tools such as Wireshark.

Running as a systemd Service (Linux)

/etc/systemd/system/clash-rs.service
[Unit]
Description=ClashRS Proxy Core
After=network-online.target
Wants=network-online.target

[Service]
Type=simple
ExecStart=/usr/local/bin/clash-rs -d /etc/clash -c config.yaml
Restart=on-failure
RestartSec=3
AmbientCapabilities=CAP_NET_ADMIN CAP_NET_BIND_SERVICE
CapabilityBoundingSet=CAP_NET_ADMIN CAP_NET_BIND_SERVICE
LimitNOFILE=1048576

[Install]
WantedBy=multi-user.target

Enable and start the service:

sudo systemctl daemon-reload
sudo systemctl enable --now clash-rs