Skip to content

Commit 70ea2ad

Browse files
prestwichclaude
andauthored
Add Claude pre-push hooks for clippy and doc checks (#134)
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) <noreply@anthropic.com>
1 parent d10bb07 commit 70ea2ad

3 files changed

Lines changed: 61 additions & 0 deletions

File tree

.claude/hooks/pre-push.sh

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
# Consume stdin (hook protocol)
5+
cat > /dev/null
6+
7+
cd "$(dirname "$0")/../.."
8+
9+
echo "Running pre-push checks..." >&2
10+
11+
if ! cargo +nightly fmt -- --check 2>&1; then
12+
echo "Format check failed. Run 'cargo +nightly fmt' to fix." >&2
13+
exit 2
14+
fi
15+
16+
if ! cargo clippy --workspace --all-targets --all-features -- -D warnings 2>&1; then
17+
echo "Clippy (--all-features) failed." >&2
18+
exit 2
19+
fi
20+
21+
if ! cargo clippy --workspace --all-targets --no-default-features -- -D warnings 2>&1; then
22+
echo "Clippy (--no-default-features) failed." >&2
23+
exit 2
24+
fi
25+
26+
if ! RUSTDOCFLAGS="-D warnings" cargo doc --workspace --no-deps 2>&1; then
27+
echo "Doc check failed." >&2
28+
exit 2
29+
fi
30+
31+
echo "All pre-push checks passed." >&2
32+
exit 0

.claude/settings.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"hooks": {
3+
"PreToolUse": [
4+
{
5+
"matcher": "Bash",
6+
"hooks": [
7+
{
8+
"type": "command",
9+
"if": "Bash(git push *)",
10+
"command": "\"$CLAUDE_PROJECT_DIR\"/.claude/hooks/pre-push.sh",
11+
"timeout": 600
12+
}
13+
]
14+
}
15+
]
16+
}
17+
}

CLAUDE.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,18 @@ long-term maintenance and may receive active work.
1515
Pre-push: clippy (both feature sets where applicable) + fmt. Never use `cargo check/build`.
1616
These checks apply before any push — new commits, rebases, cherry-picks, etc.
1717

18+
### Pre-push Checks (enforced by Claude hook)
19+
20+
A Claude hook in `.claude/settings.json` runs `.claude/hooks/pre-push.sh`
21+
before every `git push`. The push is blocked if any check fails. The checks:
22+
23+
- `cargo +nightly fmt -- --check`
24+
- `cargo clippy --workspace --all-targets --all-features -- -D warnings`
25+
- `cargo clippy --workspace --all-targets --no-default-features -- -D warnings`
26+
- `RUSTDOCFLAGS="-D warnings" cargo doc --workspace --no-deps`
27+
28+
Clippy and doc warnings are hard failures.
29+
1830
## Style
1931

2032
- Functional combinators over imperative control flow

0 commit comments

Comments
 (0)