[GH-ISSUE #4940] [Feature Request] Add subClashRules Support for Generated Clash/Mihomo Subscriptions #3462

Closed
opened 2026-10-31 20:32:36 +07:00 by bsakaguchi · 1 comment
Owner

Originally created by @zencreek on GitHub (Jun 5, 2026).
Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/4940

Currently, 3x-ui can generate Clash/Mihomo subscriptions, but the generated YAML configuration only contains the default routing rules.

For self-hosted users, it is very common to use custom routing rules such as:

  • China Direct
  • Private IP Direct
  • Custom domain routing
  • Everything else through Proxy

At the moment, users must:

  • Configure Merge rules manually in Clash Verge
  • Use an external Subconverter service
  • Modify the generated YAML after every subscription update

This makes subscription management more complicated than necessary.

Existing Behavior

3x-ui already provides subJsonRules for generated JSON subscriptions, allowing administrators to prepend custom routing rules to client configurations.

However, there is currently no equivalent feature for Clash/Mihomo subscriptions.

Describe the solution you'd like

Add a new optional setting in:

Panel Settings → Subscription → Clash/Mihomo

Example:

prepend-rules:
  - GEOIP,PRIVATE,DIRECT
  - GEOSITE,cn,DIRECT
  - GEOIP,CN,DIRECT

or

subClashRules:
  - GEOIP,PRIVATE,DIRECT
  - GEOSITE,cn,DIRECT
  - GEOIP,CN,DIRECT

When generating Clash/Mihomo subscriptions, 3x-ui should inject these rules before the final catch-all rule.

Generated example:

rules:
  - GEOIP,PRIVATE,DIRECT
  - GEOSITE,cn,DIRECT
  - GEOIP,CN,DIRECT
  - MATCH,PROXY

Optional Enhancement

Support both:

prepend-rules:

and

append-rules:

for maximum flexibility.

Although prepend-rules would be the primary use case, allowing both options would make the feature more versatile for advanced users.


Benefits

  • No need for external Subconverter services
  • No need for Clash Verge Merge configuration
  • Easier deployment for self-hosted users
  • Consistent behavior across all client devices
  • Better compatibility with Clash Verge Rev and Mihomo-based clients
  • Similar experience to the existing subJsonRules functionality

Additional Notes

This feature would be conceptually similar to the existing subJsonRules implementation, but targeted at Clash/Mihomo YAML subscriptions.

Since 3x-ui already supports custom rule injection for JSON subscriptions, extending a similar mechanism to Clash/Mihomo subscriptions would provide a consistent subscription management experience across different client types.

Related:
subJsonRules already exists for JSON subscriptions.
This request is specifically for Clash/Mihomo YAML subscriptions.

Alternatives you've considered

No response

Concrete use case

No response

Mockups, screenshots, or examples

No response

Which parts of the panel would this affect?

Subscription (share links / Clash / JSON)

Are you willing to help?

  • I'd like to implement this feature myself and open a PR.
  • I can help test once a PR is open.

Before submitting

  • I searched existing issues and this feature has not been requested.
  • This feature request is written in English.
Originally created by @zencreek on GitHub (Jun 5, 2026). Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/4940 ### Is your feature request related to a problem? Currently, 3x-ui can generate Clash/Mihomo subscriptions, but the generated YAML configuration only contains the default routing rules. For self-hosted users, it is very common to use custom routing rules such as: * China Direct * Private IP Direct * Custom domain routing * Everything else through Proxy At the moment, users must: * Configure Merge rules manually in Clash Verge * Use an external Subconverter service * Modify the generated YAML after every subscription update This makes subscription management more complicated than necessary. ### Existing Behavior 3x-ui already provides `subJsonRules` for generated JSON subscriptions, allowing administrators to prepend custom routing rules to client configurations. However, there is currently no equivalent feature for Clash/Mihomo subscriptions. ### Describe the solution you'd like Add a new optional setting in: ```text Panel Settings → Subscription → Clash/Mihomo ``` Example: ```yaml prepend-rules: - GEOIP,PRIVATE,DIRECT - GEOSITE,cn,DIRECT - GEOIP,CN,DIRECT ``` or ```yaml subClashRules: - GEOIP,PRIVATE,DIRECT - GEOSITE,cn,DIRECT - GEOIP,CN,DIRECT ``` When generating Clash/Mihomo subscriptions, 3x-ui should inject these rules before the final catch-all rule. Generated example: ```yaml rules: - GEOIP,PRIVATE,DIRECT - GEOSITE,cn,DIRECT - GEOIP,CN,DIRECT - MATCH,PROXY ``` ### Optional Enhancement Support both: ```yaml prepend-rules: ``` and ```yaml append-rules: ``` for maximum flexibility. Although `prepend-rules` would be the primary use case, allowing both options would make the feature more versatile for advanced users. --- ### Benefits * No need for external Subconverter services * No need for Clash Verge Merge configuration * Easier deployment for self-hosted users * Consistent behavior across all client devices * Better compatibility with Clash Verge Rev and Mihomo-based clients * Similar experience to the existing `subJsonRules` functionality --- ### Additional Notes This feature would be conceptually similar to the existing `subJsonRules` implementation, but targeted at Clash/Mihomo YAML subscriptions. Since 3x-ui already supports custom rule injection for JSON subscriptions, extending a similar mechanism to Clash/Mihomo subscriptions would provide a consistent subscription management experience across different client types. ```text Related: subJsonRules already exists for JSON subscriptions. This request is specifically for Clash/Mihomo YAML subscriptions. ``` ### Alternatives you've considered _No response_ ### Concrete use case _No response_ ### Mockups, screenshots, or examples _No response_ ### Which parts of the panel would this affect? Subscription (share links / Clash / JSON) ### Are you willing to help? - [ ] I'd like to implement this feature myself and open a PR. - [ ] I can help test once a PR is open. ### Before submitting - [x] I searched [existing issues](../issues?q=is%3Aissue) and this feature has not been requested. - [x] This feature request is written in English.
bsakaguchi 2026-10-31 20:32:36 +07:00
Author
Owner

@github-actions[bot] commented on GitHub (Jun 5, 2026):

Good news — this feature is already implemented in the current codebase.

How to enable it

Go to Panel Settings → Subscription → General tab. Scroll to the Clash / Mihomo section. You will find two controls:

  1. Enable Routing (subClashEnableRouting) — toggle this on. Rules are only injected when this is enabled.
  2. Routing Rules (subClashRules) — paste your custom rules here, one per line (no YAML header needed).

Input format — plain text, one rule per line:

GEOIP,PRIVATE,DIRECT
GEOSITE,cn,DIRECT
GEOIP,CN,DIRECT

Or as a YAML sequence:

- GEOIP,PRIVATE,DIRECT
- GEOSITE,cn,DIRECT
- GEOIP,CN,DIRECT

How rules are applied

Custom rules are prepended before the catch-all MATCH,PROXY rule, producing exactly the output you described. If your custom rules already include a MATCH rule, they replace the defaults entirely rather than being prepended.

Implementation references

  • web/entity/entity.go — SubClashRules / SubClashEnableRouting fields
  • web/service/setting.go — GetSubClashRules() / GetSubClashEnableRouting()
  • sub/subClashService.go — mergeClashRulesYAML() / mergeClashRules()
  • frontend/src/pages/settings/SubscriptionGeneralTab.tsx — UI controls
<!-- gh-comment-id:4627463416 --> @github-actions[bot] commented on GitHub (Jun 5, 2026): Good news — this feature is **already implemented** in the current codebase. **How to enable it** Go to Panel Settings → Subscription → General tab. Scroll to the Clash / Mihomo section. You will find two controls: 1. **Enable Routing** (`subClashEnableRouting`) — toggle this **on**. Rules are only injected when this is enabled. 2. **Routing Rules** (`subClashRules`) — paste your custom rules here, one per line (no YAML header needed). **Input format** — plain text, one rule per line: ``` GEOIP,PRIVATE,DIRECT GEOSITE,cn,DIRECT GEOIP,CN,DIRECT ``` Or as a YAML sequence: ```yaml - GEOIP,PRIVATE,DIRECT - GEOSITE,cn,DIRECT - GEOIP,CN,DIRECT ``` **How rules are applied** Custom rules are prepended before the catch-all `MATCH,PROXY` rule, producing exactly the output you described. If your custom rules already include a `MATCH` rule, they replace the defaults entirely rather than being prepended. **Implementation references** - `web/entity/entity.go` — `SubClashRules` / `SubClashEnableRouting` fields - `web/service/setting.go` — `GetSubClashRules()` / `GetSubClashEnableRouting()` - `sub/subClashService.go` — `mergeClashRulesYAML()` / `mergeClashRules()` - `frontend/src/pages/settings/SubscriptionGeneralTab.tsx` — UI controls
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
MHSanaei/3x-ui#3462
No description provided.