clang-format
$ clang-format Foundation Low RiskOfficial LLVM code formatting CLI supporting C, C++, Objective-C, Java, JavaScript, and Protocol Buffers via .clang-format rules. Offers non-destructive --dry-run and -Werror checks before applying -i in-place edits.
brew install clang-format Formats C/C++/Protobuf AST tokens locally in milliseconds; no MCP server is needed.
Agent-Readiness Checklist
Static evaluation (not yet probed on this host). Run npm run data:probe locally to capture live verification.
FCRS-1.0 6-Dimension Breakdown
Provides --dry-run, -Werror, and --output-replacements-xml, though it lacks native --json output.
--dry-run -Werrorgives deterministic pass/fail exit codes--output-replacements-xmlemits machine-parseable XML hunks instead of JSON
Read-only by default; writes to disk only when -i is explicitly supplied.
- Non-destructive default stdout mode and explicit
--dry-runflag
Widely distributed standalone binary via Homebrew, Linux packages, PyPI wheel, and LLVM releases.
- Cross-platform native C++ binary on macOS, Linux, and Windows
Industry-standard formatter across C/C++/Protobuf with deterministic .clang-format config resolution.
- Supports multiple C-family and IDL languages from one binary
Official LLVM Foundation tool maintained continuously in llvm/llvm-project.
- Part of official
llvm/llvm-projecttoolchain
Thorough option reference and .clang-format style docs on clang.llvm.org.
- Official documentation at clang.llvm.org/docs/ClangFormat.html
Security, Auth & Guardrails
Purely local source formatting; no credentials stored or required.
Apache-2.0 with LLVM Exception open-source binary; completely free.
# clang-format Agent Rules - Always verify with `clang-format --dry-run -Werror` before running `clang-format -i`. - Scope `-i` to edited files rather than globbing the entire repo unless requested.
Agent-Ready Command Recipes
Safe Read-Only Queries
clang-format --dry-run -Werror src/*.cpp include/*.h
Reports unformatted locations to stderr and exits non-zero without modifying any files.
clang-format --output-replacements-xml src/main.cpp
Outputs structured XML byte-offset replacement hunks without rewriting disk files.
Controlled Writes & Previews
clang-format -i src/main.cpp
Reformats only the specified file in place using the repository .clang-format config.
Strengths for Agents
- +
--dry-run -Werrorcatches formatting drift cleanly without modifying files. - + Deterministic
.clang-formatstyle inheritance across C, C++, Objective-C, Java, and Protobuf.
Caveats & Pitfalls
- ! No
--jsonoutput; machine parsing requires--output-replacements-xmlor diff inspection. - ! Version mismatches across LLVM releases can change formatting edge cases.