Skip to content

Commit 73f351f

Browse files
committed
feat: add hook to prevent force push
1 parent fb5c697 commit 73f351f

3 files changed

Lines changed: 36 additions & 1 deletion

File tree

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/bash
2+
# Prevent force push commands
3+
4+
set -euo pipefail
5+
6+
input_data=$(cat)
7+
cmd=$(echo "$input_data" | jq -r '.tool_input.command // empty')
8+
9+
if [[ -z "$cmd" ]]; then
10+
exit 0
11+
fi
12+
13+
if [[ "$cmd" =~ git\ push.*(-f|--force) ]]; then
14+
echo "Force push is not allowed" >&2
15+
exit 2
16+
fi
17+
18+
exit 0

.claude/settings.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,15 @@
99
"command": "\"$CLAUDE_PROJECT_DIR\"/.claude/hooks/protect-files.sh"
1010
}
1111
]
12+
},
13+
{
14+
"matcher": "Bash",
15+
"hooks": [
16+
{
17+
"type": "command",
18+
"command": "\"$CLAUDE_PROJECT_DIR\"/.claude/hooks/prevent-force-push.sh"
19+
}
20+
]
1221
}
1322
],
1423
"PostToolUse": [

AGENTS.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,4 +106,12 @@ This file provides guidance to coding agents when working with code in this repo
106106

107107
## Pull Requests
108108

109-
Keep PR descriptions concise and to the point. Reviewers should not be exhausted by lengthy explanations.
109+
Keep PR descriptions concise and to the point. Reviewers should not be exhausted by lengthy explanations.
110+
111+
## Claude Code Hooks
112+
113+
Hooks are configured in `.claude/settings.json`:
114+
115+
- **File Protection** (PreToolUse): Blocks edits to `pnpm-lock.yaml`, `src/migration/`, `.infra/Pulumi.*`, `.env`, `.git/`
116+
- **Prevent Force Push** (PreToolUse): Blocks `git push --force` and `git push -f`
117+
- **Auto-Lint** (PostToolUse): Runs `eslint --fix` on TypeScript files after edits

0 commit comments

Comments
 (0)