Configuration Syntax
This document defines the lexical and structural syntax rules for configuration profiles. Refer to individual section documents for field types, defaults, value ranges, and semantic validation.
File Layout & Sections
Configuration profiles are plain UTF-8 text (an optional UTF-8 BOM is accepted) and are parsed line by line (supporting both LF and CRLF line endings). Multi-line strings and backslash line continuations are not supported.
A section header [Section] occupies its own line (leading horizontal whitespace is allowed; after ], only whitespace or a #/; inline comment preceded by whitespace is permitted). Section names are matched ASCII case-insensitively. Entries appearing before the first section header belong to [General] by default. Unknown sections preserve basic syntactic structure without semantic interpretation.
The 13 official sections fall into three syntactic prototypes:
| Prototype | Applicable Sections | Parsing Rules |
|---|---|---|
| Structured Assignment | [General], [MITM], [Keystore], [Proxy], [Proxy Group], [Proxy Resource], [Plugin], [Script], [Host], [Response] (and unknown sections) | Parsed as key = value when a top-level = appears before the first top-level comma , and any inline comment; otherwise parsed as a comma-separated expression sequence |
| Structured Expression | [Rule] | Top-level key = value assignments are not parsed; the entire line is parsed as a comma-separated sequence supporting (...), [...], {...}, double quotes, and inline k=v options |
| Whitespace Expression | [URL Rewrite], [Header Rewrite] | Top-level = assignments are not parsed; tokens are split on horizontal whitespace (spaces or tabs), recognizing only double-quoted strings "..." and whitespace-preceded #/; inline comments |
Syntax Forms & Containers
| Form | Meaning | Example |
|---|---|---|
[General] | Standalone section header line | [Proxy] |
key = value | Top-level configuration assignment | log-level = info |
DOMAIN, example.com, DIRECT | Expression statement without top-level assignment | FINAL, Direct |
a, b, c | Unbracketed comma-separated sequence at the current level | dns-server = 1.1.1.1, 8.8.8.8 |
[a, b, c] | Bracketed ordered list (nestable) | alpns=[h2, http/1.1] |
k=v | Named parameter inside a sequence or (...) | tls=true, sni=example.com |
{k1=v1, k2=v2} | Brace-enclosed ordered key-value collection | headers={Host=a.com, X-Tag=1} |
(a, b) | Parenthesized nested group (for logic rules) | AND,((DOMAIN,a.com),(DEST-PORT,443)),DIRECT |
"a, b=c" | Double-quoted literal; inner symbols do not affect structure | url = "https://example.com/?a=1,2" |
Lists & Container Conventions
- List Syntax:
- Top-Level List Attributes: In
[General],[MITM], and[Host], the right-hand side of a top-level assignment accepts an unbracketed comma-separated sequencea, b, a single scalara, and a bracketed list[a, b]. - Inline Named Options: List parameters in
key=valueform (such asalpns,includes,addresses,dns,allowed-ips,server-fingerprint,realm-stun, etc.) use bracket syntax[a, b]for multiple elements, and can omit brackets askey=afor a single element without commas (e.g.,alpns=h3,includes=RemoteNodes). Double-quoted strings containing commas are not split into lists (list options do not accept comma-delimited strings).reserved=[0, 0, 0]always uses a three-byte bracketed list.
- Top-Level List Attributes: In
- Brace Key-Value Collections
{...}: Used for ordered key-value collections (such as HTTPheaders, load-balanceweights, and WireGuardpeers). Every element inside{...}must bekey=value; one trailing comma is allowed (e.g.,{a=1, b=2, }). Declaration order and duplicate keys are preserved (single-value fields use last-write-wins, while multi-value fields such as HTTP headers keep all entries in order). Bare elements without=and colon-separated objects are not allowed. WireGuardpeerssupportspeers=[{...}], and a single peer object can also omit the outer brackets aspeers={...}. - Parenthesized Groups
(...): Nestable groups used in[Rule]for compound logic rules such asAND,OR, andNOT. - Positional & Named Argument Order: Within the same parameter sequence, all positional arguments must precede
k=vnamed options.- Bare option keys allow an ASCII letter, digit,
_, or*as the first character, followed by ASCII letters, digits,_,-,.,:, or*. Keys containing other characters must be double-quoted (e.g.,weights={"^VlessReality"=5}). - URLs with query strings in positional arguments (e.g.,
https://example.com/sub?format=raw&token=1) are parsed intact as a single positional scalar because path and query characters are outside the bare-key character set. - IPv6 socket literals starting with
[and immediately followed by:portafter](e.g.,[::1]:6171,[2001:db8::1]:51820) are recognized directly as single scalar literals rather than[...]lists.
- Bare option keys allow an ASCII letter, digit,
[General]
dns-server = system, 1.1.1.1
always-real-ip = [example.com, *.apple.com]
public-http-api-listen = [::1]:6171
[Proxy]
Node = http, proxy.example.com, 443, tls=true, alpns=[h2, http/1.1], headers={User-Agent="Mozilla/5.0"}
WG = wireguard, addresses=10.0.0.2, private-key=<SECRET>, peers={public-key=<SECRET>, endpoint=wg.example.com:51820, allowed-ips=0.0.0.0/0}
[Proxy Group]
Group = select, Node, DIRECT, includes=RemoteNodes
[Rule]
AND,((DOMAIN-SUFFIX,example.com),(DEST-PORT,443)),Node,no-resolveWhitespace, Quoting, Escaping & Empty Values
- Delimiter Scope: Commas
,and equals signs=act as delimiters only at the current nesting level and outside double quotes. Commas inside double quotes or inside[...],{...}, or(...)do not split the outer sequence. - Whitespace Handling:
- Horizontal whitespace (spaces or tabs) around top-level
=and,is trimmed, and leading/trailing horizontal whitespace on bare scalars is trimmed. - In whitespace-expression sections (
[URL Rewrite],[Header Rewrite]), arguments are separated by spaces or tabs; any single argument containing whitespace must be enclosed in double quotes.
- Horizontal whitespace (spaces or tabs) around top-level
- Double-Quote Protection & Validity:
- Enclose keys, values, or arguments in paired double quotes
""when they contain commas,, equals signs=, double quotes", structural brackets ([]{}()), significant leading/trailing whitespace, or whitespace followed by#/;. - Left-hand assignment keys also support double quotes (e.g.,
"Node, #1" = ...or a[Response]regex containing a comma"^https://example\.com/a,b$" = ...). - Double quotes must wrap the entire token: placing quotes inside a bare token (e.g.,
exa"mple".com) or leaving a quote unterminated is a syntax error. After a closing quote at the current level, only a delimiter (,or whitespace), a matching closing bracket, or an inline comment may follow.
- Enclose keys, values, or arguments in paired double quotes
- Escape Sequences: Five backslash escape sequences are interpreted inside double quotes:
\": double quote"\\: backslash\\n: line feed (LF)\r: carriage return (CR)\t: horizontal tab (TAB)- Any other
\xsequence (such as\.or\/in regex patterns) preserves both the backslash and the following character literally.
- Empty Values & Empty Lists:
key =represents an empty assignment (unset value);key = ""represents an explicit empty string;key = []represents an empty list;key = [""]represents a list containing one empty string.- Empty items inside or at the end of a list are not silently dropped by the parser; their validity is determined by the target field.
[General]
suspend-ssids = "Cafe, #1", "k=v", "(Guest)"
public-http-api-key = "<SECRET>"
[Proxy]
"Node, #1" = socks, 127.0.0.1, 1080
[Header Rewrite]
^https://example\.com/ header-add X-Client "Ring 2.0"Comments
- Full-Line Comments: Lines starting with
#or;(optional leading spaces or tabs allowed). - Inline Comments: Outside double quotes and at the top level (or after a section header's
]), a#or;preceded by at least one horizontal whitespace character (space or tab) begins an inline comment to the end of the line. - Non-Comment Cases:
#and;inside double quotes are always preserved as literal characters;#or;immediately following another character without preceding whitespace remains part of the value.
# Full-line comment
; Also a full-line comment
[General]
log-level = info # Inline comment (preceded by space)
dns-server = https://dns.example.com/dns-query#route # No space before "#", part of the URL
[Header Rewrite]
^https://example\.com/ header-replace X-Note "hello # world" ; "#" inside quotes is literalMerge Directives
When overlaying plugins onto the main profile or when duplicate sections appear within a profile, %APPEND% and %INSERT% control how layers merge. Merge directives are parsed literally from source text.
Section-Level Directives
Placed on its own line as the first effective statement immediately after a [Section] header (before any configuration entries; an inline comment may follow):
- Named-Entry Sections (
[Keystore],[Proxy],[Proxy Group],[Proxy Resource],[Host],[Script]):- Default behavior is
%APPEND%: entries with matching names are replaced wholesale by the higher-priority layer, and new entries are appended to the end; - Declaring
%INSERT%prepends new entries to the beginning of the section.
- Default behavior is
- Ordered-List Sections (
[Rule],[Response],[URL Rewrite],[Header Rewrite]):- Default behavior is
%INSERT%: entries from the higher-priority layer are prepended before existing entries; - Declaring
%APPEND%appends entries to the end. In[Rule],%APPEND%always inserts new rules before theFINALrule soFINALremains the ultimate fallback.
- Default behavior is
Key-Level Directives
Placed at the beginning of the right-hand side of an assignment (key = %APPEND% value or key = %INSERT% value, followed by whitespace or a comma):
- Without a directive, the higher-priority layer replaces the existing value wholesale;
%APPEND%appends list elements to the end of the base list, while%INSERT%prepends them to the beginning;- Only the following list-typed keys support key-level
%APPEND%/%INSERT%:[General]:dns-server,always-real-ip,tun-included-routes,tun-excluded-routes,skip-proxy,hijack-dns,force-http-hostname,always-raw-tcp-hostname,suspend-ssids[MITM]:hostname,skip-hostname
[General]
skip-proxy = %APPEND% 10.0.0.0/8, 192.168.0.0/16
always-real-ip = %APPEND% [example.org, *.internal.example]
[MITM]
hostname = %INSERT% api.plugin.local
[Rule]
%APPEND%
DOMAIN,extra.example.com,DIRECT