Skip to content

Add CLAUDE.md and a clang-format pre-commit hook#264

Merged
caitlinross merged 2 commits into
codes-org:masterfrom
caitlinross:claude-md-format-hook
Jul 14, 2026
Merged

Add CLAUDE.md and a clang-format pre-commit hook#264
caitlinross merged 2 commits into
codes-org:masterfrom
caitlinross:claude-md-format-hook

Conversation

@caitlinross

Copy link
Copy Markdown
Member

I keep forgetting to add a CLAUDE.md file, which would probably be useful.

Also adding a pre-commit hook that will run clang-format on any staged C/C++ files. This way those errors are caught before getting to CI. I also personally hate having a bunch of commits that are just "fixing formatting issues" so this will remind you (me) to do it. You do have to opt into it.

Added to the README:

To catch drift at commit time instead of in CI, enable the repo's pre-commit hook
(one-time, per clone):

git config core.hooksPath scripts/git-hooks

The hook runs the same clang-format --dry-run --Werror check CI does, on the staged
content of C/C++ files under src/, codes/, doc/, and tests/, and rejects the
commit with a fix-it command if anything drifts. Bypass a single commit with
git commit --no-verify.

When you have this enabled and try to commit a file that won't pass clang-format, you will get the following output:

$ git commit -am "Testing pre-commit hook"
pre-commit: staged files are not clang-format clean:
  src/modelconfig/config_compiler.cxx
pre-commit: fix with:  clang-format -i src/modelconfig/config_compiler.cxx
pre-commit: then re-stage (git add) and commit again. Bypass once with --no-verify.

If you use claude, it should handle running clang-format for you due to instructions in CLAUDE.md

Runs the same clang-format --dry-run --Werror check as CI
(.github/workflows/format.yml) on the staged content of C/C++ files
under src/, codes/, doc/, and tests/, rejecting the commit with a
fix-it command on drift so formatting fixups never need their own
commit. Checks the index (git show :file), not the worktree, so
partially staged files are judged on what would actually land; warns
when the local clang-format major differs from CI's pinned 20.

Opt-in per clone via 'git config core.hooksPath scripts/git-hooks'
(documented in the README); bypass a single commit with --no-verify.
@codecov

codecov Bot commented Jul 14, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@caitlinross caitlinross merged commit 1692de0 into codes-org:master Jul 14, 2026
16 checks passed
@caitlinross caitlinross deleted the claude-md-format-hook branch July 14, 2026 23:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant