The General Clash Configuration File
Relevant source files
The following files were used as context for generating this wiki page:The GeneralClashConfig.yml file is the central configuration for the Self-Rule project, which provides a customized set of proxy rules for Clash, based on the ACL4SSR project. This file defines the core behavior of the Clash client, including listening ports, operational mode, logging, and API settings. It is specifically tailored for use with Clash for Windows (CFW), containing numerous cfw- prefixed settings that control UI behavior, system proxy integration, and child process management.
A key architectural aspect of this configuration is its reliance on external rule and proxy providers. Instead of embedding all rules directly, the main configuration is designed to be used with a suite of external YAML files located in the Clash/Providers/ directory. These providers contain extensive lists of domains and IP addresses categorized for different purposes, such as proxying through the GFW, direct connections for Chinese services, or specific rules for platforms like Microsoft and various AI services. This modular approach allows for easier maintenance and updates of rule sets.
Core Network and API Settings
This section defines the fundamental network listeners, LAN access, and the RESTful API for external control.
The following diagram illustrates the basic network interaction model defined in the configuration.
This diagram shows how user devices connect to the Clash client, which then routes traffic to the internet. An external controller UI manages the client via its RESTful API.
Sources: Clash/GeneralClashConfig.yml:6-30
| Parameter | Value | Description |
|---|---|---|
mixed-port | 7890 | A combined 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 same local area network to connect to the proxy. |
bind-address | "*" | Binds to all IP addresses, allowing connections from any device on the network when allow-lan is true. |
ipv6 | true | Enables IPv6 support. |
log-level | info | Sets the logging verbosity. Options include silent, error, warning, info, debug. |
external-controller | '127.0.0.1:9090' | Defines the address for the RESTful API, used by external dashboards like YACD. |
external-ui | dashboard | Specifies the path to a static web UI for controlling Clash. The value dashboard is a common setting for CFW. |
Sources: Clash/GeneralClashConfig.yml:6-30
DNS Configuration and Logic
While the dns section is commented out in the main configuration file, the extensive comments describe the intended DNS resolution logic. The design aims to achieve fast and unpolluted DNS results by using different nameservers for domestic and foreign domains.
The DNS resolution flow is as follows:
- A domain request triggers concurrent DNS queries to all servers in both
nameserver(for domestic, fast DNS) andfallback(for reliable, international DNS) lists. - For domestic domains, the fastest result from the
nameserverlist is chosen. - If the fastest result from
nameserveris a foreign IP address (determined by GeoIP), the fastest result from thefallbacklist is used instead to prevent DNS pollution.
This flowchart visualizes the DNS resolution strategy described in the configuration comments, prioritizing speed for domestic domains and accuracy for foreign ones.
Sources: Clash/GeneralClashConfig.yml:82-93
The configuration comments also recommend using DNS over HTTPS (DoH) or DNS over TLS (DoT) in the fallback group to ensure queries for foreign domains are secure and unpolluted.
Sources: Clash/GeneralClashConfig.yml:95-103
Clash for Windows (CFW) Specific Settings
A significant portion of GeneralClashConfig.yml is dedicated to settings prefixed with cfw-, which are specific to the Clash for Windows client.
System Proxy Bypass (cfw-bypass)
This is one of the most extensive sections, defining which domains and IP ranges should bypass the Clash system proxy and connect directly. This is crucial for ensuring that local services, private networks, and domestic websites that may have issues with proxies continue to function correctly.
The list is highly detailed and categorized by service provider.
# Clash/GeneralClashConfig.yml:311-314
cfw-bypass:
# 直连列表
# MyList
- "*.13th.tech"
Sources: Clash/GeneralClashConfig.yml:311-314
Bypass Categories Include:
- Private IP Ranges:
127.*,10.*,192.168.*, etc. - Generic CN Domains:
*.cn,*.xn--fiqs8s(中国). - Major Chinese Tech Companies:
- Alibaba (
*.alipay.com,*.taobao.com) - Baidu (
*.baidu.com,*.bdstatic.com) - Bilibili (
*.bilibili.com,*.hdslb.com) - ByteDance (
*.douyin.com,*.toutiao.com) - Tencent (
*.qq.com,*.weixin.com)
- Alibaba (
- Gaming Platforms: Steam China (
csgo.wmsj.cn), Epic (*.epicgames.com). - Public CDNs:
*.bootcss.com,*.staticfile.org.
Sources: Clash/GeneralClashConfig.yml:311-898
Other CFW Settings
The configuration includes several other settings to customize the CFW user experience.
| Parameter | Value | Description |
|---|---|---|
cfw-latency-url | http://www.gstatic.com/generate_204 | The URL used to test proxy latency. |
cfw-latency-timeout | 3000 | Timeout in milliseconds for the latency test. |
cfw-conn-break-strategy | proxy: none | Defines how connections are handled when switching proxies. none means existing connections are not broken. |
cfw-proxies-order | default | Sets the sorting order for proxies in the UI. Options are default, latency, alphabet. |
Sources: Clash/GeneralClashConfig.yml:141-201
Rule and Provider Management
The project's architecture heavily relies on external files called "providers" to manage proxy groups and routing rules. This keeps the main configuration file clean and allows for modular updates to rule sets. The Clash/Providers/ directory contains numerous YAML files, each serving a specific purpose.
This diagram shows that the main configuration file references multiple external provider files for its rules and proxy lists.
Sources: Clash/Providers/ProxyGFWlist.yaml, Clash/Providers/ProxyLite.yaml, Clash/Providers/Microsoft.yaml, Clash/Providers/Ruleset/AI.yaml
Provider File Structure
Each provider file contains a payload section, which is a list of domain rules. These rules specify how traffic to certain domains should be handled.
Example from AI.yaml:
# Clash/Providers/Ruleset/AI.yaml:3-7
payload:
# 内容:内容:AI平台-国外
# 数量:39条
- DOMAIN-KEYWORD,anthropic
- DOMAIN-KEYWORD,claude
- DOMAIN-KEYWORD,openai
- DOMAIN,ai.google.dev
Sources: Clash/Providers/Ruleset/AI.yaml:3-7
The repository contains various types of providers:
- Broad Proxy Lists:
ProxyGFWlist.yamlandProxyLite.yamlcontain thousands of rules for sites that need to be accessed via a proxy. - Service-Specific Rules: Files like
Microsoft.yaml,Clash/Providers/Ruleset/Github.yaml, andClash/Providers/Ruleset/Epic.yamlgroup domains for major services. - Categorical Rules: Files such as
Clash/Providers/Ruleset/AI.yaml,Clash/Providers/Ruleset/Scholar.yaml, andClash/Providers/Ruleset/Crypto.yamlgroup domains by their content category. - Whitelists:
UnBan.yamllists domains that should explicitly not be blocked by ad-blocking rules.
Sources: Clash/Providers/ProxyGFWlist.yaml, Clash/Providers/ProxyLite.yaml, Clash/Providers/Microsoft.yaml, Clash/Providers/Ruleset/AI.yaml, Clash/Providers/UnBan.yaml
Configuration Generation Workflow
The update_providers.py script reveals an automated workflow for maintaining the YAML provider files. It finds .list files within the Clash directory, parses them, and converts them into the YAML format required by Clash, placing the output in the Clash/Providers/ directory.
The script's logic can be summarized as follows:
This flowchart details the process within update_providers.py for converting .list rule files into Clash-compatible .yaml provider files.
Sources: update_providers.py:11-41
This process automates the creation of rule providers, ensuring consistency and reducing manual effort in maintaining the large set of rules used by the project.
Conclusion
The GeneralClashConfig.yml is the cornerstone of the Self-Rule repository, providing a robust and highly customized configuration for Clash, particularly for Clash for Windows users. Its strength lies in a modular architecture that separates core settings from the vast and well-categorized rule sets managed in external provider files. The inclusion of automation scripts like update_providers.py further highlights the project's focus on maintainability and ease of use for managing complex proxy routing rules.