the formatter multiplexer [maintainers=@zimbatm,@brianmcgee] https://treefmt.com
  • Go 84.9%
  • Nix 7.1%
  • Ruby 5.5%
  • Python 1.4%
  • JavaScript 0.8%
  • Other 0.1%
Find a file
Brian McGee aac8069502
Merge pull request #745 from numtide/renovate/github.com-spf13-pflag-1.x
fix(deps): update module github.com/spf13/pflag to v1.1.0
2026-12-02 12:41:41 +00:00
.github chore(deps): update dependency ubuntu to v26 2026-10-23 16:05:22 +00:00
build feat: more stringent golangci-lint rules 2024-10-16 15:50:51 +01:00
cmd fix: clarify custom walker diagnostics and test name 2026-12-02 11:44:42 +00:00
config Add custom walker configuration 2026-12-02 11:44:42 +00:00
docs Document custom walker configuration 2026-12-02 11:44:42 +00:00
format fix: avoid closed stdin for formatter processes 2026-10-03 15:40:49 +02:00
git fix: go 1.25 toolchain upgrade 2026-03-19 17:18:36 +00:00
jujutsu fix: go 1.25 toolchain upgrade 2026-03-19 17:18:36 +00:00
nix chore: update vendorHash 2026-12-02 12:39:07 +00:00
stats feat: update to go 1.24 2025-03-11 17:45:07 +00:00
test fix: don't append options and stdin-options 2026-08-13 12:50:11 -07:00
walk fix: clarify custom walker diagnostics and test name 2026-12-02 11:44:42 +00:00
.env chore: disable devshell motd 2024-05-08 08:46:10 +01:00
.envrc feat(docs): refine setup 2025-03-12 16:29:43 +00:00
.gitignore fix: go 1.25 toolchain upgrade 2026-03-19 17:18:36 +00:00
.golangci.yaml fix: go 1.25 toolchain upgrade 2026-03-19 17:18:36 +00:00
.goreleaser.yaml fix: set go module to v2 2024-11-09 15:57:36 +00:00
default.nix feat: use numtide/blueprint instead of flake.parts 2024-06-30 12:25:00 +01:00
flake.lock fix: go 1.25 toolchain upgrade 2026-03-19 17:18:36 +00:00
flake.nix flake: drop blueprint's top-level __functor 2026-12-02 11:27:10 +00:00
go.mod fix(deps): update module github.com/spf13/pflag to v1.1.0 2026-12-02 12:37:48 +00:00
go.sum fix(deps): update module github.com/spf13/pflag to v1.1.0 2026-12-02 12:37:48 +00:00
LICENSE doc: fix copyright notice 2024-05-13 10:07:18 +01:00
main.go fix: set go module to v2 2024-11-09 15:57:36 +00:00
README.md chore: use a matrix.to link instead for the matrix room 2026-04-15 10:01:58 +01:00
renovate.json fix: renovate config 2026-04-15 16:54:34 +01:00
shell.nix feat: use numtide/blueprint instead of flake.parts 2024-06-30 12:25:00 +01:00

treefmt

The formatter multiplexer

A numtide project.

Coverage Status

treefmt streamlines the process of applying formatters to your project, making it a breeze with just one command line.

Motivation

Modern code repositories are rarely written in a single language. They often contain a mix of languages, each with its own formatting requirements.

While working for our customers, we noticed that projects each tended to re-implement the same formatter multiplexing logic. A script that invokes all the formatters.

What if that script was a single command?

What if that single command would handle all the formatters in parallel? And only format files that have changed since the previous run?

That's what treefmt is about.

About treefmt

treefmt runs all your formatters with one command. It’s easy to configure and fast to execute.

Treefmt Init

Its main features are:

  • Providing a unified CLI and output
    • You don’t need to remember which formatters are necessary for each project.
    • Once you specify the formatters in the config file, you can trigger all of them with one command and get a standardized output.
  • Running all the formatters in parallel
    • A standard script loops over your folders and runs each formatter sequentially.
    • In contrast, treefmt runs formatters in parallel. This way, the formatting job takes less time.
  • Tracking file changes
    • When formatters are run in a script, they process all the files they encounter, regardless of whether or not they have changed.
    • treefmt tracks file changes, and only attempts to format files which have changed.

To reformat the whole source tree, just type treefmt in any folder. This is a fast and simple formatting solution.

Installation

You can install treefmt by downloading the binary. Find the binaries for different architectures here. Otherwise, you can install the package from source code — either with Go, or with the help of nix.

We describe the installation process in detail in the docs.

Usage

In order to use treefmt in your project, make sure the config file treefmt.toml is present in the root folder and is edited to suit your needs.

You can generate it with:

$ treefmt --init

You can then run treefmt in your project root folder like this:

$ treefmt

To explore the tool’s flags and options, type:

$ treefmt --help

Additionally, there's a wrapper called treefmt-nix for using treefmt with nix.

Configuration

Formatters are specified in the config file treefmt.toml, which is usually located in the project root folder. The generic way to specify a formatter is like this:

[formatter.<name>]
command = "<formatter-command>"
options = ["<formatter-option-1>"...]
includes = ["<glob>"]

For example, if you want to use nixpkgs-fmt on your Nix project and rustfmt on your Rust project, then treefmt.toml will look as follows:

[formatter.nix]
command = "nixpkgs-fmt"
includes = ["*.nix"]

[formatter.rust]
command = "rustfmt"
options = ["--edition", "2018"]
includes = ["*.rs"]

Before specifying the formatter in the config, make sure it’s installed.

To find and share existing formatter recipes, take a look at the docs.

If you are a Nix user, you might also be interested in treefmt-nix to use Nix to configure and bring in formatters.

Compatibility

treefmt works with any formatter that adheres to the following specification.

For instance, you can go for:

  • clang-format for C/C++/Java/JavaScript/JSON/Objective-C/Protobuf/C#
  • gofmt for Golang
  • Prettier for JavaScript/HTML/CSS

You can find information on supported formatters here.

IDE Integration

treefmt currently has support for vscode via an extension:

Upcoming features

This project is still pretty new. Down the line we also want to add support for:

  • More IDE integration
  • Pre-commit hooks
  • EditorConfig: unifies file indentations configuration on a per-project basis.
  • prettier: an opinionated code formatter for a number of languages.
  • Super-Linter: a project by GitHub to lint all of your code.
  • pre-commit: a framework for managing and maintaining multi-language pre-commit hooks.

Contributing

All contributions are welcome! We try to keep the project simple and focused. Please refer to the Contributing guidelines for more information.

Commercial support

Looking for help or customization?

Get in touch with Numtide to get a quote. We make it easy for companies to work with Open Source projects: https://numtide.com/contact

License

Unless explicitly stated otherwise, any contribution intentionally submitted for inclusion will be licensed under the MIT license without any additional terms or conditions.