clangd is a language server that allows other programs to access introspection and refactoring capabilities for C++ via the language server protocol. It was originally meant for code editors. For example, VS Code can use it via this extension, and provide functions like “Go to definition”, “rename”. With LLMs and their harnesses, they can give those capabilities to agents which otherwise navigate code-bases via the equivalent of Windows Notepad, e.g. by reading and grep’ing. For example, for pi.dev, there are these extensions that can use clangd.
How it works
clangd is usually run by the host application, which communicates with it by sending and receiving json-rpc fragments via stdin/stdout. It can either be kept running as a continuous service and serve from memory, or keep its preprocessed info persisted to disk and use that from per-request instances/processes.
Install clangd
Go to https://github.com/llvm/llvm-project/releases, and download the Windows installer for LLVM. At the time of this writing, the version is 23.1.2. Install that. By default, the executables will go into C:\Program Files\LLVM\bin.
Add that to your PATH, e.g. by pressing Win+R and running rundll32.exe sysdm.cpl,EditEnvironmentVariables. It should be sufficient to add it for your user.
Setup your project
Make sure the CMake variable CMAKE_EXPORT_COMPILE_COMMANDS is set to ON, which will generate a compile_commands.json in your build folder. This file contains the compiler invocations for your project, which clangd needs to correctly interpret your code.
Note that the CMake documentation specifically mentions that CMAKE_EXPORT_COMPILE_COMMANDS does not work well with unity builds. This is a shame, because they rock.
Drop a file called .clangd in your project root where to find that file. Since I usually use conan and their layout, my builds go in build/Debug or build/Release. Here, I can only pick one at a time:
CompileFlags:
CompilationDatabase: "build/Debug"
At this point, you should be able to use clangd on your code. There are many other things you can configure in that file, e.g. whether to store the persistent index I mentioned above.
Try it out!
The VS Code extension I mentioned at the top is a good way to check if everything is working as expected. Hovering over an identifier should give you some nice info about it:


