Confirm the scope: this is an OpenClash override, not a subscription edit
This guide solves one task: adding a custom routing rule through OpenClash. The verified scope is OpenWrt LuCI, OpenClash stable v0.47.156, and the Mihomo core. Do not copy the menu path into Clash for Windows, Clash Verge Rev, FlClash, or a standalone Mihomo setup; older OpenClash releases may also label the controls differently.
Set the proxy mode to rule before testing. Mihomo evaluates normal routing rules from top to bottom in rule mode. The global and direct modes cannot demonstrate that a normal custom rule matched. In LuCI, open “Services → OpenClash → Overwrite Settings → Rules Setting,” enable “Custom Clash Rules,” and the “Priority” and “Extended” editors will appear.
An override does not rewrite the subscription:OpenClash injects the custom content into a temporary runtime YAML when it starts. It does not append the rule directly to the original subscription file. Keep custom rules in the overwrite page so a subscription refresh does not turn into a manual edit of generated configuration.
Priority and Extended differ by their final insertion point
Both editors store YAML, but OpenClash merges them at different positions. The bundled templates recommend an object with a top-level rules: array and can also define rule-providers: or sub-rules:. The v0.47.156 merge code accepts a root YAML array, but that form carries rules only. rule-providers require the object form plus an array-valued rules key, which may be empty. sub-rules also require the object form, but their merge does not require a rules key. New users should follow the bundled template because it is easier to inspect and extend safely.
| Editor | Stored file | Insertion in v0.47.156 | Best use |
|---|---|---|---|
| Priority | /etc/openclash/custom/openclash_custom_rules.list | At the top of the final rules array | A narrow exception that must match before subscription rules |
| Extended | /etc/openclash/custom/openclash_custom_rules_2.list | Before the last original entry containing DST-PORT,80; otherwise before the first original MATCH/FINAL; otherwise before the first original two-letter-country GEOIP rule; appended only when none exists | An addition that should retain the subscription's earlier detailed rules |
The v0.47.156 port anchor is a substring match:DST-PORT,8080 can also be selected because it contains DST-PORT,80. The GEOIP fallback recognizes two-letter country rules such as GEOIP,CN,.... Recheck the merged order after an OpenClash upgrade.
Extended does not simply mean “after MATCH.” The script records anchors from the original subscription before it inserts either custom file. Because the first matching rule wins, keep Priority entries narrow and explicit. A broad MATCH or FINAL in Priority can consume nearly every request before the subscription rules get a chance to run.
Start with one testable Priority rule
The example below sends one exact hostname directly. app.example.net is a placeholder: replace it with the real hostname observed in the connection log. DIRECT is a built-in Mihomo outbound, which keeps an unknown custom group name from confusing the first test.
OpenClash Priority rulesrules:
- DOMAIN,app.example.net,DIRECT
- Reproduce the original behavior and record the hostname, matched rule, and selected policy group.
- Back up both custom-rule files with the commands later in this guide. If a file does not yet exist, record that the switch was off and the editor was empty.
- Enable Custom Clash Rules and paste the YAML into the Priority editor.
- Preserve the two-space indentation and do not change DNS, Fake-IP, subscriptions, or proxy mode during this test.
- Select “Apply Settings” once to save the content and perform a testable restart.
The rule target must exist exactly:the final field must be a supported built-in target such as DIRECT, REJECT, GLOBAL, REJECT-DROP, PASS, or COMPATIBLE, or exactly match a current proxy group, proxy, or sub-rule name. These are not all network outbounds: PASS continues rule matching, while REJECT rejects the request. OpenClash skips an unknown target and logs Skiped The Custom Rule Because Group & Proxy Not Found.
Use Extended only when earlier subscription rules should remain ahead
The Extended editor is useful when the subscription's detailed rules should run first and the custom item should fill a later gap. Treat this as a separate experiment: remove the Priority example before testing it, and replace updates.example.net with a real domain. Running both examples together would hide which editor supplied the match.
OpenClash Extended rulesrules:
- DOMAIN-SUFFIX,updates.example.net,DIRECT
- Remove the Priority test item while leaving every other variable unchanged.
- Paste this YAML into Extended and select Apply Settings.
- Find the entry in the runtime rules and compare it with the last original entry containing
DST-PORT,80, the firstMATCH/FINAL, or the first two-letter-country rule such asGEOIP,CN,.... - Make a real request and inspect the log. If an earlier subscription rule already matches, the Extended entry will not run; that is normal first-match behavior, not a save failure.
Judge Extended by the merged position:text in the editor alone is not proof. Confirm its order in the runtime rules, then confirm one actual connection.
Verify the startup log, merged order, and a real request
In v0.47.156, “Commit Settings” saves the form and custom files without restarting OpenClash. “Apply Settings” saves the changes, enables OpenClash, and restarts it. If you intend to test immediately, one Apply is sufficient; a separate Commit first is unnecessary. A short interruption during restart is expected, but a service that never returns to running is not.
- Wait for OpenClash to return to a running state, then read the first YAML, rule, or group error in the startup log.
- Inspect the runtime configuration or rule list and confirm that
DOMAIN,app.example.net,DIRECTappears at the expected position. - Request the exact hostname from a real client and check the rule type, payload, and final outbound in the connection log.
- Test an unrelated site to confirm that the remaining subscription rules still behave normally.
A saved file does not prove that the rule was loaded, and a rule visible in the runtime YAML does not prove that a request matched it. The startup result, merged order, and actual connection must agree before the change is considered verified.
When a rule does not work, begin with mode and YAML
| Symptom | Check first | Next action |
|---|---|---|
| No behavior change after saving | Whether only Commit Settings was used | Use Apply Settings when a short restart is acceptable |
| Rule is present but never matches | rule mode and an earlier matching entry | Return to rule mode and test one exact hostname |
| YAML error during startup | Indentation, colon, and list markers | Restore the bundled structure and add only one rules item |
| Group & Proxy Not Found | Spelling and case of the final field | Use an existing group or supported rule target |
RULE-SET does not match | Provider definition, download result, and compatible behavior | Prove the path with DOMAIN first, then add the provider separately |
Both custom files can define rule-providers and sub-rules, but same-name definitions introduce overwrite risk during merging. Do not paste a large provider block into both editors without comparing the final runtime YAML. The one-hostname test in this guide does not require a provider.
Change one variable at a time:if the Priority rule does not match, do not simultaneously replace the core, DNS, Fake-IP mode, node, and subscription. Establish the proxy mode, YAML syntax, rule target, and actual hostname first.
Back up both custom files and keep a clear rollback path
Before the first edit, copy both custom files over SSH. These commands copy only when the source exists, but they overwrite a same-name .bak; choose a new backup name if one already exists.
OpenWrt Shelltest -f /etc/openclash/custom/openclash_custom_rules.list && cp /etc/openclash/custom/openclash_custom_rules.list /root/openclash_custom_rules.list.bak
test -f /etc/openclash/custom/openclash_custom_rules_2.list && cp /etc/openclash/custom/openclash_custom_rules_2.list /root/openclash_custom_rules_2.list.bak
After checking that the backups contain the intended text, restore any backup that exists with:
OpenWrt Shell · restoretest -f /root/openclash_custom_rules.list.bak && cp /root/openclash_custom_rules.list.bak /etc/openclash/custom/openclash_custom_rules.list
test -f /root/openclash_custom_rules_2.list.bak && cp /root/openclash_custom_rules_2.list.bak /etc/openclash/custom/openclash_custom_rules_2.list
You can also restore the previous text in LuCI or disable Custom Clash Rules, then use Apply Settings to rebuild the runtime configuration. After restoring files over SSH, reload LuCI and confirm the text before applying it so a stale browser form does not overwrite the restored file. Do not delete the subscription and do not treat a generated runtime YAML as the long-term source of truth.
Completion criteria:the YAML parses, the insertion point matches the chosen editor, the rule target exists, OpenClash restarts cleanly, a real request takes the intended action or path, unrelated routing remains intact, and both original custom files can be restored.
For current OpenClash and Mihomo-related platform downloads, use the site's download page. Replacing a client does not substitute for checking merged rule order and connection logs.
Official sources and version scope
- OpenClash v0.47.156 official release
- OpenClash v0.47.156 overwrite UI source
- OpenClash v0.47.156 official Simplified Chinese UI translations
- OpenClash v0.47.156 custom-rule merge source
- OpenClash v0.47.156 priority custom-rule template
- OpenClash v0.47.156 extended custom-rule template
- Mihomo official routing-rule documentation
- Mihomo official general configuration
Version numbers, filenames, and interface labels can change. Confirm them in the linked project documentation before making changes.