Getting Started
Relevant source files
The following files were used as context for generating this wiki page:- Clash/GeneralClashConfig.yml
- update_providers.py
- update_sing_box.py
- Clash/Providers/ProxyGFWlist.yaml
- Clash/Providers/ProxyLite.yaml
- Clash/Providers/Ruleset/AI.yaml
- Clash/Providers/Ruleset/Developer.yaml
- Clash/Providers/Ruleset/Scholar.yaml
- Clash/Providers/Microsoft.yaml
- Tool/Surge转acl工具/acl自定义语言格式文件.xml
The Self-Rule project provides a comprehensive and personalized collection of rule configurations for network proxy clients, primarily focusing on Clash. These rules are designed to intelligently route internet traffic, directing specific requests through proxies while allowing others to connect directly. This is particularly useful for navigating complex network environments and accessing international resources. The configuration is highly modular, with separate rule sets for different services like AI platforms, developer tools, and academic websites, allowing for easy customization.
This guide provides an overview of the core configuration, rule structure, and automation tools within the repository. It will help you understand how to use and customize these rules for your own setup. The primary configuration file is Clash/GeneralClashConfig.yml, which serves as the entry point for the Clash client.
Core Configuration
The main settings for the Clash client are defined in Clash/GeneralClashConfig.yml. This file must be placed in $HOME/.config/clash/config.yml or in the same directory where the Clash executable is run. It controls listening ports, LAN access, logging, and the RESTful API for management.
Sources: Clash/GeneralClashConfig.yml:2-5
Key Parameters
The following table summarizes the essential configuration parameters found at the top of the GeneralClashConfig.yml file.
| Parameter | Example Value | Description |
|---|---|---|
mixed-port | 7890 | A single port for both HTTP and SOCKS5 proxy services. |
socks-port | 7891 | A dedicated port for the SOCKS5 proxy service. |
allow-lan | true | Allows other devices on the local network to connect to the proxy. |
bind-address | "*" | Binds to all IP addresses when allow-lan is true. |
ipv6 | true | Enables IPv6 traffic processing. |
log-level | info | Sets the verbosity of logs. Options are silent, error, warning, info, debug. |
external-controller | '127.0.0.1:9090' | The address for the Clash RESTful API, used by dashboards like yacd. |
external-ui | dashboard | Specifies the directory for a static web dashboard to manage Clash. |
Sources: Clash/GeneralClashConfig.yml:7-40
Clash for Windows (CFW) Specifics
The configuration also includes settings specifically for the Clash for Windows client, prefixed with cfw-.
# Clash for Windows
# Proxies module latency test settings
cfw-latency-timeout: 3000
cfw-latency-url: http://www.gstatic.com/generate_204
Sources: Clash/GeneralClashConfig.yml:150-153
A critical feature is cfw-bypass, which defines a list of domains and IP networks that should skip the system proxy and connect directly. This is essential for ensuring local services and specific domestic websites function correctly.
# System proxy will ignore these domains(or ipnet)
cfw-bypass:
# 直连列表
# MyList
- "*.13th.tech"
- "*.423down.com"
# CN域名直连(中国|公司|网络)
- "*.cn"
# China DNS
- "*.doh.pub"
- "*.dns.alidns.com"
# Local addresses
- localhost
- 127.*
- 10.*
- 192.168.*
- <local>
Sources: Clash/GeneralClashConfig.yml:267-1011
The logic for handling system traffic with cfw-bypass is illustrated below.
This diagram shows how the cfw-bypass list is used to exclude certain traffic from the proxy.
Sources: Clash/GeneralClashConfig.yml:267-1011
Rule and Provider Structure
The power of this repository lies in its modular rule system. Instead of a single monolithic rule file, it uses proxy-providers and rule-providers. These are external files containing lists of domains, keywords, or IP ranges that define how traffic should be routed.
The main proxy rule lists are ProxyGFWlist.yaml (comprehensive) and ProxyLite.yaml (a smaller, faster alternative). These files contain a large payload of rules.
Sources: Clash/Providers/ProxyGFWlist.yaml, Clash/Providers/ProxyLite.yaml
Rule Provider Examples
The repository contains specialized rule sets for various services. These are typically used within proxy-groups in a full Clash configuration to direct traffic to specific proxies.
| Rule Provider File | Description |
|---|---|
Ruleset/AI.yaml | Contains domains for AI platforms like OpenAI, Gemini, and Claude. |
Ruleset/Developer.yaml | Includes domains for developer tools and forums like Docker, GitLab, and Stack Overflow. |
Ruleset/Scholar.yaml | Lists domains for academic and research websites such as IEEE, Nature, and ACM. |
Ruleset/Crypto.yaml | A comprehensive list for cryptocurrency exchanges and services like Binance, Coinbase, and Ethereum. |
Microsoft.yaml | Contains domains for various Microsoft services, including Office 365, Azure, and OneDrive. |
Sources: Clash/Providers/Ruleset/AI.yaml, Clash/Providers/Ruleset/Developer.yaml, Clash/Providers/Ruleset/Scholar.yaml, Clash/Providers/Ruleset/Crypto.yaml, Clash/Providers/Microsoft.yaml
Rule Syntax
The provider files use a simple YAML structure with a payload key, followed by a list of rule entries.
payload:
# 内容:Wikipedia 维基相关域名
# 数量:12条
- DOMAIN-SUFFIX,mediawiki.org
- DOMAIN-SUFFIX,wikibooks.org
- DOMAIN-SUFFIX,wikidata.org
Sources: Clash/Providers/Ruleset/Wikipedia.yaml:1-6
The common rule types are:
DOMAIN-SUFFIX: Matches a domain and all its subdomains (e.g.,google.com).DOMAIN-KEYWORD: Matches if a keyword is present anywhere in the domain name.IP-CIDR: Matches an IP address range.
Sources: Clash/Providers/ProxyGFWlist.yaml:7010-7012, Clash/Providers/Ruleset/AI.yaml:5-7
Automation and Tooling
The repository includes Python scripts to automate the generation and maintenance of rule files, ensuring consistency across different formats.
Provider Update Script (update_providers.py)
This script scans the Clash directory for .list files and converts them into Clash-compatible .yaml provider files. It handles comments and formats the output correctly under the payload key.
The process is as follows:
- Walk through the
Clashdirectory, ignoring specified folders likeconfigandProviders. - For each
.listfile found, create a corresponding.yamlfile in theClash/Providers/directory. - Read the
.listfile line by line. - Write each rule from the
.listfile into the new.yamlfile, prefixed with-. - The script also cleans up old
.yamlfiles inClash/Providersif their source.listfile no longer exists.
Sources: update_providers.py
This diagram outlines the workflow of the update_providers.py script for converting .list files to .yaml rule providers.
Sources: update_providers.py
Sing-box Update Script (update_sing_box.py)
A similar script, update_sing_box.py, exists to support the sing-box proxy client. It converts the same .list files into a JSON format, which is then compiled into a binary .srs rule-set file using the sing-box command-line tool. This demonstrates the project's adaptability to different proxy ecosystems.
The script defines data classes (HeadlessRule, Rule) to structure the JSON output correctly based on the rule types found in the .list files (e.g., DOMAIN-SUFFIX, IP-CIDR).
Sources: update_sing_box.py
Other Tools
The repository also contains tools for converting between different rule formats, such as the "Surge to ACL" tool. This is indicated by XML files defining language syntax and macros for Notepad++, designed to automate the conversion of rules from Surge's format to a compatible ACL format.
Sources: Tool/Surge转acl工具/acl自定义语言格式文件.xml, Tool/Surge转acl工具/shortcuts.xml
Summary
The Self-Rule project is a powerful, well-structured collection of proxy rulesets for advanced users. By leveraging a modular provider system and automation scripts, it offers a flexible and maintainable way to manage complex network routing policies. Getting started involves placing the main GeneralClashConfig.yml in the correct directory and ensuring that the associated provider files are correctly referenced and updated. The extensive cfw-bypass list is a key feature for Windows users, providing a seamless experience by separating local/domestic traffic from traffic that requires a proxy.