Skip to content

ByteTrue/sub2mihomo

Repository files navigation

sub2mihomo

将 v2ray/xray 订阅链接转换为 mihomo(Clash Meta)YAML 配置文件。

一个轻量级 CLI 工具,接收 base64 编码的订阅 URL(来自 3x-ui 等面板),输出开箱即用的 mihomo 配置文件——无需服务端订阅转换。

功能

  • 协议支持:VLESS(+ Reality)、VMess、Trojan、Shadowsocks
  • 智能解码:自动识别 base64 / 纯文本订阅内容
  • 内置规则:AI 服务、流媒体、Telegram、广告拦截等代理分组
  • 规则提供者:使用 Loyalsoldier/clash-rules 保持域名/IP 列表最新
  • 自定义模板:通过 YAML 模板覆盖 DNS、规则和代理组
  • 单一二进制:无运行时依赖,可交叉编译到任意平台

安装

下载预编译版本

Releases 下载对应平台的二进制文件。

Linux / macOS 下载后需要添加执行权限:

chmod +x sub2mihomo-linux-amd64

macOS 首次运行如果被 Gatekeeper 拦截,执行:

xattr -d com.apple.quarantine sub2mihomo-darwin-arm64

从源码安装

go install github.com/ByteTrue/sub2mihomo@latest

或手动编译:

git clone https://github.com/ByteTrue/sub2mihomo.git
cd sub2mihomo
go build -o sub2mihomo .

使用方式

交互模式

直接运行(不带任何参数),程序会引导你逐步完成转换:

$ sub2mihomo

sub2mihomo - convert v2ray subscriptions to mihomo config
https://github.com/ByteTrue/sub2mihomo

? Enter subscription URL or paste share link:
> https://panel:2096/sub/token

  Fetching subscription...
  Found 3 proxies:
    [1] vless-reality (vless) 1.2.3.4:443
    [2] vmess-ws (vmess) 5.6.7.8:8080
    [3] ss-node (ss) 9.10.11.12:8388

? Output file path (config.yaml):
>

? Custom template path (leave empty to skip):
>

  Generated config with 3 proxies -> config.yaml

命令行模式

# 从订阅 URL 转换
sub2mihomo -url "https://your-panel:2096/sub/token" -o config.yaml

# 从 stdin 管道输入分享链接
echo "vless://uuid@host:port?params#name" | sub2mihomo -o config.yaml

# 使用自定义模板
sub2mihomo -url "https://..." -template my-template.yaml -o config.yaml

# 详细输出
sub2mihomo -url "https://..." -o config.yaml -v

参数

参数 说明 默认值
-url 订阅 URL (必需,或通过 stdin 输入)
-o 输出文件路径 stdout
-template 自定义模板 YAML (内置配置)
-v 详细日志 false

默认配置

生成的配置包含:

代理组

分组 类型 用途
proxy select 主代理选择器
auto-select url-test 自动选择最快节点
fallback fallback 自动故障转移
AI select ChatGPT、Claude、Gemini、Copilot
streaming select YouTube、Netflix、Disney+、Spotify
telegram select Telegram
ad-block select 广告拦截(REJECT)

DNS:fake-ip 模式,国内 DoH(AliDNS、DNSPod)+ 国外 DoH 回退(Cloudflare、Google)

规则:GEOIP CN → DIRECT,基于规则提供者的域名/IP 匹配,MATCH → proxy

自定义模板

创建 YAML 模板来覆盖默认的 DNS、规则和代理组。使用 __all_proxies__ 作为占位符,会自动展开为所有解析到的代理节点名称。

dns:
  enable: true
  enhanced-mode: redir-host
  nameserver:
    - 8.8.8.8

rules:
  - DOMAIN-SUFFIX,google.com,proxy
  - MATCH,DIRECT

proxy-groups:
  - name: my-group
    type: select
    proxies:
      - __all_proxies__
      - DIRECT

支持的协议

协议 链接格式 备注
VLESS vless://uuid@host:port?params#name Reality、TCP、WS、gRPC
VMess vmess://base64-json WS、gRPC、TLS
Trojan trojan://password@host:port?params#name TCP、WS
Shadowsocks ss://base64(method:pass)@host:port#name SIP002 + 旧版格式

编译

# 当前平台
go build -o sub2mihomo .

# 交叉编译
GOOS=linux   GOARCH=amd64 go build -o sub2mihomo-linux-amd64 .
GOOS=darwin  GOARCH=arm64 go build -o sub2mihomo-darwin-arm64 .
GOOS=windows GOARCH=amd64 go build -o sub2mihomo-windows-amd64.exe .

测试

go test ./...

许可证

MIT

About

Convert v2ray/xray subscriptions to mihomo (Clash Meta) config

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages