Skip to content

feat: implementation-worker SubAgent に push destination guard hook を追加する #360

Closed as not planned

Description

@squne121

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.json or .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.sh script that:
    • Receives Claude Code PreToolUse hook JSON on stdin
    • Detects if tool is Bash and command contains git 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.json or .claude/settings.local.json as PreToolUse hook
  • 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

Acceptance Criteria

  • AC1: File .claude/hooks/pretooluse_git_push_guard.sh exists and is executable (mode +x)
  • AC2: Hook is registered in .claude/settings.json (or .claude/settings.local.json per existing pattern) as PreToolUse hook
  • AC3: Test suite confirms blocking: git push origin HEAD:main, git push origin foo:main, git push origin foo:refs/heads/main all exit 2
  • AC4: Test suite confirms allow: git push origin worktree-issue-N-foo exits 0; normal PR branches are not blocked
  • AC5: pnpm typecheck && pnpm lint && pnpm test && pnpm build all 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.sh

Allowed 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

Activity

  1. added
    enhancement
    phase/implementation
    agent/implementer
    triage-required
    on May 24, 2026
  2. added a commit that references this issue on May 24, 2026
  3. squne121 commented on Aug 21, 2026

    @squne121
    OwnerAuthor

    Owner Disposition: CLOSED / NOT_PLANNED

    本 Issue の PreToolUse push destination guard は実装しません。

    理由:

    Superseded by #359 and #2223 (Owner Decision synced from #1860 principle).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    agent/implementerenhancementphase/implementationtriage-required

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions