CLI Reference
Synopsis
dfmt [options] format all included files
dfmt <file-or-dir> [options] format subset of included files
dfmt --dialect <dialect> <file> [options] yolo mode (no config file)
dfmt --changed-since <ref> [options] format files changed since git ref
dfmt --model <name> [options] format specific dbt model
dfmt --init [dialect] create .dfmt.json
Modes
Config mode (default)
Requires a .dfmt.json file, found by walking up from the current directory (or target path). The config provides the dialect, format options, and include/exclude patterns that determine which files to format.
Running dfmt with no arguments formats all files matching the include/exclude patterns.
Running dfmt <path> formats files under <path> that match the patterns.
Yolo mode
When no .dfmt.json exists, --dialect is required:
dfmt --dialect snowflake query.sql
dfmt --dialect bigquery queries/
In yolo mode, all .sql files under the target are formatted.
Options
Core
| Flag | Description |
|---|---|
--write | Write formatted output back to files (only if changed) |
--check | Exit 1 if any file needs formatting. For CI pipelines. |
--init [dialect] | Create .dfmt.json in the current directory |
File selection
| Flag | Description |
|---|---|
--dialect <dialect> | Set dialect explicitly. Required in yolo mode. |
--model <name> | Format a specific dbt model by name |
--changed-since <ref> | Format only .sql files changed since a git ref (branch, tag, or SHA) |
--no-jinja | Format as plain SQL even if a dbt project is detected |
Shorthand
| Flag | Description |
|---|---|
--uppercase | Uppercase keywords (equivalent to --keyword-case upper) |
--lowercase | Lowercase keywords |
--leading-commas | Leading comma style |
--indent N | Indent width (spaces) |
--width N | Max line width |
Format options
All format options from .dfmt.json can also be set via CLI flags. CLI flags override config file values.
| Flag | Values | Default |
|---|---|---|
--keyword-case | upper, lower, preserve | lower |
--identifier-case | upper, lower, preserve | preserve |
--function-case | upper, lower, preserve | lower |
--data-type-case | upper, lower, preserve | lower |
--max-line-width | integer | 80 |
--indent-width | integer | 4 |
--comma-style | trailing, leading | trailing |
--clause-layout | indented, adaptive | indented |
--sibling-layout | stacked, consistent, pack | stacked |
--short-statements-one-line | boolean | true |
--clarify-structure | boolean | false |
--blank-line-between-ctes | boolean | false |
--align-token | token to align (e.g., AS) | none |
Dialects
ansi, bigquery, postgres, duckdb, spark, databricks, snowflake, oracle, db2, tsql, mariadb, presto, trino, redshift, sqlite
Resolution Order
- Dialect:
--dialectflag >.dfmt.jsondialect > dbt adapter type >ansi - Format options: dialect defaults >
.dfmt.jsonoverrides > CLI flag overrides - Files:
.dfmt.jsoninclude/exclude patterns > target path filter >--changed-sincefilter
Exit Codes
| Code | Meaning |
|---|---|
| 0 | Success (or --check found no changes needed) |
| 1 | Error, or --check found files that need formatting |