Skip to content

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:

PrototypeApplicable SectionsParsing 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 ​

FormMeaningExample
[General]Standalone section header line[Proxy]
key = valueTop-level configuration assignmentlog-level = info
DOMAIN, example.com, DIRECTExpression statement without top-level assignmentFINAL, Direct
a, b, cUnbracketed comma-separated sequence at the current leveldns-server = 1.1.1.1, 8.8.8.8
[a, b, c]Bracketed ordered list (nestable)alpns=[h2, http/1.1]
k=vNamed parameter inside a sequence or (...)tls=true, sni=example.com
{k1=v1, k2=v2}Brace-enclosed ordered key-value collectionheaders={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 structureurl = "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 sequence a, b, a single scalar a, and a bracketed list [a, b].
    • Inline Named Options: List parameters in key=value form (such as alpns, includes, addresses, dns, allowed-ips, server-fingerprint, realm-stun, etc.) use bracket syntax [a, b] for multiple elements, and can omit brackets as key=a for 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.
  • Brace Key-Value Collections {...}: Used for ordered key-value collections (such as HTTP headers, load-balance weights, and WireGuard peers). Every element inside {...} must be key=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. WireGuard peers supports peers=[{...}], and a single peer object can also omit the outer brackets as peers={...}.
  • Parenthesized Groups (...): Nestable groups used in [Rule] for compound logic rules such as AND, OR, and NOT.
  • Positional & Named Argument Order: Within the same parameter sequence, all positional arguments must precede k=v named 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 :port after ] (e.g., [::1]:6171, [2001:db8::1]:51820) are recognized directly as single scalar literals rather than [...] lists.
ini
[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-resolve

Whitespace, 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.
  • 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.
  • 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 \x sequence (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.
ini
[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.
ini
# 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 literal

Merge 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.
  • 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 the FINAL rule so FINAL remains the ultimate fallback.

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
ini
[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