Built-in Formatters
OpenCode comes with several built-in formatters for popular languages and frameworks. Below is a list of the formatters, supported file extensions, and commands or config options it needs.| Formatter | Extensions | Requirements |
|---|---|---|
| air | .R | air command available |
| biome | .js, .jsx, .ts, .tsx, .html, .css, .md, .json, .yaml, and more | biome.json(c) config file |
| cargofmt | .rs | cargo fmt command available |
| clang-format | .c, .cpp, .h, .hpp, .ino, and more | .clang-format config file |
| cljfmt | .clj, .cljs, .cljc, .edn | cljfmt command available |
| dart | .dart | dart command available |
| dfmt | .d | dfmt command available |
| gleam | .gleam | gleam command available |
| gofmt | .go | gofmt command available |
| htmlbeautifier | .erb, .html.erb | htmlbeautifier command available |
| ktlint | .kt, .kts | ktlint command available |
| mix | .ex, .exs, .eex, .heex, .leex, .neex, .sface | mix command available |
| nixfmt | .nix | nixfmt command available |
| ocamlformat | .ml, .mli | ocamlformat command available and .ocamlformat config file |
| ormolu | .hs | ormolu command available |
| oxfmt (Experimental) | .js, .jsx, .ts, .tsx | oxfmt dependency in package.json and an experimental env variable flag |
| pint | .php | laravel/pint dependency in composer.json |
| prettier | .js, .jsx, .ts, .tsx, .html, .css, .md, .json, .yaml, and more | prettier dependency in package.json |
| rubocop | .rb, .rake, .gemspec, .ru | rubocop command available |
| ruff | .py, .pyi | ruff command available with config |
| rustfmt | .rs | rustfmt command available |
| shfmt | .sh, .bash | shfmt command available |
| standardrb | .rb, .rake, .gemspec, .ru | standardrb command available |
| terraform | .tf, .tfvars | terraform command available |
| uv | .py, .pyi | uv command available |
| zig | .zig, .zon | zig command available |
prettier in your package.json, OpenCode will automatically use it.
How It Works
When OpenCode writes or edits a file, it:- Checks the file extension against all enabled formatters.
- Runs the appropriate formatter command on the file.
- Applies the formatting changes automatically.
Configure Formatters
You can customize formatters through theformatter section in your OpenCode config.
opencode.json
Set this to
true to disable the formatter.The command to run for formatting. Use
$FILE as a placeholder for the file path.Environment variables to set when running the formatter.
File extensions this formatter should handle.
Disabling Formatters
To disable all formatters globally, setformatter to false:
opencode.json
disabled to true:
opencode.json
Custom Formatters
You can override the built-in formatters or add new ones by specifying the command, environment variables, and file extensions:opencode.json
$FILE placeholder in the command will be replaced with the path to the file being formatted.
Examples
Override Prettier Configuration
opencode.json
Add Custom Python Formatter
opencode.json
Configure Multiple Formatters
opencode.json