CLI Reference

Back to README

The adblock-compiler CLI is the primary entry-point for compiling filter lists locally with full control over the transformation pipeline, HTTP fetching, filtering, and output.

Installation

# Run directly with Deno (no install)
deno run --allow-read --allow-write --allow-net jsr:@jk-com/adblock-compiler/cli -c config.json -o output.txt

# Install globally
deno install --allow-read --allow-write --allow-net -n adblock-compiler jsr:@jk-com/adblock-compiler/cli

Usage

adblock-compiler [options]

Options

General

FlagShortTypeDescription
--config <file>-cstringPath to the compiler configuration file
--input <source>-istring[]URL or file path to compile (repeatable)
--input-type <type>-thosts|adblockInput format [default: hosts]
--verbose-vbooleanEnable verbose logging
--benchmark-bbooleanShow performance benchmark report
--use-queue-qbooleanSubmit job to async queue (requires worker API)
--priority <level>standard|highQueue priority [default: standard]
--versionbooleanShow version number
--help-hbooleanShow help

Either --config or --input must be provided (but not both).


Output

FlagShortTypeDescription
--output <file>-ostringOutput file path [required unless --stdout]
--stdoutbooleanWrite output to stdout instead of a file
--appendbooleanAppend to output file instead of overwriting
--format <format>stringOutput format
--name <file>stringCompare output against an existing file and print a summary of added/removed rules
--max-rules <n>numberTruncate output to at most n rules

--stdout and --output are mutually exclusive.


Transformation Control

When no transformation flags are specified, the default pipeline is used: RemoveCommentsDeduplicateCompressValidateTrimLinesInsertFinalNewLine

FlagTypeDescription
--no-commentsbooleanSkip the RemoveComments transformation
--no-deduplicatebooleanSkip the Deduplicate transformation
--no-compressbooleanSkip the Compress transformation
--no-validatebooleanSkip the Validate transformation
--allow-ipbooleanReplace Validate with ValidateAllowIp (keeps IP-address rules)
--invert-allowbooleanAppend the InvertAllow transformation
--remove-modifiersbooleanAppend the RemoveModifiers transformation
--convert-to-asciibooleanAppend the ConvertToAscii transformation
--transformation <name>string[]Override the entire pipeline (repeatable). When provided, all other transformation flags are ignored.

Available transformation names for --transformation:

NameDescription
RemoveCommentsRemove ! and # comment lines
DeduplicateRemove duplicate rules
CompressConvert hosts-format rules to adblock syntax and remove redundant entries
ValidateRemove dangerous or incompatible rules (strips IP-address rules)
ValidateAllowIpLike Validate but keeps IP-address rules
InvertAllowConvert blocking rules to allow/exception rules
RemoveModifiersStrip unsupported modifiers ($third-party, $document, etc.)
TrimLinesRemove leading/trailing whitespace from each line
InsertFinalNewLineEnsure the output ends with a newline
RemoveEmptyLinesRemove blank lines
ConvertToAsciiConvert non-ASCII hostnames to Punycode

See TRANSFORMATIONS.md for detailed descriptions of each transformation.


Filtering

These flags apply globally to the compiled output (equivalent to IConfiguration.exclusions / inclusions).

FlagTypeDescription
--exclude <pattern>string[]Exclude rules matching the pattern (repeatable). Supports exact strings, * wildcards, and /regex/ patterns. Maps to exclusions[].
--exclude-from <file>string[]Load exclusion patterns from a file (repeatable). Maps to exclusions_sources[].
--include <pattern>string[]Include only rules matching the pattern (repeatable). Maps to inclusions[].
--include-from <file>string[]Load inclusion patterns from a file (repeatable). Maps to inclusions_sources[].

When used with --config, these flags are overlaid on top of any exclusions / inclusions already defined in the config file.


Networking

FlagTypeDescription
--timeout <ms>numberHTTP request timeout in milliseconds
--retries <n>numberNumber of HTTP retry attempts (uses exponential backoff)
--user-agent <string>stringCustom User-Agent header for HTTP requests

Examples

Basic compilation from a config file

adblock-compiler -c config.json -o output.txt

Compile from multiple URL sources

adblock-compiler \
  -i https://example.org/hosts.txt \
  -i https://example.org/extra.txt \
  -o output.txt

Stream output to stdout

adblock-compiler -i https://example.org/hosts.txt --stdout

Skip specific transformations

# Keep IP-address rules and skip compression
adblock-compiler -c config.json -o output.txt --allow-ip --no-compress

# Skip deduplication (faster, output may contain duplicates)
adblock-compiler -c config.json -o output.txt --no-deduplicate

Explicit transformation pipeline

# Only remove comments and deduplicate — no compression or validation
adblock-compiler -i https://example.org/hosts.txt -o output.txt \
  --transformation RemoveComments \
  --transformation Deduplicate \
  --transformation TrimLines \
  --transformation InsertFinalNewLine

Filtering rules from output

# Exclude specific domain patterns
adblock-compiler -c config.json -o output.txt \
  --exclude "*.cdn.example.com" \
  --exclude "ads.example.org"

# Load exclusion list from a file
adblock-compiler -c config.json -o output.txt \
  --exclude-from my-whitelist.txt

# Include only rules matching a pattern
adblock-compiler -c config.json -o output.txt \
  --include "*.example.com"

# Load inclusion list from a file
adblock-compiler -c config.json -o output.txt \
  --include-from my-allowlist.txt

Limit output size

# Truncate to first 50,000 rules
adblock-compiler -c config.json -o output.txt --max-rules 50000

Compare output against a previous build

adblock-compiler -c config.json -o output.txt --name output.txt.bak
# Output:
# Comparison with output.txt.bak:
#   Added:   +42 rules
#   Removed: -7 rules
#   Net:     +35 rules

Append to an existing output file

adblock-compiler -i extra.txt -o output.txt --append

Custom networking options

adblock-compiler -c config.json -o output.txt \
  --timeout 15000 \
  --retries 5 \
  --user-agent "MyListBot/1.0"

Verbose benchmarking

adblock-compiler -c config.json -o output.txt --verbose --benchmark

Configuration File

When using --config, the compiler reads an IConfiguration JSON file. The CLI filtering and transformation flags are applied as an overlay on top of what is defined in that file.

See CONFIGURATION.md for the full configuration file reference.