Skip to content

Compilation databases and agent workflows ​

CLAP can emit a Clang compilation database (compile_commands.json) for direct builds. CMake builds already export the same database into the CMake build directory because CLAP configures them with CMAKE_EXPORT_COMPILE_COMMANDS=ON.

Generate it explicitly for a direct build:

bash
clap build main.c util.c --compile-commands
# or choose the destination
clap build main.c util.c --compile-commands-output .clangd/compile_commands.json

The generated file is ordinary JSON in the format consumed by clangd-style tools. Each entry contains:

FieldMeaning
directoryworking directory used for the compilation command
fileabsolute source file path
outputobject-file path used by CLAP/Ninja
argumentsexact compiler argument vector, including language standard, target, includes, defines, and flags

CLAP writes arguments rather than a shell-quoted command string. That avoids quoting ambiguity on Windows paths containing spaces or Unicode characters.

Editor and analyzer consumers ​

clangd ​

Point clangd at the project root or copy/symlink the database there:

bash
clap build main.c util.c --compile-commands-output compile_commands.json

For direct multi-file projects this is usually the simplest setup: restart clangd after regenerating the file. For CMake projects, point clangd at build/compile_commands.json or symlink it into the project root.

Microsoft C/C++ extension ​

clap vscode writes .vscode/c_cpp_properties.json with compileCommands set to ${workspaceFolder}/compile_commands.json, plus a CLAP: Build task that regenerates that file. Existing unrelated VS Code configuration is preserved.

clang-tidy and other Clang tools ​

Most Clang-based tools accept -p:

bash
clang-tidy main.c -p compile_commands.json

The exact flag spelling depends on the tool version; consult that tool's documentation. CLAP only guarantees that the database itself follows the standard JSON shape.

Agent workflow ​

For an AI agent or automation, prefer JSON CLI output and stable files over terminal scraping:

  1. Run clap inspect to determine project sources, dependency metadata, cache state, and platform overrides.
  2. Run clap build ... --compile-commands --json or clap test ... --json.
  3. Read compile_commands.json when exact per-source compiler arguments are needed.
  4. Read clap.spdx.json when dependency/provenance metadata is needed.
  5. Treat diagnostics in the JSON diagnostics array as structured data; use stdout/stderr only as fallback context.

A compact agent loop is:

bash
clap inspect > inspect.json
clap build --compile-commands --json > build.json
clap test --junit-xml test-results.xml --json > test.json

The build may use direct source discovery, clap.toml, or a CMake project; the agent does not need to know which one before inspect runs.

Regeneration and staleness ​

Compilation databases are build metadata, not dependency locks. Regenerate them after changing:

  • source file lists;
  • include paths, defines, libraries, or language standards;
  • compiler selection or target triple;
  • platform-specific project overrides;
  • generated sources or generated headers.

compile_commands.json does not itself cause rebuilds. Ninja incremental state remains in .clap-ninja/ for direct builds or in the CMake build directory for CMake builds.