Repository navigation
Description
Machine-Readable Contract
contract_schema_version: v1
issue_kind: implementation
parent_issue: "none"
goal_ref: "Prevent SubAgent from pushing to main/master branches via PreToolUse hook"
change_kind: code
blocked_by: ["#1745"]Parent Issue
none
Parent Goal Ref
- Goal: Add SubAgent-side push destination guard to block main/master push attempts at PreToolUse hook level
- Desired Destination: N/A (standalone implementation)
Current Validated Scope
.claude/hooks/pretooluse_git_push_guard.sh(new hook script).claude/hooks/tests/test_pretooluse_git_push_guard.sh(unit tests).claude/settings.jsonor.claude/settings.local.json(hook registration)
Remaining Parent Gaps
なし
Outcome
SubAgent cannot execute git push commands with destination branches named main, master, or refs/heads/main; hook exits with code 2 and stderr message before bash execution. Normal PR branch pushes succeed. Tests pass for both block and allow cases.
In Scope
- Create
.claude/hooks/pretooluse_git_push_guard.shscript that:- Receives Claude Code PreToolUse hook JSON on stdin
- Detects if tool is
Bashand command containsgit push - Blocks if destination ref contains:
main,master,HEAD:main,refs/heads/main, or similar patterns - Exits with code 2 on block, logs reason to stderr
- Exits with code 0 for allowed commands (e.g.,
git push origin worktree-issue-N-foo)
- Register hook in
.claude/settings.jsonor.claude/settings.local.jsonasPreToolUsehook - Create unit tests in
.claude/hooks/tests/test_pretooluse_git_push_guard.sh - Ensure script is executable and follows existing hook patterns in repo
Out of Scope
- GitHub-side main branch protection (separate Issue ops: main 直接 push 防止のための GitHub branch protection / ruleset hardening #359)
- Blocking other protected branches (release, staging, etc.) — extensible in future AC
- Blocking
git push --force-with-leaseentirely — only destination=main is blocked - Integration testing in live Claude Code session (unit test sufficient)
- PreToolUse hook framework changes or SDK enhancements
Acceptance Criteria
- AC1: File
.claude/hooks/pretooluse_git_push_guard.shexists and is executable (mode +x) - AC2: Hook is registered in
.claude/settings.json(or.claude/settings.local.jsonper existing pattern) asPreToolUsehook - AC3: Test suite confirms blocking:
git push origin HEAD:main,git push origin foo:main,git push origin foo:refs/heads/mainall exit 2 - AC4: Test suite confirms allow:
git push origin worktree-issue-N-fooexits 0; normal PR branches are not blocked - AC5:
pnpm typecheck && pnpm lint && pnpm test && pnpm buildall PASS - AC6: Hook script passes bash 4+ syntax check (no bashisms that break in strict POSIX environments)
Verification Commands
# AC1
$ test -x .claude/hooks/pretooluse_git_push_guard.sh
# AC2
$ rg -q "pretooluse_git_push_guard" .claude/settings.json
# AC3
$ bash .claude/hooks/tests/test_pretooluse_git_push_guard.sh
# AC4
$ bash .claude/hooks/tests/test_pretooluse_git_push_guard.sh
# AC5
$ pnpm typecheck
$ pnpm lint
$ pnpm test
$ pnpm build
# AC6
$ bash -n .claude/hooks/pretooluse_git_push_guard.shAllowed Paths
.claude/hooks/pretooluse_git_push_guard.sh.claude/hooks/tests/test_pretooluse_git_push_guard.sh.claude/settings.json(if new PreToolUse entry is needed).claude/settings.local.json(if local settings pattern is preferred)
Required Design References
.claude/settings.json.claude/hooks/docs/dev/hook-boundaries.md
Stop Conditions
- Allowed Paths 外の変更が必要と判明した場合
- In Scope の固定契約(キー集合・スキーマ・型定義)の変更が必要になった場合
- 新規 Issue の起票が必要と判断した場合(スコープ分割が発生する場合)
- 後続 Phase / 別スコープへの波及が判明した場合
- nested SubAgent delegation が必要になった場合
- 外部サービス利用・権限昇格・既存テスト大規模改変が必要になった場合
- Allowed Paths must be expanded beyond
.claude/hooks/and settings files - Claude Code SDK PreToolUse hook contract changes mid-implementation
- Existing hook patterns conflict with design approach (must align with current repo hooks)
- Python environment / testing framework changes require new dependencies
- Runtime verification AC (AC3, AC4) cannot be satisfied without live Claude Code execution
- Escalation needed: PreToolUse hook framework does not support regex destination matching
Required Skills
- bash 4+ scripting (hook implementation)
- JSON parsing (Claude Code hook contract)
- git command syntax understanding (destination ref patterns)
Scope Delta
N/A
Background
On 2026-05-24, the implementation-worker SubAgent (Claude Haiku) executed git push origin main without destination validation, resulting in commit abbc61a landing directly on main. Recovery PR #358 is in progress. While GitHub-side branch protection (Issue #359) prevents merge-without-PR at the API level, the SubAgent-side guard adds an additional defensive layer by preventing the push command from executing in the first place.
This Issue implements a Claude Code PreToolUse hook that inspects outgoing Bash tool calls and blocks any git push with main/master destination before the command reaches the shell.
References
- Issue ops: main 直接 push 防止のための GitHub branch protection / ruleset hardening #359 (GitHub branch protection, complementary)
- PR Revert "fix(#324): refresh session-recording-policy table + warning per PR #355 review" #358 (recovery)
- PR feat(#324): integrate session_recording_policy checker into CI and pnpm scripts #355 (originating impl-review-loop)
- Issue 実装: session_recording_policy checker を CI / python-test workflow に統合する #324 (impl-review-loop parent)
- Incident comment: Revert "fix(#324): refresh session-recording-policy table + warning per PR #355 review" #358 (comment)
- Related:
.claude/hooks/existing patterns (inspect before implementation)
Activity
docs(#359): main branch protection / ruleset hardening (#362)
fix: harden publish lane approval bridge against adversarial review f…
feat: PreToolUse remote_write_requires_approval を publish lane 証跡で通過可…
chore: 未配線の external trust root(scripts/trust-root/)を削除する (#1469) (#1471
squne121 commentedon Aug 21, 2026
Owner Disposition: CLOSED / NOT_PLANNED
本 Issue の
PreToolUsepush destination guard は実装しません。理由:
gh/git pushを遮断する新規 enforcing hook を追加しない方針が確定しました。Superseded by #359 and #2223 (Owner Decision synced from #1860 principle).