Generate a ready-to-use sing-box config.json from a subscription URL or local subscription file.
English | 简体中文
sing-box-subscribe-cli is a small, pure Go command-line tool. It is useful for local scripts, servers, CI jobs, and any workflow where you want to turn a subscription into a sing-box configuration without running a web service.
- Read subscriptions from HTTP/HTTPS URLs or local files.
- Parse common Clash YAML subscriptions with a
proxieslist. - Convert Clash
vmess,vless,trojan,ss,ssr,hysteria,hysteria2,tuic,wireguard,socks5,http, andanytlsnodes to sing-box outbounds. - Reuse existing sing-box
outboundsfrom a subscription source. - Merge generated nodes into bundled sing-box JSON templates.
- Expand
{all}in selector and urltest outbound lists. - Support selector/urltest
filterrules in templates. - Filter nodes by protocol or name.
- Add a prefix to generated node tags.
- Output only generated nodes when you do not want to merge a template.
This tool generates configuration files. It does not run sing-box for you.
Install the CLI, then generate a config from a subscription:
sing-box-sub \
'https://example.com/api/v1/client/subscribe?token=REDACTED' \
--out config.jsonValidate the result when the tools are available:
jq empty config.json
sing-box check -c config.jsonInstall with Homebrew:
brew install rainbend/tap/sing-box-subscribe-cliCheck the installed command:
sing-box-sub versionInstall the latest release:
curl -fsSL https://raw.githubusercontent.com/rainbend/sing-box-subscribe-cli/main/install.sh | bashThe installer supports linux/amd64 and linux/arm64. It installs sing-box-sub to /usr/local/bin by default and may ask for sudo.
Install to a custom directory:
curl -fsSL https://raw.githubusercontent.com/rainbend/sing-box-subscribe-cli/main/install.sh | INSTALL_DIR="$HOME/.local/bin" bashInstall a specific version:
curl -fsSL https://raw.githubusercontent.com/rainbend/sing-box-subscribe-cli/main/install.sh | VERSION=v1.0.0 bashUse ExecStartPre in a systemd unit when you want to regenerate the sing-box config before starting sing-box:
[Unit]
Description=sing-box service
Documentation=https://sing-box.sagernet.org
After=network.target nss-lookup.target network-online.target
[Service]
CapabilityBoundingSet=CAP_NET_ADMIN CAP_NET_BIND_SERVICE CAP_SYS_PTRACE CAP_DAC_READ_SEARCH
AmbientCapabilities=CAP_NET_ADMIN CAP_NET_BIND_SERVICE CAP_SYS_PTRACE CAP_DAC_READ_SEARCH
ExecStartPre=/usr/local/bin/sing-box-sub --out /etc/sing-box/config.json 'https://example.com/api/v1/client/subscribe?token=REDACTED'
ExecStart=/usr/bin/sing-box -D /var/lib/sing-box -C /etc/sing-box run
ExecReload=/bin/kill -HUP $MAINPID
Restart=on-failure
RestartSec=10s
LimitNOFILE=infinity
[Install]
WantedBy=multi-user.targetIf ExecStartPre fails, systemd stops the startup before launching sing-box. Make sure /usr/local/bin/sing-box-sub exists, the service can write /etc/sing-box/config.json, and the subscription URL is reachable when the service starts.
Download the matching Windows .zip from the GitHub Releases page, extract sing-box-sub.exe, and place it in a directory listed in PATH.
Check the installed command:
sing-box-sub.exe versionPull the image from GitHub Packages:
docker pull ghcr.io/rainbend/sing-box-subscribe-cli:latest
docker pull ghcr.io/rainbend/sing-box-subscribe-cli:v1.0.0Run the CLI with the current directory mounted as /work:
docker run --rm \
-v "$PWD:/work" \
ghcr.io/rainbend/sing-box-subscribe-cli:latest \
./subscription.yaml --out config.jsonThe image supports linux/amd64 and linux/arm64.
Generate from a subscription URL:
sing-box-sub \
'https://example.com/api/v1/client/subscribe?token=REDACTED' \
--out config.jsonYou can also pass the source with --url:
sing-box-sub \
--url 'https://example.com/api/v1/client/subscribe?token=REDACTED' \
--out config.jsonGenerate from a local subscription file:
sing-box-sub ./subscription.yaml --out config.jsonUse another bundled template:
sing-box-sub ./subscription.yaml \
--template config_template_groups_rule_set_tun.json \
--out config.jsonUse your own template file:
sing-box-sub ./subscription.yaml \
--template ./my-template.json \
--out config.jsonWrite only generated outbounds:
sing-box-sub ./subscription.yaml --only-nodes --out nodes.jsonFilter or rename generated nodes:
sing-box-sub ./subscription.yaml \
--prefix "Home - " \
--exclude-protocol "ssr" \
--exclude-node-name "expired|test" \
--out config.jsonList bundled templates:
sing-box-sub listBundled templates:
config_template_groups_rule_set_tun.jsonconfig_template_groups_rule_set_tun_fakeip.jsonconfig_template_no_groups_tun_VN.jsonsb-config-1.12.jsonsb-config-1.14.json
The default template is sb-config-1.14.json.
When --template is a bundled template name, the bundled template is used first. Template paths such as ./template.json and /path/to/template.json are also supported, as are HTTP/HTTPS template URLs.
The bundled templates and rule layout are inspired by Toperlock/sing-box-subscribe.
sing-box-sub [subscription URL or file] [flags]
sing-box-sub list
sing-box-sub version
Common flags:
| Flag | Default | Description |
|---|---|---|
--url |
empty | Subscription URL or local subscription file. |
--template |
sb-config-1.14.json |
Template name, template path, or template URL. |
--out |
config.json |
Output file path. Use - for stdout. |
--tag |
tag_1 |
Subscription group tag. |
--ua |
clashmeta |
User-Agent for subscription and template HTTP requests. |
--prefix |
empty | Prefix for generated outbound tags. |
--exclude-protocol |
ssr |
Protocols to skip, separated by commas. |
--exclude-node-name |
empty | Node tag substrings to skip, separated by commas or ` |
--only-nodes |
false |
Write generated outbounds only. |
--timeout |
60s |
HTTP request timeout. |
Requirements:
- Go 1.24 or newer
make, optional
Build:
git clone https://github.com/rainbend/sing-box-subscribe-cli.git
cd sing-box-subscribe-cli
make buildThe binary is written to ./bin/sing-box-sub.
Run tests:
go test ./...Build a local container image:
docker build \
--build-arg VERSION=dev \
-t sing-box-subscribe-cli:dev .Maintainers publish a release by pushing a Git tag:
git tag v1.0.0
git push origin v1.0.0The release workflow runs tests, uses GoReleaser to build Linux, macOS, and Windows archives for amd64 and arm64, injects the tag into sing-box-sub version, uploads the artifacts and checksums.txt to GitHub Releases, and updates the Homebrew tap formula.
Container images are published to GitHub Packages. Version tags publish <version> and latest; pushes to main publish main and a sha-... tag.
Subscription URLs often contain private tokens. Do not share real subscription URLs, tokens, or node details in issues, documentation, tests, or fixtures. Use redacted examples or local fixtures when reproducing behavior.
Licensed under the Apache License 2.0.