Skip to content

Commit 23bd93b

Browse files
chore(hooks): add Claude Code hook guard, scrub legacy hooksPath refs (#312)
Add .claude/hooks/guard.sh PreToolUse hook, update settings.json with hook wiring and permissions, update docs.
1 parent 9bfe1d0 commit 23bd93b

5 files changed

Lines changed: 57 additions & 16 deletions

File tree

.claude/hooks/guard.sh

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/usr/bin/env bash
2+
# Claude Code PreToolUse hook shim.
3+
# Delegates to vrg-hook-guard if available; falls back to a
4+
# jq-based git/gh check that hard-denies when vergil-tooling
5+
# is not installed.
6+
set -euo pipefail
7+
8+
if command -v vrg-hook-guard &>/dev/null; then
9+
exec vrg-hook-guard
10+
fi
11+
12+
input=$(cat)
13+
command=$(printf '%s' "$input" | jq -r '.tool_input.command // empty')
14+
bin=$(printf '%s' "$command" | awk '{print $1}')
15+
base=$(basename "$bin" 2>/dev/null || printf '%s' "$bin")
16+
17+
case "$base" in
18+
git|gh)
19+
jq -n '{
20+
hookSpecificOutput: {
21+
hookEventName: "PreToolUse",
22+
permissionDecision: "deny",
23+
permissionDecisionReason: "vergil-tooling is not available. This repository requires a correctly configured environment — all git/gh operations are blocked until resolved."
24+
}
25+
}'
26+
exit 0
27+
;;
28+
esac
29+
30+
exit 0

.claude/settings.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,22 @@
11
{
2+
"permissions": {
3+
"allow": [
4+
"Bash(vrg-*)"
5+
]
6+
},
7+
"hooks": {
8+
"PreToolUse": [
9+
{
10+
"matcher": "Bash",
11+
"hooks": [
12+
{
13+
"type": "command",
14+
"command": "${CLAUDE_PROJECT_DIR}/.claude/hooks/guard.sh"
15+
}
16+
]
17+
}
18+
]
19+
},
220
"extraKnownMarketplaces": {
321
"vergil-marketplace": {
422
"source": {

CLAUDE.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,8 @@ Java wrapper for the IBM MQ administrative REST API, ported from `pymqrest` (Pyt
104104

105105
- **Java**: 17+ (install via `brew install openjdk@17` or SDKMAN)
106106
- **Maven**: Provided by Maven Wrapper (`./mvnw`), no separate install needed
107-
- **Git hooks**: `git config core.hooksPath ../vergil-tooling/scripts/lib/git-hooks`
108-
- **VERGIL CLI tools (`vrg-commit`, `vrg-validate`, etc.) are pre-installed in the dev container images
107+
- **Hook guard**: The Claude Code PreToolUse hook guard (`.claude/hooks/guard.sh`) blocks raw `git`/`gh` — use `vrg-git`/`vrg-gh`
108+
- **VERGIL CLI tools** (`vrg-commit`, `vrg-validate`, etc.) are pre-installed in the dev container images
109109

110110
### CI
111111

docs/repository-standards.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
- Before modifying any files, check the current branch with `git status -sb`.
1515
- If on `develop`, create a short-lived `feature/*` branch or ask for explicit approval to proceed on `develop`.
1616
- If approval is granted to work on `develop`, call it out in the response and proceed only for that user-approved scope.
17-
- Enable repository git hooks before committing: `git config core.hooksPath .githooks`.
17+
- The Claude Code hook guard (`.claude/hooks/guard.sh`) blocks raw `git`/`gh` — use `vrg-git`/`vrg-gh`.
1818

1919
## Local validation
2020

docs/site/docs/development/developer-setup.md

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ cd mq-rest-admin-java
5252
# Compile and run all quality checks
5353
./mvnw verify
5454

55-
# Enable repository git hooks
56-
git config core.hooksPath scripts/git-hooks
55+
# The Claude Code hook guard (.claude/hooks/guard.sh) blocks raw
56+
# git/gh commands — use vrg-git / vrg-gh wrappers.
5757
```
5858

5959
## Building
@@ -122,18 +122,11 @@ scripts/dev/mq_stop.sh
122122
See [local MQ container](local-mq-container.md) for full container configuration,
123123
credentials, gateway routing, and troubleshooting.
124124

125-
## Git hooks
125+
## Claude Code hook guard
126126

127-
Enable repository git hooks before committing:
128-
129-
```bash
130-
git config core.hooksPath scripts/git-hooks
131-
```
132-
133-
The hooks enforce:
134-
135-
- **pre-commit**: Branch naming conventions and protected branch rules
136-
- **commit-msg**: Conventional Commits format and co-author trailer validation
127+
The `.claude/hooks/guard.sh` PreToolUse hook blocks raw `git` and
128+
`gh` commands in AI agent sessions — all operations must go through
129+
the `vrg-git` / `vrg-gh` wrappers.
137130

138131
## Documentation
139132

0 commit comments

Comments
 (0)