prettier --write: Format Files in Place
prettier --write formats matched files and saves the changes to disk.
This is the flag developers run locally and that pre-commit hooks use. CI usually runs --check instead so it never mutates the checkout.
What it does
prettier --write formats each matched file and writes the result back. It prints each file path with the time taken and marks files it changed. Unchanged files are listed as "(unchanged)". It exits 0 on success and non-zero only on a real error such as a syntax error or an unwritable path.
Common usage
prettier --write .
prettier --write "src/**/*.{ts,tsx}"
# format only files staged in git
git diff --name-only --cached | xargs prettier --writeFlags
| Flag | What it does |
|---|---|
| --write / -w | Format and save files in place |
| --check / -c | Check only, do not write (use this in CI) |
| --ignore-unknown / -u | Skip files with no associated parser instead of erroring |
| --log-level <level> | Control verbosity of the per-file output |
| --cache | Only reformat files changed since the last run |
In CI
Avoid --write in CI on the main checkout; it changes files and can mask drift. If you auto-fix in a bot job, run prettier --write . then commit the result on a branch. For PR gating, prefer --check so the job fails loudly and the author fixes it.
Common errors in CI
"[error] EACCES: permission denied, open '...'" means the target file or directory is read-only on the runner. "[error] No parser could be inferred for file ..." means an extension Prettier does not recognize; add --ignore-unknown or a plugin. A syntax error prints "[error] SyntaxError: ..." with a line and column and exits non-zero.