Repository navigation
tooling(claude): the clang-format edit hook formats with pre-commit's pinned clang-format, as CI does (#3022) - #3023
Merged
Conversation
… pinned clang-format, as CI does (#3022) It used the PATH clang-format, which can differ from the mirrors-clang-format rev CI pins (#2947 passed it locally with 22.1.2 and failed CI's 22.1.8). With pre-commit installed the hook now runs its clang-format hook on the file; without it, it falls back to the PATH binary and says so. Fixes #3022 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.Scanned FilesNone |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes #3022
Claude Code's
PostToolUseformat hook ran whateverclang-formatis on PATH. CI'sFormat C++ codeuses themirrors-clang-formatrev pinned in.pre-commit-config.yaml. #2947 passed the hook locally (Ubuntu's 22.1.2) and failed CI (v22.1.8). The same skew #916 fixed fortools/check-format.sh.The hook now:
pre-commit run clang-format --files "$f"from the file's repository root, so the edit gets exactly CI's formatter. That command exits 1 when it changed the file, which is ignored.clang-format -ifrom PATH, warning that it may differ from CI.It stays quiet and non-blocking otherwise, and still skips non-C++ files.
PR Size
✅ Small (one command in
.claude/settings.json).Type of Change
Checklist
pre-commit run --all-filesor installed pre-commit hooksTesting
I piped the hook a synthetic Edit payload for a badly formatted
.cpp.int main( ) {return 0;}came out formatted by pre-commit's pinned clang-format, and the scratch file was removed afterwards.Additional Notes
This is checked-in agent configuration, so it's for the maintainer's look.
🤖 Generated with Claude Code