From 19c413adf83d3070548da11ace29a33fef7b38ce Mon Sep 17 00:00:00 2001 From: James Date: Tue, 7 Apr 2026 16:51:22 -0400 Subject: [PATCH] Add Claude pre-push hooks for clippy and doc checks Adds a Claude Code hook that runs before every `git push`: - cargo +nightly fmt --check - cargo clippy with -D warnings - RUSTDOCFLAGS="-D warnings" cargo doc Clippy and doc warnings are hard failures that block the push. Co-Authored-By: Claude Opus 4.6 (1M context) --- .claude/hooks/pre-push.sh | 32 ++++++++++++++++++++++++++++++++ .claude/settings.json | 17 +++++++++++++++++ CLAUDE.md | 12 ++++++++++++ 3 files changed, 61 insertions(+) create mode 100755 .claude/hooks/pre-push.sh create mode 100644 .claude/settings.json diff --git a/.claude/hooks/pre-push.sh b/.claude/hooks/pre-push.sh new file mode 100755 index 0000000..20ce0f4 --- /dev/null +++ b/.claude/hooks/pre-push.sh @@ -0,0 +1,32 @@ +#!/usr/bin/env bash +set -euo pipefail + +# Consume stdin (hook protocol) +cat > /dev/null + +cd "$(dirname "$0")/../.." + +echo "Running pre-push checks..." >&2 + +if ! cargo +nightly fmt -- --check 2>&1; then + echo "Format check failed. Run 'cargo +nightly fmt' to fix." >&2 + exit 2 +fi + +if ! cargo clippy --all-targets --all-features -- -D warnings 2>&1; then + echo "Clippy (--all-features) failed." >&2 + exit 2 +fi + +if ! cargo clippy --all-targets --no-default-features -- -D warnings 2>&1; then + echo "Clippy (--no-default-features) failed." >&2 + exit 2 +fi + +if ! RUSTDOCFLAGS="-D warnings" cargo doc --no-deps 2>&1; then + echo "Doc check failed." >&2 + exit 2 +fi + +echo "All pre-push checks passed." >&2 +exit 0 diff --git a/.claude/settings.json b/.claude/settings.json new file mode 100644 index 0000000..cc3faa1 --- /dev/null +++ b/.claude/settings.json @@ -0,0 +1,17 @@ +{ + "hooks": { + "PreToolUse": [ + { + "matcher": "Bash", + "hooks": [ + { + "type": "command", + "if": "Bash(git push *)", + "command": "\"$CLAUDE_PROJECT_DIR\"/.claude/hooks/pre-push.sh", + "timeout": 600 + } + ] + } + ] + } +} diff --git a/CLAUDE.md b/CLAUDE.md index f8fc8c1..74dd8a1 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -132,6 +132,18 @@ cargo clippy --no-default-features --all-targets cargo +nightly fmt ``` +### Pre-push Checks (enforced by Claude hook) + +A Claude hook in `.claude/settings.json` runs `.claude/hooks/pre-push.sh` +before every `git push`. The push is blocked if any check fails. The checks: + +- `cargo +nightly fmt -- --check` +- `cargo clippy --all-targets --all-features -- -D warnings` +- `cargo clippy --all-targets --no-default-features -- -D warnings` +- `RUSTDOCFLAGS="-D warnings" cargo doc --no-deps` + +Clippy and doc warnings are hard failures. + ## Linux Testing Before committing, run the Docker Linux environment to verify changes pass on Linux: