/flags/caddy/caddy-fmt-overwrite
caddy fmt --overwrite and --diff: format a Caddyfile
verified onenvironmentlocal · windows 10.0.26200 arm64 · GNU bash 5.3.15 (Git Bash) · v2.11.7 h1:yj0Y4fYZGPkSvibBJ1sTWE33xC0fxztVyXEW5iIdUT4=updated 2026-10-20
- tool
- Caddy
- command
- caddy fmt
- flag
- --overwrite
- default
- print to standard output
caddy fmt [Caddyfile] reads a Caddyfile and prints it in the canonical format: tabs for indentation and consistent spacing. Without flags it only prints. --overwrite (-w) writes the result back to the file, and --diff prints what would change. When the input is not formatted, caddy fmt exits with a non-zero status, so it can be used as a CI check.
Format a file
printf 'example.com {\n reverse_proxy localhost:3000\n encode gzip\n}\n' > Caddyfile
caddy fmt --diff Caddyfile 2>/dev/null
caddy fmt Caddyfile >/dev/null 2>&1; echo "unformatted, exit status: $?"
caddy fmt --overwrite Caddyfile
cat -A Caddyfile | sed 's/\$$//'
caddy fmt Caddyfile >/dev/null 2>&1; echo "formatted, exit status: $?"Output
example.com {
- reverse_proxy localhost:3000
- encode gzip
+ reverse_proxy localhost:3000
+ encode gzip
}
unformatted, exit status: 1
example.com {
^Ireverse_proxy localhost:3000
^Iencode gzip
}
formatted, exit status: 0cat -A shows tabs as ^I: the formatter indents with tabs.
Flags
| Flag | Effect |
|---|---|
| (none) | print the formatted Caddyfile to standard output |
| --overwrite, -w | write the result back to the file |
| --diff | print a diff instead of the whole file |
| FILE or - | the file to format; - reads standard input (default: ./Caddyfile) |
caddy run, caddy validate and caddy adapt also warn when a Caddyfile is not formatted, but they still load it.
Sources
Related pages
errors · caddyCaddy: Caddyfile:2: unrecognized directiveCaddy fails with Caddyfile:N: unrecognized directive for a misspelled directive, a plugin missing from the binary, or a global option inside a site block.compare · caddyCaddy vs nginx: HTTPS, configuration and performance comparedCaddy gets and renews HTTPS certificates automatically with a few lines of config; nginx needs certbot or similar but has more modules, docs and tuning.commands · nginxnginx -t: test the configuration before reloadingnginx -t checks the configuration syntax and the files it references without touching the running server; nginx -T also prints the full merged config.