Clash Verge: How to Add Rules / Custom Rules (Rev v2.x current method)
If you searched for “Clash Verge add rules” or “custom rules”, you’ve probably hit the same trap as everyone else: you edited the config file, added your rules — and they all vanished after the next subscription update. This guide uses the current (v2.x) method so your rules survive subscription updates, with copy-paste examples.
This follows Clash Verge Rev (you should use Rev today — here’s why).
First principle: never edit the subscription file directly #
The subscription you import is downloaded as a YAML config file. Every subscription update re-downloads and overwrites that file — so any rule you typed into it is lost.
Likewise, the Rules tab in the left sidebar is read-only. It only shows the rules currently in effect; you cannot add rules there.
The correct ways are on the Profiles page:
| Method | Best for | Notes |
|---|---|---|
| Edit Rule | Most people | Open via right-click on the profile card; add rules in a visual prepend/append editor (the official home of prepend-rules since v1.7.x) |
| Extended Script | Batch / conditional logic | JavaScript that modifies config.rules; most flexible |
⚠️ Version note: in v1.6.x and earlier you wrote
prepend-rulesinside the “Merge” config; since v1.7.x the Extended Configuration is only for override/merge (DNS, ports, etc. — see Global Extended Configuration). Add rules via Edit Rule below.
Rule basics: types and match order #
A rule looks like: TYPE,MATCH,TARGET.
| Type | Meaning | Example |
|---|---|---|
DOMAIN | Exact domain | DOMAIN,www.google.com,Proxy |
DOMAIN-SUFFIX | Domain suffix (most used) | DOMAIN-SUFFIX,google.com,Proxy |
DOMAIN-KEYWORD | Domain contains keyword | DOMAIN-KEYWORD,google,Proxy |
DOMAIN-REGEX | Regex domain (Mihomo) | DOMAIN-REGEX,^.+\.google\.com$,Proxy |
GEOSITE | Domain category set (Mihomo) | GEOSITE,category-ads-all,REJECT |
IP-CIDR | IPv4 range | IP-CIDR,192.168.0.0/16,DIRECT,no-resolve |
GEOIP | IP by country | GEOIP,CN,DIRECT |
PROCESS-NAME | Local process name | PROCESS-NAME,Telegram.exe,Proxy |
RULE-SET | Reference a rule set (below) | RULE-SET,my-direct,DIRECT |
MATCH | Catch-all for everything left | MATCH,Proxy |
The target (last field) is one of three: DIRECT, REJECT (block — for ad-blocking), or a proxy group name (⚠️ it must be a group that actually exists in your subscription, e.g. Proxy, Auto).
Match order: top to bottom, first match wins. Put a rule in prepend to make it win; MATCH is always the final catch-all (your subscription already has one — don’t duplicate it).
Method 1: right-click profile → “Edit Rule” (recommended) #
- Open the Profiles page and right-click the profile you use.
- Choose Edit Rule.
- Add your rules in the prepend area (highest priority, inserted before all other rules); put catch-all rules in append. One per line:
# force through proxy (replace "Proxy" with a real group name from your subscription)
DOMAIN-SUFFIX,openai.com,Proxy
DOMAIN-SUFFIX,githubusercontent.com,Proxy
# force direct (corporate intranet, banking, etc.)
DOMAIN-SUFFIX,mybank.com,DIRECT
IP-CIDR,192.168.0.0/16,DIRECT,no-resolve
# block ads / specific domains
DOMAIN-SUFFIX,doubleclick.net,REJECT
DOMAIN-KEYWORD,adservice,REJECT
Save, then refresh that profile. These edits are stored in the profile’s extended config, so updates won’t wipe them. Search your domain in the Rules tab to confirm.
Method 2: add rules via Extended Script (batch) #
For conditional or bulk edits, use an Extended Script (JavaScript, running on quickjs — no filesystem access). main(config) receives the config object and returns the modified one:
// right-click profile → edit (Extended Script), or use the Global Extended Script
function main(config) {
const myRules = [
"DOMAIN-SUFFIX,openai.com,Proxy",
"DOMAIN-SUFFIX,claude.ai,Proxy",
"DOMAIN-SUFFIX,doubleclick.net,REJECT",
];
config.rules = [...myRules, ...(config.rules || [])]; // prepend = highest priority
return config;
}
To apply rules to all subscriptions at once, put the script in the Global Extended Script (chain: Global Extended Configuration → Global Extended Script → Subscription Extended Configuration → Subscription Extended Script).
Advanced: manage large rule lists with RULE-SET #
To maintain hundreds of rules, define a rule-providers set and reference it with RULE-SET:
rule-providersis a map, so put it in the Extended Configuration (override/merge):
rule-providers:
my-direct:
type: http
behavior: classical # classical / domain / ipcidr — must match the list content
url: "https://your-rule-list-url/direct.list"
path: ./ruleset/my-direct.yaml
interval: 86400
- Then add a reference line in Edit Rule (prepend):
RULE-SET,my-direct,DIRECT(or push it toconfig.rulesin an Extended Script).
Rule differences: Clash Verge Rev vs the original #
- Rev is based on Mihomo and is fully compatible with the original Clash.Meta rule syntax; your existing rules carry over.
- Rev/Mihomo adds:
GEOSITE,DOMAIN-REGEX, logical rulesAND/OR/NOT,SUB-RULE, and more. - If a rule errors on Rev, check the Mihomo docs. Still on the original? Migrate to Rev.
Rule not working? Run through this checklist #
| Symptom | Cause / fix |
|---|---|
| Rule added but nothing happens | Wrong target — use a real group name from your subscription (e.g. Auto), not a nonexistent PROXY |
| Rule ignored | Order issue — move it into prepend |
| Rules gone after subscription update | You edited the subscription file — use Edit Rule / Extended Script |
Old prepend-rules does nothing | Removed from Extended Configuration in v1.7.x — use Edit Rule’s prepend |
| IP rule inaccurate or slow | A pure-IP rule is missing no-resolve — append ,no-resolve |
| Edit never takes effect | You didn’t refresh — reselect the profile or reconnect the core |
Related #
- Apply DNS/ports/proxy-groups to all subscriptions: Clash Verge Global Extended Configuration
- New here? Start with the Clash Verge tutorial
- Original vs Rev? Clash Verge Rev vs the original
- System-wide proxy: Clash Verge TUN mode setup
- On a phone? Clash Verge for Android (alternatives)
- Auto-pick the fastest node: 204 test URLs for Clash Verge