Skip to content
Latchkey

ninja -t clean: Clean Build Outputs

ninja -t clean deletes the files ninja knows it built, leaving the manifest and configuration in place.

Sometimes a CI build needs a clean slate without throwing away the configured build directory. ninja -t clean removes outputs while keeping build.ninja, so the next build reconfigures nothing.

What it does

ninja -t clean invokes the clean tool, which removes every output file recorded in build.ninja. It does not touch the manifest or generated configuration, so a subsequent ninja rebuilds from sources without rerunning cmake or meson. -g also cleans generator-built files.

Common usage

Terminal
ninja -C build -t clean        # remove built outputs
ninja -C build -t clean -g     # also clean generator outputs
ninja -C build -t clean my_app # clean only one target's outputs

Options

FlagWhat it does
-t cleanRemove all known build outputs
-t clean <target>Clean outputs for specific targets
-t clean -gAlso remove files produced by the generator
-t cleandeadRemove outputs for rules no longer in the manifest

In CI

Prefer ninja -t clean over rm -rf build when you want a fresh compile but a kept configuration, for example to force a rebuild after toggling ccache without paying the cmake reconfigure cost. When the configuration itself is stale, deleting the build dir and reconfiguring is the correct heavier reset.

Common errors in CI

"ninja: error: loading 'build.ninja'" before clean runs means there is no configured build dir to clean; configure first. If clean appears to do nothing, the outputs may already be absent (a fresh checkout) which is expected. A clean that does not fix a stale build usually means the configuration, not the outputs, is the problem; reconfigure instead.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →