Bear is a build tool that generates compile_commands.json for any C or C++ project, enabling code navigation and diagnostics with Clang tooling regardless of build system.
Bear solves the problem of integrating C and C++ projects with Clang-based tools like clangd and clang-tidy when the build system cannot produce a compilation database natively. It works by intercepting compiler invocations as the build runs, capturing the exact flags and arguments used, then writing this information to a compile_commands.json file. The tool can also parse build system dry-run output or saved build logs when the build cannot be executed directly, reconstructing the compilation database from that text.
Bear is the right choice for projects using Make, autotools, or custom build scripts—the majority of C codebases—as well as for third-party projects you cannot modify, unusual toolchains like embedded systems or HPC compilers, and situations where you only have access to build logs. It handles compiler wrappers like ccache and distcc, cross-compilers, and CUDA builds. If your project uses CMake, Meson, or Bazel, those tools can export a compilation database directly, which should be preferred when available. The tool requires no changes to your build system; you simply prefix your build command with bear --.
Bear runs on Linux, macOS, and multiple BSD variants as well as Windows, though each platform and build system imposes constraints on which interception methods are available. The project maintains documentation covering platform-specific usage, known limitations, and workarounds. Development is sustained by regular sponsorship and community contributions, with the maintainers actively addressing problem reports and usage questions through issues and chat channels.