clang-tidy: controlling color diagnostics

Is there a way to turn on/off color diagnostics in clang-tidy? Passing -f[no]-color-diagnostics via -extra-arg does not seem to have any effect.


Did you build it yourself?

There’s a test in llvm/cmake/config-ix.cmake that sets HAVE_TERMINFO, which needs to be set in order to enable colors. If it’s not set or set to 0, then you won’t get colors. Try installing one of the libraries mentioned in the test: tinfo terminfo curses ncurses ncursesw.


Thanks for your quick response. I am able to get colors on a terminal. But I am unable to control it with a command line option.

I lose colors when I redirect the output to a file. With clang, I can force colors even when redirecting to a file using -fcolor-diagnostics option. However, -extra-arg=-fcolor-diagnostics doesn’t work with clang-tidy.

Alternatively, if I want to turn off color onto a terminal, I can use -fno-color-diagnostics with clang. With clang-tidy, that also doesn’t work.

I wonder if the following code in ClangTidy.cpp is the reason:

class ErrorReporter {

. . .

DiagOpts->ShowColors = llvm::sys::Process::StandardOutHasColors();


clang does it differently—see parseShowColorArgs in CompilerInvocation.cpp:

if (O.matches(options::OPT_fcolor_diagnostics) ||

O.matches(options::OPT_fdiagnostics_color)) {

ShowColors = Colors_On;

} . . .



if (ShowColors == Colors_On ||

(ShowColors == Colors_Auto && llvm::sys::Process::StandardErrHasColors()))

return true;


Ah, I see. Not sure about clang-tidy.

This seems like a limitation of clang-tidy. It is probably a simple fix. But not sure what is the appropriate way.

Should this be supported via -extra-arg=-f[no-]color-diagnostics or should it be a clang-tidy option?


Okay, so I looked into this and -extra-arg and -extra-arg-before modify the actual command line from the compilation database. So, if you had actual errors in your code, you could toggle the colors for that reporting.

However, this has nothing to do with the diagnostics created by clang-tidy. They are actually hard coded to colors if your systems has them. Here’s the line you should look at.

ClangTidy:99 DiagOpts->ShowColors = llvm::sys::Process::StandardOutHasColors();

So, if you wanted to fix this, you could add an additional option to clang-tidy that controls both.


Ø Here’s the line you should look at.


Ø ClangTidy:99 DiagOpts->ShowColors = llvm::sys::Process::StandardOutHasColors();

Yes, that is the same line I was referring to in my earlier email. Thanks.