Skip to content

Adancurusul/clash-chain-patcher

Repository files navigation

Clash Chain Patcher

Logo

A GUI & CLI tool to add SOCKS5 proxy chains to Clash configurations

Version Rust License

FeaturesDownloadGUICLIBuilding


Screenshot

Main Interface

Features

  • Dual Chain Groups - Creates both Chain-Auto (fastest auto-select) and Chain-Selector (manual) groups
  • Rules Rewrite - Selectively redirect Clash rules to use chain proxies (Chain-Selector / Chain-Auto)
  • Custom Rules - Inject custom domain routing rules (e.g., Lark/飞书 → DIRECT) with saveable presets
  • Proxy Pool - Manage multiple SOCKS5 upstream proxies with health checking
  • File Watching - Auto re-apply when Clash config changes externally
  • CLI Support - Full command-line interface (ccp) for scripting and automation
  • Cross-platform - Windows, macOS, Linux

How It Works

Traffic flow: You → Clash → VPN Node → Your SOCKS5 Proxy → Internet
  1. Add your SOCKS5 proxy to the Proxy Pool
  2. Select Clash config file
  3. Configure Rules Rewrite - Choose which rule groups to redirect through chain proxies
  4. Add Custom Rules (optional) - Route specific domains to DIRECT or other groups
  5. Click Apply - Creates chain relays, selector groups, rewrites rules, and injects custom rules

Download

Download the latest release from Releases:

Platform File Note
Windows *-setup.exe NSIS Installer (Recommended)
Windows *-portable.zip Portable version
macOS *.dmg Drag to Applications
Linux clash-chain-patcher-linux chmod +x and run

macOS: First Launch

xattr -cr /Applications/Clash\ Chain\ Patcher.app

GUI Usage

Step 1: Add SOCKS5 Proxy

Fill in Host, Port, User, Pass, click + Add.

Step 2: Select Clash Config

Click Select to choose your Clash YAML config file.

Step 3: Rules Rewrite (Optional)

After loading a config, the Rules Rewrite panel auto-detects all proxy groups referenced in rules:

  • Click the check (✓) to enable/disable a group for rewriting
  • Click the target button to cycle through: KeepChain-SelectorChain-Auto
  • Non-DIRECT/REJECT groups are auto-checked with Chain-Selector by default

Step 4: Custom Rules (Optional)

Expand the Custom Rules panel to add domain-specific routing exceptions:

  • Enter domains (comma-separated, e.g. lark.com,feishu.cn)
  • Click Type to cycle: SUFFIX (domain suffix) → KEYWORD (contains) → EXACT (exact match)
  • Click Target to cycle through available groups: DIRECT, config groups, Chain-Selector, Chain-Auto
  • Click + Add to add the rule

Use case: When using a US SOCKS5 proxy chain, services like Lark/飞书 (blocked in the US) should go DIRECT.

Presets: Save your custom rules as named presets for reuse — enter a name and click Save. Click Load to load a saved preset.

Step 5: Apply

Click Apply. The tool will:

  • Create relay chains for each proxy node
  • Create Chain-Selector and Chain-Auto groups
  • Rewrite checked rules to point to the selected chain group
  • Inject custom rules at the top of the rules section (highest priority)

CLI Usage

The CLI binary is called ccp (Clash Chain Patcher).

Show config info

ccp info config.yaml

Output:

Rules: 3 groups, 630 total rules
Group                                       Rules
--------------------------------------------------
Proxy                                         371
DIRECT                                        233
REJECT                                         26

Proxy nodes: 45
Proxy groups: 5

Apply chain patch + rewrite rules

# Auto-detect main group and replace with Chain-Selector
ccp apply config.yaml -p host:port:user:pass -r auto

# Specify target explicitly
ccp apply config.yaml -p host:port -r "Proxy=Chain-Selector"

# Multiple rewrites
ccp apply config.yaml -p user:pass@host:port \
  -r "Proxy=Chain-Selector" \
  -r "Streaming=Chain-Auto"

Apply with custom rules

# Inject custom domain rules (highest priority, prepended to rules section)
ccp apply config.yaml -p host:port:user:pass -r auto \
  --custom-rule "DOMAIN-KEYWORD:lark,feishu:DIRECT"

# Multiple custom rules
ccp apply config.yaml -p host:port -r auto \
  --custom-rule "DOMAIN-KEYWORD:lark,feishu:DIRECT" \
  --custom-rule "DOMAIN-SUFFIX,larksuite.com,DIRECT"

# Use a saved preset
ccp apply config.yaml -p host:port -r auto --preset lark-direct

Custom rule formats:

  • Colon format (multi-domain): TYPE:domain1,domain2:GROUP
  • Comma format (single): TYPE,domain,GROUP
  • Types: DOMAIN-SUFFIX / DOMAIN-KEYWORD / DOMAIN (or short: SUFFIX / KEYWORD / EXACT)

Manage presets

# Create a reusable preset
ccp preset create lark-direct \
  --rule "DOMAIN-KEYWORD,lark,DIRECT" \
  --rule "DOMAIN-KEYWORD,feishu,DIRECT" \
  --rule "DOMAIN-SUFFIX,larksuite.com,DIRECT"

# List all presets
ccp preset list

# Show preset details
ccp preset show lark-direct

# Delete a preset
ccp preset delete lark-direct

Presets are saved in ~/.config/clash-chain-patcher/config.json.

Rewrite rules only (no chain creation)

ccp rules config.yaml -r auto
ccp rules config.yaml -r "Proxy=Chain-Auto"

Options

ccp apply [OPTIONS] --proxy <PROXY> <CONFIG>

Options:
  -p, --proxy <PROXY>          SOCKS5 proxy string
  -r, --rewrite <REWRITE>      Rule rewrite (repeatable), or "auto"
      --custom-rule <RULE>     Custom rule to inject (repeatable)
      --preset <NAME>          Apply a saved preset (repeatable)
      --no-backup              Skip creating backup
      --suffix <SUFFIX>        Chain suffix [default: -Chain]

Example

Original config:

proxies:
  - name: "Tokyo-01"
    type: vmess
    server: example.com

proxy-groups:
  - name: "Proxy"
    type: select
    proxies: ["Tokyo-01"]

rules:
  - DOMAIN,google.com,Proxy
  - MATCH,Proxy

After ccp apply config.yaml -p 1.2.3.4:1080 -r auto --custom-rule "DOMAIN-KEYWORD:lark,feishu:DIRECT":

proxies:
  - name: "Local-Chain-Proxy"
    type: socks5
    server: 1.2.3.4
    port: 1080

  - name: "Tokyo-01"
    type: vmess
    server: example.com

proxy-groups:
  - name: "Chain-Selector"
    type: select
    proxies: ["Tokyo-01-Chain"]

  - name: "Chain-Auto"
    type: url-test
    proxies: ["Tokyo-01-Chain"]
    url: "http://www.gstatic.com/generate_204"
    interval: 300

  - name: "Proxy"
    type: select
    proxies: ["Chain-Selector", "Chain-Auto", "Tokyo-01"]

  - name: "Tokyo-01-Chain"
    type: relay
    proxies: ["Tokyo-01", "Local-Chain-Proxy"]

rules:
  - DOMAIN-KEYWORD,lark,DIRECT          # custom rule (highest priority)
  - DOMAIN-KEYWORD,feishu,DIRECT        # custom rule
  - DOMAIN,google.com,Chain-Selector    # was: Proxy
  - MATCH,Chain-Selector                # was: Proxy

Building

Prerequisites

  • Rust 1.70+

Build from source

git clone https://github.com/user/clash-chain-patcher.git
cd clash-chain-patcher

# Build GUI
cargo build --release --bin clash-chain-patcher

# Build CLI
cargo build --release --bin ccp

Tech Stack

  • GUI: Makepad - Rust native UI framework
  • CLI: clap - Command-line argument parser
  • YAML: serde_yaml
  • File dialogs: rfd

Disclaimer

This software is provided for educational and research purposes only.

  • Intended solely for learning network technologies and personal research
  • Users are responsible for ensuring compliance with applicable laws
  • The author assumes no liability for misuse or consequences

Use at your own risk.

License

MIT License

About

A GUI tool to add SOCKS5 proxy chains to Clash configurations

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages