Repository navigation
Closed
Labels
agent/implementerAI implementer agentenhancementNew feature or requestphase/implementationImplementation phasetriage-requiredNeeds owner triage for priority decision
Description
Machine-Readable Contract
contract_schema_version: v1
issue_kind: implementation
parent_issue: "#1047"
goal_ref: "Hook EACCES / exec-form エラーが作業フローにノイズを混入しないよう、settings.json 登録 hook の実行可能性を CI で deterministic に検査する"
change_kind: workflowParent Issue
Parent Goal Ref
- Goal:
.claude/settings.jsonに登録された全 hook command の実行可能性を決定論的に検査し、EACCES ノイズを根絶する - Desired Destination:
.claude/hooks/*.sh/*.py/*.mjsの実行ビット・パス解決が CI required ジョブで常時検証される状態
Current Validated Scope
.claude/hooks/check_hook_integrity.pyを新規追加する.claude/hooks/tests/test_check_hook_integrity.pyを新規追加する.github/workflows/check-hook-integrity.ymlを新規追加する
Remaining Parent Gaps
- Issue 4(worktree_scope_guard 分類)、Issue 3(PR body 生成)、Issue 1(preflight)、Issue 5〜9 が残る
Outcome
.claude/hooks/check_hook_integrity.py --format json が HOOK_INTEGRITY_RESULT_V1(decision / hooks_checked / failures[] / warnings[] / command_form / mode_octal / effective_x_ok / remediation フィールドを含む)を出力し、.github/workflows/check-hook-integrity.yml が追加されて CI で check-hook-integrity job が実行される workflow が追加される状態で、uv run pytest が PASS している。branch protection / ruleset への required check 登録は本 Issue 外(repo 設定または別 Issue)。
In Scope
.claude/hooks/check_hook_integrity.py(HOOK_INTEGRITY_RESULT_V1出力・--format json対応).claude/hooks/tests/test_check_hook_integrity.py(unit test).github/workflows/check-hook-integrity.yml(CI required ジョブ)- 検査対象:
.claude/settings.jsonの hook command /.claude/hooks/*.sh/*.py/*.mjs - 判定:
not_executable/missing/path_placeholder_unresolved/unsafe_shell_form
Out of Scope
- hook script 自体の自動修復(chmod や設定書き換えは行わない)
.claude/settings.jsonの hook 登録追加・削除.claude/settings.jsonの大規模リファクタリング- branch protection / ruleset への required check 登録(repo 設定または別 Issue で対応)
Acceptance Criteria
- AC1:
.claude/hooks/check_hook_integrity.pyが追加され、--format jsonを受け付ける - AC2: stdout は
HOOK_INTEGRITY_RESULT_V1JSON のみを出し、decision、hooks_checked、failures[]、warnings[]を含む - AC3:
argsキーが存在する hook entry を exec form、存在しない hook entry を shell form として分類する - AC4: direct path exec form の
.shが executable bit を欠く fixture はnot_executableでfailures[]に含まれる - AC5: 存在しない path を指す fixture は
missingでfailures[]に含まれる - AC6: 未解決の
${PLACEHOLDER}を含む fixture はpath_placeholder_unresolvedでfailures[]に含まれる - AC7: unquoted
${CLAUDE_PROJECT_DIR}を含む shell form fixture はunsafe_shell_formでwarnings[]に含まれる - AC8:
command: "bash"+args: ["${CLAUDE_PROJECT_DIR}/.claude/hooks/x.sh"]は interpreter form として pass し、target.shの executable bit は要求しない - AC9:
command: "node"+.mjsargs は pass し、.mjsの executable bit は要求しない - AC10:
failures[]が空でなければdecision: "fail"、空ならdecision: "pass" - AC11:
uv run pytest .claude/hooks/tests/test_check_hook_integrity.py -qが PASS する - AC12:
.github/workflows/check-hook-integrity.ymlが追加され、astral-sh/setup-uvで uv をセットアップしたうえで pytest とcheck_hook_integrity.py --format jsonの両方を実行する
Verification Commands
# AC1
# baseline-expect: fail
$ test -f .claude/hooks/check_hook_integrity.py
# AC2
# baseline-expect: fail
$ uv run pytest .claude/hooks/tests/test_check_hook_integrity.py -q
# AC3
# baseline-expect: fail
$ uv run pytest .claude/hooks/tests/test_check_hook_integrity.py -q
# AC4
# baseline-expect: fail
$ uv run pytest .claude/hooks/tests/test_check_hook_integrity.py -q
# AC5
# baseline-expect: fail
$ uv run pytest .claude/hooks/tests/test_check_hook_integrity.py -q
# AC6
# baseline-expect: fail
$ uv run pytest .claude/hooks/tests/test_check_hook_integrity.py -q
# AC7
# baseline-expect: fail
$ uv run pytest .claude/hooks/tests/test_check_hook_integrity.py -q
# AC8
# baseline-expect: fail
$ uv run pytest .claude/hooks/tests/test_check_hook_integrity.py -q
# AC9
# baseline-expect: fail
$ uv run pytest .claude/hooks/tests/test_check_hook_integrity.py -q
# AC10
# baseline-expect: fail
$ uv run pytest .claude/hooks/tests/test_check_hook_integrity.py -q
# AC11
# baseline-expect: fail
$ uv run pytest .claude/hooks/tests/test_check_hook_integrity.py -q
# AC12
# baseline-expect: fail
$ test -f .github/workflows/check-hook-integrity.ymlRuntime Verification Applicability
decision: not_applicable — 本 Issue の AC はすべて静的検証可能(ファイル存在確認・pytest による fixture ベース unit test)であり、ブラウザや runtime の直接観察は不要。
Allowed Paths
.claude/hooks/check_hook_integrity.py.claude/hooks/tests/test_check_hook_integrity.py.github/workflows/check-hook-integrity.yml.claude/hooks/local_main_branch_guard.sh(Scope Delta: chmod +x のみ、content 変更なし)
Stop Conditions
- Allowed Paths 外の変更が必要と判明した場合
- In Scope の固定契約(キー集合・スキーマ・型定義)の変更が必要になった場合
- 新規 Issue の起票が必要と判断した場合(スコープ分割が発生する場合)
- 後続 Phase / 別スコープへの波及が判明した場合
- nested SubAgent delegation が必要になった場合
- 外部サービス利用・権限昇格・既存テスト大規模改変が必要になった場合
.claude/settings.jsonの hook 形式が想定外で全 hook を再設計する必要が生じた場合
Required Skills
- Python 3(argparse / json / subprocess / os.access)
- GitHub Actions YAML
astral-sh/setup-uv(GitHub Actions action)
Scope Delta(任意)
.claude/hooks/local_main_branch_guard.shを Allowed Paths に追加(chmod +xのみ、content 変更なし)- 追加理由: 人間レビュアー(squne121)が PR feat(#1048): Hook Executability / Exec-form Health Guard を追加し EACCES ノイズを根絶する #1062 レビューコメント(#issuecomment-4759725090)で明示的にこの変更を本 PR に含めることを推奨。
check_hook_integrity.pyが PR feat(#1014): local_main_branch_guard — ローカル root checkout のブランチ drift を Claude Code / Codex CLI の双方でブロック #1041 の既存バグ(executable bit 欠如)を正しく検出し、CI を green にするために必要。
Metadata
Metadata
Assignees
Labels
agent/implementerAI implementer agentenhancementNew feature or requestphase/implementationImplementation phasetriage-requiredNeeds owner triage for priority decision
Activity
squne121 commentedon Jun 20, 2026
結論
#1048 は 実装すべき P0 Issue です。ただし、現行 Issue のまま実装すると 「CI を追加したのに required ではない」「EACCES を検出したいのに shell/exec form の意味を誤判定する」「uv が CI に入っておらず workflow が落ちる」「AC が grep ベースで false green になる」 可能性があります。
したがって判定は Go, but tighten contract before implementation です。
#1048 自体は、
.claude/settings.json登録 hook の実行可能性を CI で決定論的に検査し、HOOK_INTEGRITY_RESULT_V1を出すcheck_hook_integrity.py、unit test、workflow を追加する Issue です。対象 reason code はnot_executable/missing/path_placeholder_unresolved/unsafe_shell_formです。親 #1047 は、#1040→PR #1045 の作業ログで発生した EACCES/posix_spawn 36 回、worktree_scope_guard 誤ブロック 22 回、PR body 日本語チェック失敗、contract snapshot 欠如、CLI 引数不整合を 9 件の子 Issue に分解したものです。#1048 はその最優先順序の先頭です。
なお、#1048 と #1047 のコメントはどちらも空でした。追加仕様・反対意見・レビューコメントはまだありません。
敵対的レビュー
1. 「CI required ジョブ」は Issue の Allowed Paths だけでは完了できない
#1048 の Outcome は
.github/workflows/check-hook-integrity.ymlが CI required ジョブとして常時実行される状態を求めています。これは workflow ファイル追加だけでは完了しません。GitHub の required status checks は branch protection / ruleset 側で有効化する設定が必要で、required checks が成功・skip・neutral でない限り merge できない、という挙動です。([GitHub Docs]1)つまり #1048 の Allowed Paths だけでできるのは workflow を追加して check 名を安定化することまでです。required 化は repo 設定であり、Issue 本文上は次のどちらかに直すべきです。
このままだと、実装者が「workflow 追加 = required 完了」と誤報告する余地があります。
2.
args: []は shell form ではなく exec form として扱う必要がある現行
.claude/settings.jsonは、PreToolUse の多くでcommand: "${CLAUDE_PROJECT_DIR}/.claude/hooks/*.sh"とargs: []を使っています。たとえばsecret_boundary_guard.sh、local_main_branch_guard.sh、worktree_scope_guard.sh、guard-japanese-prose.sh、rtk_boundary_shadow_guard.shは直接 command として登録されています。Stop / SubagentStop も
session_manifest_coordinator.shを直接 command として登録し、PostToolUse だけがcommand: "node"+.mjspath の args 形式です。Claude Code hooks の公式仕様では、
argsがある command hook は shell を通さず executable と args を直接 spawn する exec form です。argsがない場合だけ shell form として扱われます。([Claude API Docs]2)したがって #1048 の中心は、単なる「chmod されているか」ではなく、settings.json の hook entry が shell form なのか exec form なのかを正しく分類し、exec form の直接 command だけ実行ビットを要求する検査です。ここを曖昧にすると、
nodehook の.mjsに誤って executable bit を要求したり、逆に直接.shの EACCES を見逃したりします。3.
nodehook pass の AC が弱いAC5 は「
nodehook は現行通り pass」としていますが、これだけでは不十分です。PostToolUse はcommand: "node"、args: ["${CLAUDE_PROJECT_DIR}/.claude/hooks/generate_session_manifest_from_hook.mjs"]です。この場合の正しい検査は次です。
nodeが CI runner 上でPATH解決できる${CLAUDE_PROJECT_DIR}が repo root に解決できる.mjsファイルが存在し、読み取り可能.mjs自体の executable bit は要求しないPython
subprocessの公式 docs でも、外部プログラム起動では args sequence と fully qualified path の利用が推奨されています。([Python documentation]3)つまり
nodehook は「target script executable」ではなく interpreter form として扱うべきです。4.
uv run pytestを workflow に入れるなら uv setup が必要既存 CI は checkout 後にローカル composite action
setup-node-pnpmを使い、pnpm install / typecheck / lint などを実行しています。その composite action は pnpm と Node.js をセットアップするだけで、uv は入れていません。
#1048 の AC7 は
uv run pytest .claude/hooks/tests/test_check_hook_integrity.py -qを求めています。workflow でもこれを実行するなら、astral-sh/setup-uvを明示して uv を入れる必要があります。uv 公式 docs も GitHub Actions ではastral-sh/setup-uvの利用と version pin を推奨しています。([Astral Docs]4)ここを落とすと、hook integrity の実装ではなく CI 環境不足で PR が赤くなります。
5.
os.access(..., X_OK)だけに依存すると検査が浅い#1048 の Required Skills に
os.accessが挙げられていますが、Python docs はos.access()について、実際の操作前検査には TOCTTOU があり、アクセス確認後でも操作が失敗し得ると注意しています。([Python documentation]5)os.X_OKは executable 判定用の mode ですが、CI 静的検査ではPath.stat().st_mode & 0o111とos.access(path, os.X_OK)の両方を出す方がよいです。([Python documentation]5)推奨は、failure に
mode_octalとeffective_x_okを入れることです。これにより「Git index 上の実行ビット欠落」なのか「runner の実効権限問題」なのかを後続が切り分けられます。6. Allowed Paths が狭すぎるため、実際に失敗を検出すると PR が詰まる可能性がある
#1048 の Allowed Paths は以下だけです。
.claude/hooks/check_hook_integrity.py.claude/hooks/tests/test_check_hook_integrity.py.github/workflows/check-hook-integrity.yml一方、もし現行 hook script の executable bit が本当に欠けていた場合、修正には対象
.shの mode 変更が必要です。しかし #1048 では hook script 自体の chmod や settings 書き換えが out of scope です。これは危険です。実装 PR が checker と CI を追加した瞬間、既存 hook の不備を検出して自分自身を merge 不能にする可能性があります。対策は次のどちらかです。
.claude/hooks/*.shの chmod-only mode change を Allowed Paths に含める7. transitive executable も見ないと EACCES の根絶にならない
session_manifest_coordinator.shは settings から直接起動されますが、その中でGUARD_SCRIPTを直接実行しています。つまり coordinator 自体に executable bit があっても、内部で直接呼ぶ
session_recording_policy_guard.shが executable でなければ、coordinator 内部で失敗します。#1048 は「
.claude/hooks/*.sh/*.py/*.mjsの実行ビット・パス解決」を CI で検査したい Issue です。ならば settings に直接出ている hook だけでなく、少なくとも.claude/hooks/*.shのうち shebang 付きで hook runtime から直接呼ばれ得るものは検査対象にすべきです。ただし
.py/.mjsは全件 executable 必須にしてはいけません。worktree_scope_guard.shは Python module をpython3経由で exec しています。.mjsも現行 settings ではnode経由です。したがって「拡張子で一律 executable」ではなく、直接 command として起動されるか、interpreter の args として渡されるかで判定を変えるべきです。
高品質化した実装方針
まず command form を正規化する
check_hook_integrity.pyは、settings hook entry ごとに次を出すべきです。AC2 の
decision / hooks_checked / failures[]だけでは、#1052 の preflight consumer が機械的に利用しにくいです。#1052 は後続でhook_executability.status:failを preflight に取り込む設計なので、#1048 の schema は downstream consumer 前提で固定すべきです。判定ルールはこうするべき
.claude/settings.jsonを読み、hooks配下の全 event / matcher / hook entry を走査する。argskey が存在する場合は exec form、存在しない場合は shell form とする。これは Claude Code hooks の仕様に合わせる。([Claude API Docs]2)${CLAUDE_PROJECT_DIR}は repo root にだけ解決する。未知 placeholder が残る場合はpath_placeholder_unresolved。Claude docs では placeholders は command/args に使えるが、exec form では executable path として解決される必要があります。([Claude API Docs]2)exec form:
commandが/を含む path なら、存在・file・実行可能を検査するcommandがbash/sh/python/python3/nodeのような interpreter なら、shutil.which(command)と args の path 存在を検査するcommandに空白が含まれる場合はunsupported_command_formまたはunsafe_shell_formshell form:
${CLAUDE_PROJECT_DIR}が未 quote の path として使われるならunsafe_shell_form.claude/hooks/*.shは shebang 付き direct hook candidate として executable bit を検査する。.py/.mjsは、settings で直接 command として参照される場合だけ executable bit を要求する。interpreter args の場合は存在・readable のみ。Claude Code docs の security best practice でも、hook input の validate/sanitize、shell variable quote、path traversal の block、absolute path の使用が推奨されています。([Claude API Docs]2)
AC の修正版
現行 AC の
rg -q "command.*bash"やrg -q "node"は弱いです。コメントや未使用コードでも通ります。実行結果 JSON を検証する AC に変えるべきです。workflow の推奨形
check-hook-integrity.ymlは既存 CI の style に合わせ、最低限これを入れるべきです。一点だけ注意があります。Issue 本文の Outcome は
.claude/hooks/check_hook_integrity.py --format jsonの直接実行を求めていますが、checker 自体の executable bit が壊れていた場合、structured JSON を出す前に workflow が落ちます。CI ではuv run python3 ...で実行し、checker 自身を direct executable にしたいなら別 AC で shebang + executable bit を検査する方が安定します。#1048 実装時に特に見るべき現行 hook
secret_boundary_guard.shは stdin JSON を読み、jq 不在・malformed stdin で fail-closed します。spawn 前に EACCES で死ぬと、この fail-closed/diagnostic 設計まで到達しません。worktree_scope_guard.shは Python module へ exec する薄い wrapper で、wrapper 自体は direct executable 必須です。session_manifest_coordinator.shは guard failure を fail-open にする設計ですが、coordinator 自体が EACCES ならその設計は効きません。さらに内部のGUARD_SCRIPTを直接起動しています。save_loop_state_before_compaction.shは fail-open 設計ですが、こちらも direct command 登録なので executable bit が必要です。Claude Code hooks の exit code 2 は PreToolUse などで block 挙動を持ち、Stop/SubagentStop では停止を妨げる扱いがあります。したがって hook spawn / exec-form エラーは単なるログ汚染ではなく、agent control flow を乱すリスクとして扱うべきです。([Claude API Docs]2)
最終提案
#1048 は次の方針で進めるのがよいです。
check_hook_integrity.pyは.claude/settings.json専用 parser + hook dir scanner にし、stdout は machine-readable JSON のみにする。実装者向けには、この一文を #1048 に追加すると事故が減ります。
作業注記: 検証中に GitHub connector の tree 作成 API を誤って呼び出しました。branch/ref/file の更新は行っていないため、リポジトリ状態は変更していません。
squne121 commentedon Jun 20, 2026
Refinement Loop: Approved
The issue has been approved and is ready for implementation.
approvedsqune121 commentedon Jun 20, 2026
Contract Review Result
squne121 commentedon Jun 20, 2026
implement-issue: 実装完了 (2026-06-20T18:45:23Z)
.claude/worktrees/issue-1048-refinementworktree-issue-1048-refinementfix(#1048): B1-B4 — interpreter_missing, placeholder allowlist, subpr…
squne121 commentedon Jun 20, 2026
impl-review-loop 人間判断要請
要請種別: contract snapshot 更新(Allowed Paths Scope Delta)
状況
PR #1062(iteration 2)の実装は完了しています:
local_main_branch_guard.shchmod +x ✓shutil.which()検証 ✓${CLAUDE_PLUGIN_ROOT}/${CLAUDE_PLUGIN_DATA}placeholder allowlist 追加 ✓ブロッカー
PR review(pr-reviewer SubAgent)が Allowed Paths Gate:
fail_closedを返しています。原因: Issue 本文の Allowed Paths を 4 ファイル(
.claude/hooks/local_main_branch_guard.shを Scope Delta 追加)に更新しましたが、既存の contract snapshot(#issuecomment-4759561202)が古い 3 ファイル分の sha256 を持っています。ensure_contract_snapshot.pyは freshness を検査せずexisting_goを返し、run_contract_review_once.pyは post-implementation 状態(AC1/AC12 がunexpected_pass)でブロックされます。人間に必要なアクション
以下のいずれかを実行してください:
Option A(推奨): PR #1062 の LOOP_VERDICT_V2 コメントに対して、以下を返信する:
Option B:
issue-contract-reviewskill を Issue #1048 に対して手動実行し、新しいstatus: gosnapshot を投稿するどちらの対応後も、
/impl-review-loop https://github.com/squne121/loop-protocol/issues/1048#issuecomment-<新コメントURL>で再開できます。LOOP_STATE: iteration=2, max_iterations=3, termination_reason=null(人間判断待ち)
feat(#1048): Hook Executability / Exec-form Health Guard を追加し EACCES …