clang-tidy -- using custom path config file


Does clang-tidy accepts config (i.e. .clang-tidy) file from custom path?

I am planning to use to have “.clang-tidy” maintained as “/some/path/to/my-tidy-config” and

need to pass “/some/path/to/my-tidy-config” to clang-tidy.

Tried :::

$ clang-tidy --config=/some/path/to/my-tidy-config

YAML:1:1: error: not a mapping



Error: invalid configuration specified.

Invalid argument

Any suggestion? Or existing patch?

Thank you.

Hi Hiral,

The `--config` command line option is specifying the config inplace
that clang-tidy should use. Alot of the clang-tidy lit tests use this
functionality, have a look at some tests files in `/clang-tools-
extra/test/clang-tidy/checkers` for how this is done.

If that option isn't specified, clang-tidy will fall back to recursing
the parent directories for a file name .clang-tidy and use that as its
config, in much the same way that clang-format does.

I guess if you want to share a clang-tidy config across multiple
projects your best bet is to symlink it to the root directory of each

cd mr-project-dir
ln -s /some/path/to/my-tidy-config .clang-tidy


Thanks Nathan for reply.

The `--config` command line option is specifying the config inplace that clang-tidy should use.

Got it.

Thanks for suggesting symlink :slight_smile:

I am looking for some option with clang-tidy such that $ clang-tidy --config-file-path </some/path/to/.clang-tidy> -- pick '.clang-tidy' from custom location not from parent(s) directories for a file name.


Hi Hiral,

Unfortunately such an option doesn't exist. While it is trivial to add
one, I'm not too sure it would add enough value to justify it.

There is actually an alternative that could work for your use case
without adding the option or symlinks by piping the file contents into
the config option. It may look a little on the hacky side but does the

$ clang-tidy <input_files> --config="`cat </some/path/to/.clang-tidy>`"

The downside of this approach is it wont integrate nicely with tools
taht use clang-tidy internally(clangd) or tools that handle invoking
clang-tidy on their own (editor integrations etc). However for manually
invoking clang-tidy it should do the job.