MCPcopy Index your code
hub / github.com/Watfaq/clash-rs

github.com/Watfaq/clash-rs @v0.10.7

Chat with this repo
repository ↗ · DeepWiki ↗ · release v0.10.7 ↗ · + Follow
3,049 symbols 9,940 edges 349 files 288 documented · 9%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

ClashRS

A custom protocol, rule based network proxy software.

CI codecov

✨ Features

  • 🌈 Flexible traffic routing rules based off source/destination IP/Domain/GeoIP etc.
  • 📦 Local anti spoofing DNS with support of UDP/TCP/DoH/DoT remote, and expose it as a local UDP/TCP/DoH/DoT server.
  • ⚙️ AnyTLS/Hysteria2/Shadowquic/Shadowsocks/Socks5(TCP/UDP)/SSH/Tailscale/tor(onion)/Trojan/Tuic/VLess/Vmess/Wireguard(userspace) outbound support with different underlying transports(gRPC/TLS/H2/WebSocket/etc.).
  • 🔀 Multiple inbound modes: HTTP, SOCKS5, Mixed, Shadowsocks, AnyTLS, Redir, TProxy, and TUN (utun) for transparent proxying.
  • 🌍 Dynamic remote rule/proxy loader.
  • 🎵 Tracing with Jaeger

📡 Protocol Support

Inbounds

Type Description Notes
http HTTP proxy
socks SOCKS5 (TCP + UDP)
mixed HTTP + SOCKS5 on a single port
shadowsocks Shadowsocks inbound with multi-user support shadowsocks feature
anytls AnyTLS inbound with multi-user support, GFW fallback camouflage
tun TUN device for transparent proxying All platforms
tproxy Transparent proxy (TCP + UDP) Linux; tproxy feature
redir TCP redirect Linux; redir feature
tunnel Routes all traffic to a fixed target

Outbounds

Protocol Transports Notes
direct
reject
ss plain · obfs-http · obfs-tls · v2ray-plugin-ws · v2ray-plugin-ws-tls · shadow-tls shadowsocks feature
socks5 plain TCP · TLS
anytls TLS
trojan TLS · WebSocket+TLS · gRPC+TLS
vmess TCP · TCP+TLS · WebSocket+TLS · H2+TLS · gRPC+TLS
vless TLS · WebSocket+TLS · H2+TLS · gRPC+TLS · REALITY
wireguard UDP (userspace) wireguard feature
hysteria2 QUIC · obfs-salamander
tuic QUIC (bbr / cubic / new_reno) tuic feature
shadowquic QUIC · over-stream shadowquic feature
ssh SSH tunnel ssh feature
tor Onion routing onion feature (plus build)
tailscale Mesh VPN tailscale feature (plus build)

🖥 Environment Support

  • Linux
  • macOS
  • Windows
  • You need to copy the wintun.dll file which matches your architecture to the same directory as your executable and run your program as administrator.
  • iOS
  • ChocLite App Store
  • TestFlight Access: TestFlight

💰 Sponsors

📦 Install

Use With GUI

https://github.com/LibNyanpasu/clash-nyanpasu

Download Prebuilt Binary

Can be found at https://github.com/Watfaq/clash-rs/releases

Docker Image

https://github.com/Watfaq/clash-rs/pkgs/container/clash-rs

Local Build

Dependencies

  • cmake (3.29 or newer)
  • libclang(LLVM)
  • nasm (Windows)
  • protoc(for geodata proto generation)
  • pre-commit for managing git hooks
$ pipx install pre-commit
$ pre-commit install

$ cargo build

🔨 Usage

Example Config

sample.yaml:

port: 7890

Run

-> % ./target/debug/clash-rs -c sample.yaml

Help

-> % ./target/debug/clash-rs -h
Usage: clash-rs [OPTIONS]

Options:
  -d, --directory <DIRECTORY>      Set working directory (config-relative paths resolve from here)
  -c, --config <FILE>              Specify configuration file [default: config.yaml] [short aliases: f]
  -t, --test-config                Test configuration and exit
  -v, --version                    Print clash-rs version and exit [short aliases: V]
  -l, --log-file <LOG_FILE>        Additionally log to file
      --help-improve               Enable crash report to help improve clash
      --controller-ipc <IPC_PATH>  Specify the IPC path for the controller [aliases: --ext-ctl-pipe, --ext-ctl-unix]
      --compatibility              Enable compatibility mode for mihomo-consistent behavior
  -h, --help                       Print help

FFI

Compile for apple platforms

To create a framework for iOS and macOS platforms

git clone https://github.com/Watfaq/clash-rs.git
cd clash-rs
chmod +x scripts/build_apple.sh
./scripts/build_apple.sh

This command will generate a clashrs.xcframework file in the build directory.

🔗 Links

🤝 Contributing

❤️ Inspired By

Extension points exported contracts — how you extend this code

Stream (Interface)
`AsyncRead` + `AsyncWrite` + `AsRawFd` Wrapper for stream. This trait is auto implemented for `TcpStream` and `UnixStrea [23 …
clash-lib/src/common/io/splice.rs
Connection (Interface)
(no doc) [1 implementers]
clash-dashboard/src/lib/api.ts
DnsMessageExchanger (Interface)
(no doc)
clash-dns/src/lib.rs
OutboundHandler (Interface)
(no doc) [23 implementers]
clash-lib/src/proxy/mod.rs
ProxyGroupsProps (Interface)
(no doc)
clash-dashboard/src/components/ProxyGroups.tsx
DialWithConnector (Interface)
(no doc) [15 implementers]
clash-lib/src/proxy/mod.rs
TrafficChartProps (Interface)
(no doc)
clash-dashboard/src/components/TrafficChart.tsx
PlainProxyAPIResponse (Interface)
(no doc) [15 implementers]
clash-lib/src/proxy/mod.rs

Core symbols most depended-on inside this repo

new
called by 2112
clash-lib/src/app/dns/resolver/mod.rs
clone
called by 966
clash-lib/src/session.rs
to_owned
called by 525
clash-lib/src/proxy/transport/shadow_tls/utils.rs
len
called by 293
clash-lib/src/proxy/hysteria2/codec.rs
get
called by 134
clash-lib/src/proxy/converters/hysteria2.rs
is_empty
called by 129
clash-netstack/src/ring_buffer.rs
insert
called by 122
clash-lib/src/common/trie.rs
push
called by 119
clash-lib/src/app/dispatcher/statistics_manager.rs

Shape

Method 1,470
Function 1,013
Class 424
Interface 75
Enum 67

Languages

Rust92%
TypeScript6%
Python1%

Modules by API surface

clash-lib/tests/api_tests.rs48 symbols
clash-lib/src/config/internal/proxy.rs48 symbols
clash-lib/src/config/def.rs45 symbols
clash-lib/src/proxy/anytls/mod.rs43 symbols
clash-lib/src/app/dns/resolver/enhanced.rs43 symbols
clash-dashboard/src/lib/api.ts41 symbols
clash-lib/src/proxy/hysteria2/mod.rs38 symbols
clash-lib/src/proxy/shadowsocks/outbound/mod.rs34 symbols
clash-lib/src/proxy/ssh/mod.rs33 symbols
clash-lib/src/app/router/rules/composite.rs33 symbols
clash-lib/src/proxy/vmess/mod.rs31 symbols
clash-lib/src/proxy/utils/test_utils/docker_utils/docker_runner.rs31 symbols

For agents

$ claude mcp add clash-rs \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page