Download a Clash or Mihomo subscription YAML, replace the top-level rule-providers and rules, and write both a timestamped history file and a stable latest.yaml.
main.py: CLI entrypoint.clash_subscription_tool.py: core logic.settings.example.yaml: sample runtime config.preferences.example.yaml: sample replacement forrule-providersandrules.
- Install dependencies:
pip install -r requirements.txt- Copy and edit the example files:
copy settings.example.yaml settings.yaml
copy preferences.example.yaml preferences.yaml- Run the tool:
python main.py --config settings.yamlsettings.yaml:
subscription_url: https://example.com/sub?token=YOUR_TOKEN
preferences_file: ./preferences.yaml
output_dir: ./output
latest_filename: latest.yaml
history_filename_pattern: config-%Y%m%d-%H%M%S.yaml
request_timeout_sec: 20preferences.yaml:
rule-providers:
proxy:
type: http
behavior: classical
url: https://example.com/rules/proxy.yaml
path: ./ruleset/proxy.yaml
interval: 86400
rules:
- RULE-SET,proxy,Proxy
- MATCH,DIRECT- The subscription URL must already return Clash or Mihomo YAML.
- The tool only replaces
rule-providersandrules. Other top-level fields are preserved. - The tool prepends a generated
PROXYselect group whoseproxieslist contains all otherproxy-groupsby name. - Provider files are not downloaded by this script. Clash or Mihomo still fetches them using the final config.
- The sample rule providers in
preferences.example.yamlare based on Loyalsoldier/clash-rules.
- Commit
settings.example.yamlandpreferences.example.yaml, not your localsettings.yaml. - Do not commit the generated
output/directory because it can contain subscription secrets and node credentials. - The included
.gitignorealready excludessettings.yaml,preferences.yaml,output/, and Python cache files.