From harness-anchor
Formats C/C++ code with clang-format, focusing on changed lines only to avoid diff pollution. Provides commands for formatting, verification, and .clang-format configuration.
How this skill is triggered — by the user, by Claude, or both
Slash command
/harness-anchor:cpp-formattingThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
`clang-format` is the de-facto C/C++ formatter. Like Prettier or rustfmt, it's deterministic and removes formatting debates.
clang-format is the de-facto C/C++ formatter. Like Prettier or rustfmt, it's deterministic and removes formatting debates.
clang-format installed (brew install clang-format / apt install clang-format).clang-format config at project root (use templates/cpp/.clang-format.tpl if not present — /cpp-init drops it for you)git diff -U0 --no-color HEAD | clang-format-diff -p1 -i
Or, for staged changes:
git clang-format
This formats only changed lines — does not touch unrelated code. Critical for keeping diffs clean.
clang-format -i path/to/file.cpp
Only use this on files you OWN this session, or when starting fresh. Reformatting an unchanged file in the middle of a feature pollutes the diff and obscures review.
clang-format --dry-run --Werror path/to/file.cpp
Returns non-zero if anything would change. Useful in pre-commit / CI.
The template uses LLVM as the base with a few popular tweaks:
BasedOnStyle: LLVM
IndentWidth: 4
ColumnLimit: 100
AllowShortIfStatementsOnASingleLine: Never
AllowShortFunctionsOnASingleLine: Empty
SortIncludes: true
Project teams should agree on BasedOnStyle (LLVM / Google / Mozilla / WebKit) early and stick with it. Don't tweak per-PR.
.pb.cc from protobuf) — exclude via .clang-format-ignoreThe harness-anchor Stop hook (Phase 3+) is currently advisory; it doesn't auto-format. Format manually with git clang-format before /session-end to keep the diff clean.
git diff --stat # should show only changed lines' format
If clang-format touched files you didn't change, your .clang-format may have drifted between machines (different versions produce different output). Pin clang-format major version in CI.
For an unfamiliar .clang-format key (e.g. PenaltyExcessCharacter, BreakInheritanceList) — invoke the docs-lookup skill. It encodes the Context7 → WebSearch fallback and the "Context7 unavailable" detection rules.
Typical entry query: clang-format <option-name> or clang-format style options.
npx claudepluginhub redtropig/harness-anchor --plugin harness-anchorConfigures clang-format code formatting: creates .clang-format from templates, analyzes code styles to generate configs, troubleshoots issues, integrates with git and editors.
Performs static analysis on C/C++ code using clang-tidy, cppcheck, and IWYU. Designed for incremental review of changed lines, needs compile_commands.json.
Reformats source code using the project's IntelliJ IDEA code-style settings. Supports single files, line ranges, and git-changed files. Invoke after editing to maintain consistent formatting.