New Rule Format
The next-generation, YAML-authored ClearURLs rule format.
This page describes the next-generation ClearURLs rule format. It is designed for human authoring and review, while still allowing efficient transport after compilation.
The recommended workflow is:
- Author rule catalogs in YAML.
- Validate and compile them to a canonical JSON representation.
- Minify and compress the generated JSON for distribution.
The YAML file is the authoring format. The compiled JSON file is the transport format.
The new format replaces the old split between rules, rawRules, referralMarketing, and redirections
with a unified rule model.
Design Goals
The new rule format is built around the following goals:
- Human-readable and easy to edit
- Extensible without introducing new top-level arrays for every new feature
- Explicit support for
description,preprocessors,exceptions,requestTypes, andreplacePattern - Compact authoring syntax for simple field-removal rules
- Easy compilation to a transport-friendly JSON artifact
File Structure
Every rules file starts with a version and a defaults block.
versionidentifies the format revisiondefaultscontains standard values that apply to rules unless overriddenproviderscontains all provider definitions
Example of the new rule format
version: 2
defaults:
active: true
requestTypes: all
preprocessors: []
exceptions: []
providers:
google:
urlPattern: '^https?:\/\/(?:[a-z0-9-]+\.)*?google(?:\.[a-z]{2,}){1,}'
forceRedirection: true
exceptions:
- '^https?:\/\/mail\.google\.com\/'
rules:
- ved
- id: 'remove-referrer'
match: 'referrer'
description: 'Remove referrer marker'
- id: 'redirect-target'
kind: redirection
match: '^https?:\/\/(?:[a-z0-9-]+\.)*?google(?:\.[a-z]{2,}){1,}\/url\?.*?(?:url|q)=([^&]+)'
preprocessors:
- type: doubleUrlDecode
inputs: [1]
action:
type: redirect
replacePattern: '§1§'Top-level Keys
version
The format version of the rules file.
Current value:
2
defaults
Defines default values for rule-level properties.
Supported defaults:
activedescriptionrequestTypespreprocessorsexceptions
Defaults are applied when the same property is omitted in a rule object.
They should stay in the defaults block and must not be repeated on every rule unless a rule explicitly overrides them.
providers
Holds all provider definitions.
Each provider groups rules that apply under the same urlPattern.
Provider Definition
Every provider supports the following keys:
urlPattern(required)completeProvider(optional)forceRedirection(optional)methods(optional)exceptions(optional)rules(optional)
urlPattern
A regular expression that must match the URL before provider rules are considered.
completeProvider
If enabled and domain blocking is active in the runtime, the matching request can be blocked completely.
forceRedirection
Signals that redirections should be enforced by the integration layer for main_frame requests.
methods
Optional list of HTTP methods for which the provider should apply.
exceptions
Provider-level URL exceptions. If the request URL matches one of these expressions, no further processing happens for this provider.
rules
The provider's rule list. All rule kinds are expressed in this single list.
Rule Definition
A rule can either be written in short form or long form.
Short Form
The short form is intended for simple field-removal rules that use only defaults. It should only be used when all of the following are true:
- the rule kind is
field - the action is
remove - the rule does not override
active,description,exceptions,requestTypes, orpreprocessors - the rule is not marked as
referralMarketing
Short form
rules:
- utm_source
- fbclidThis is equivalent to the following long-form rule:
rules:
- id: remove-utm-source
kind: field
match: 'utm_source'
action:
type: removewith all other fields taken from defaults.
Short form keeps the catalog compact and is the preferred notation for ordinary field-removal rules.
The engine generates deterministic fallback ids for short-form rules, but these ids are not a persistence contract.
Use the long form with an explicit id whenever rule-level toggles need to survive future catalog edits.
Long Form
Use the long form whenever you need metadata or non-default behavior.
Long-form rules must declare an explicit id.
Supported keys:
idaliaseskindmatchactivedescriptionexceptionsrequestTypespreprocessorsreferralMarketingaction
id
The provider-local stable rule identifier.
- Required for every long-form rule
- Must match
^[a-z0-9][a-z0-9_-]*$ - Must be unique within the provider across both rule ids and aliases
The runtime namespaces this id as sourceId::providerId::ruleId.
This namespaced runtime id is what the core engine exposes for persistent rule toggles.
aliases
Optional previous names for a rule.
- Must follow the same slug syntax as
id - Must not contain the rule's own
id - Must be unique within the provider across both rule ids and aliases
Aliases allow a renamed rule to keep existing persisted toggles working.
kind
Supported rule kinds:
fieldrawredirection
If omitted, field is assumed.
match
The regular expression string for the rule.
fieldrules operate on query and fragment keysrawrules operate on the full URL stringredirectionrules operate on the full URL string
For field rewrite rules, the matched key stays unchanged and the action rewrites the corresponding value.
The current value is exposed to preprocessors and replacePattern as §1§.
active
Whether the rule is active.
If omitted, the rule inherits the value from defaults.active.
description
Optional human-readable explanation for the rule.
exceptions
Rule-level exceptions expressed as regular expressions. If one matches, the rule is skipped.
requestTypes
Defines for which request types the rule applies.
Supported values:
all- a list such as
['main_frame', 'sub_frame']
Example
requestTypes: allrequestTypes: ['main_frame', 'sub_frame']Use all whenever the rule should apply to every request type.
preprocessors
Preprocessors transform captured regex groups before the action is executed.
Every preprocessor defines:
typeinputs
The inputs field controls which capture groups are processed.
Supported forms:
all[1][1, 2]
Common supported preprocessor types in the core engine:
urlEncodeurlDecodedoubleUrlEncodedoubleUrlDecodebase64Encode
Example
preprocessors:
- type: base64Encode
inputs: [1]
- type: doubleUrlDecode
inputs: [2]preprocessors:
- type: doubleUrlDecode
inputs: allreferralMarketing
Marks a field rule as a referral marketing rule. These rules are only applied when referral marketing is not allowed by the runtime configuration.
Actions
Every rule resolves to an action.
Supported action types:
removeredirectrewrite
remove
Deletes the matched field or removes the raw match from the URL.
Example
action:
type: removeredirect
Builds a new target URL from regex capture groups and navigates to it.
Example
action:
type: redirect
replacePattern: '§1§'rewrite
Builds a new URL string from regex capture groups without implying a redirect-specific runtime behavior.
For field rules, rewrite keeps the matched query or fragment key and replaces only its value.
For raw rules, rewrite rebuilds the full URL string from regex capture groups.
Example
action:
type: rewrite
replacePattern: '§1§://§2§.clearurls.xyz/'Field rewrite
rules:
- id: rewrite-token
match: token
preprocessors:
- type: base64Encode
inputs: [1]
action:
type: rewrite
replacePattern: 'wrapped-§1§'This keeps the key token and rewrites a value such as test to wrapped-dGVzdA==.
replacePattern
The replacePattern supports placeholder substitution based on regex capture groups.
For example:
replacePattern: '§1§://§2§.clearurls.xyz/'with capture groups:
['https', 'test']results in:
https://test.clearurls.xyz/This makes it possible to rebuild a target URL from multiple capture groups instead of being limited to the first group only.
Complete Example
Example provider using the new rule model
version: 2
defaults:
active: true
requestTypes: all
preprocessors: []
exceptions: []
providers:
example:
urlPattern: '^https?:\/\/(?:[a-z0-9-]+\.)*?example\.com'
forceRedirection: true
rules:
- utm_source
- id: 'referral-tag'
match: 'tag'
referralMarketing: true
- id: 'raw-ref'
kind: raw
match: '/ref=([^/?]*)'
action:
type: rewrite
replacePattern: '/clean/§1§'
- id: 'redirect-target'
kind: redirection
match: '^https?:\/\/(?:[a-z0-9-]+\.)*?example\.com\/go\?.*target=([^&]+)'
preprocessors:
- type: doubleUrlDecode
inputs: [1]
action:
type: redirect
replacePattern: '§1§'Migration from the Old Format
The recommended migration is:
- Read the legacy JSON catalog.
- Convert each provider to the new YAML rule model.
- Convert:
- old
rulestokind: field - old
rawRulestokind: raw - old
redirectionstokind: redirection - old
referralMarketingentries tokind: fieldwithreferralMarketing: true
- old
- Keep provider-level
exceptionsas provider-level exceptions. - Move global defaults that repeat across many rules into the
defaultsblock instead of copying them into each rule. - Add explicit long-form
idvalues for every rule that should support stable persisted toggles.
Conversion Tool
The core package contains an interactive converter that migrates a legacy JSON catalog into the new YAML format.
Run it from core:
npm run convert-rules -- /path/to/legacy-rules.json /path/to/new-rules.yamlThe tool asks for default values for the new rule fields and then writes the converted YAML file.
Additional Tooling
The core package also contains two non-interactive export tools for the new YAML format.
Convert YAML to the transport-oriented minified JSON representation:
npm run new-rules-to-json -- /path/to/new-rules.yaml /path/to/new-rules.min.jsonConvert YAML back to the legacy ClearURLs JSON dataset:
npm run new-rules-to-legacy -- /path/to/new-rules.yaml /path/to/new-rules.legacy.jsonAttention
The legacy export is behavior-preserving, not identity-preserving.
Rule id and aliases are intentionally dropped because the old format has no place to store them.
If the YAML file contains behavioral features that cannot be represented in the old format, such as preprocessors,
the conversion fails instead of silently changing the rules.
Last updated on