Scope of this historical document
This document preserves historical instructions for original Clash / Clash Premium to help interpret older configurations. References to “Premium only”, unsupported features, or platform limits do not describe current Mihomo capabilities. Do not use them to overwrite your current client configuration or run permission-related commands.
For Mihomo, consult current Mihomo configuration documentation. For the graphical interface, installation, and permissions, follow the documentation for your specific client.
Clash Premium provides Python3-based scripting so users can select packet policies dynamically and flexibly.
You can control the entire rule-matching engine with a single Python script, or define Shortcuts and use them alongside regular rules. This page covers the latter; for the former, see Script.
This feature makes it possible to use scripts in rules mode. By default, SCRIPT rules perform DNS resolution. Append no-resolve to a rule to prevent resolution (for example, SCRIPT,quic,DIRECT,no-resolve).
mode: Rule
script:
engine: expr # or starlark (10x to 20x slower)
shortcuts:
quic: network == 'udp' and dst_port == 443
curl: resolve_process_name() == 'curl'
# curl: resolve_process_path() == '/usr/bin/curl'
rules:
- SCRIPT,quic,REJECTEvaluation engines
Expr, the default engine for Script Shortcuts, is 10 to 20 times faster than Starlark.
Starlark is a Python-like configuration language that can also be used for Script Shortcuts.
Variables
- network: string
- type: string
- src_ip: string
- dst_ip: string
- src_port: uint16
- dst_port: uint16
- inbound_port: uint16
- host: string
- process_path: string
WARNING
Starlark does not currently include the process_path variable.
Functions
type resolve_ip = (host: string) => string // ip string
type in_cidr = (ip: string, cidr: string) => boolean // ip in cidr
type in_ipset = (name: string, ip: string) => boolean // ip in ipset
type geoip = (ip: string) => string // country code
type match_provider = (name: string) => boolean // in rule provider
type resolve_process_name = () => string // find process name (curl .e.g)
type resolve_process_path = () => string // find process path (/usr/bin/curl .e.g)