Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions .claude/hooks/branch-guard.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/bin/bash
# PreToolUse hook: 保護ブランチ (develop / prod / main) での直接編集をブロック
set -euo pipefail

PROTECTED_BRANCHES="^(develop|prod|main)$"

# git リポジトリでない場合はスキップ
if ! git rev-parse --git-dir >/dev/null 2>&1; then
exit 0
fi

BRANCH=$(git rev-parse --abbrev-ref HEAD 2>/dev/null || echo "")

if [ -z "$BRANCH" ]; then
exit 0
fi

if echo "$BRANCH" | grep -qE "$PROTECTED_BRANCHES"; then
cat >&2 <<EOF
BLOCKED: 現在 '${BRANCH}' ブランチで編集しようとしています。保護ブランチには直接コミットしないでください。

feature ブランチを切ってから再度実行してください:

/branch-from-develop <topic>

または

git checkout -b feature/<topic>
EOF
exit 2
fi

exit 0
6 changes: 6 additions & 0 deletions .claude/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@
{
"matcher": "Write|Edit",
"hooks": [
{
"type": "command",
"command": "$CLAUDE_PROJECT_DIR/.claude/hooks/branch-guard.sh",
"timeout": 5,
"statusMessage": "ブランチ保護チェック中..."
},
{
"type": "command",
"command": "$CLAUDE_PROJECT_DIR/.claude/hooks/pre-edit-guard.sh",
Expand Down
Loading
Loading