Skip to content

fix: Claude Code hooks の matcher 構文を修正 - #455

Merged
keito4 merged 1 commit into
mainfrom
fix/hooks-matcher-syntax-454
Feb 11, 2026
Merged

fix: Claude Code hooks の matcher 構文を修正#455
keito4 merged 1 commit into
mainfrom
fix/hooks-matcher-syntax-454

Conversation

@keito4

@keito4 keito4 commented Feb 11, 2026

Copy link
Copy Markdown
Owner

Summary

  • Claude Code の hooks 設定で使用されていた無効な matcher 構文を修正
  • tool_name == 'Bash'Bash (正しいパターンマッチ構文)

問題

~/.claude/settings.json の hooks 設定で、式構文(tool_name == '...')が使用されていたため、
ユーザーレベルのフックが一切実行されていなかった。

影響を受けていたフック

Hook Type Script 機能
PreToolUse block_git_no_verify.py --no-verify のブロック
PreToolUse pre_git_quality_gates.py Quality Gates の実行
PreToolUse pre_exit_plan_ai_review.py プラン終了前のAIレビュー
PostToolUse post_git_push_ci.py push後のCI確認
PostToolUse post_pr_ai_review.py PR作成後のAIレビュー

確認済み

Closes #454

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Refactor
    • Optimized internal configuration structure for improved system efficiency. No user-facing changes or functionality impacts.

`tool_name == 'Bash'` などの式構文はサポートされていないため、
正しいパターンマッチ構文 `Bash` に修正。

修正内容:
- PreToolUse: block_git_no_verify.py, pre_git_quality_gates.py, pre_exit_plan_ai_review.py
- PostToolUse: post_git_push_ci.py, post_pr_ai_review.py

Closes #454

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Feb 11, 2026

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

Corrects matcher syntax in Claude Code hooks configuration from expression format ("tool_name == 'X'") to simple tool name patterns ("X") to enable hook execution.

Changes

Cohort / File(s) Summary
Claude Code Hook Matchers
.devcontainer/claude-settings.json
Fixed matcher syntax in PreToolUse and PostToolUse hooks by replacing "tool_name == 'Bash'" with "Bash" and "tool_name == 'ExitPlanMode'" with "ExitPlanMode" to enable proper hook dispatch.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

Possibly related PRs

Suggested labels

size/XS

Poem

🐰 The hooks were broken, tools wouldn't run,
Expression syntax—oh, what a bun!
Simple names is what they crave,
"Bash" and "ExitPlanMode" now behave,
Config fixed, the rabbits celebrate with glee! 🎉

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title clearly describes the main change: fixing Claude Code hooks matcher syntax from invalid expression format to correct pattern format.
Linked Issues check ✅ Passed The PR successfully addresses all coding requirements from issue #454: replacing invalid matcher syntax (tool_name == 'X') with correct pattern names (Bash, ExitPlanMode) across PreToolUse and PostToolUse hooks.
Out of Scope Changes check ✅ Passed All changes are within scope - only matcher syntax corrections in the hooks configuration file, directly addressing issue #454 requirements.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/hooks-matcher-syntax-454

No actionable comments were generated in the recent review. 🎉

🧹 Recent nitpick comments
.devcontainer/claude-settings.json (1)

388-415: Consolidate duplicate Bash matchers to reduce repetition.

The PreToolUse section has two separate "Bash" matcher blocks (lines 389–397 and 398–406), and PostToolUse has the same pattern (lines 419–425 and 428–434). Merge each pair into a single matcher object with both hooks in the hooks array, following the recommended configuration pattern. The current structure works but is less efficient.

Example for PreToolUse
     "PreToolUse": [
       {
         "matcher": "Bash",
         "hooks": [
           {
             "type": "command",
             "command": "python3 /home/vscode/.claude/hooks/block_git_no_verify.py"
-          }
-        ]
-      },
-      {
-        "matcher": "Bash",
-        "hooks": [
+          },
           {
             "type": "command",
             "command": "python3 /home/vscode/.claude/hooks/pre_git_quality_gates.py"
           }
         ]
       },

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@keito4
keito4 merged commit b5ed354 into main Feb 11, 2026
12 of 14 checks passed
@claude

claude Bot commented Feb 11, 2026

Copy link
Copy Markdown
Contributor

コードレビュー結果

✅ 総合評価: 承認(条件付き)

このPRは重要なバグ修正であり、hooks が正常に動作するようにするための必須の変更です。


📋 レビュー詳細

1. コード品質とベストプラクティス ⭐⭐⭐⭐⭐

良い点:

  • 正確な修正: Claude Code の matcher 構文に準拠した正しいパターンマッチング形式への変更
  • 一貫性: 全ての matcher を統一的に修正(BashExitPlanMode
  • 最小限の変更: 必要な箇所のみを修正し、他の設定には影響なし
  • 実証済み: Elu-co-jp/cyber_ace_1on1 での動作確認が完了している

変更内容:

- "matcher": "tool_name == 'Bash'"
+ "matcher": "Bash"

- "matcher": "tool_name == 'ExitPlanMode'"
+ "matcher": "ExitPlanMode"

2. 潜在的なバグ・問題 ⚠️

重大な問題は検出されませんでした。

ただし、以下の点に注意:

  • この修正により、これまで動作していなかった5つの hooks が全て有効化される
  • hooks のスクリプト自体に問題がないか、事前に確認済みであることが前提

3. パフォーマンスへの影響 ⭐⭐⭐⭐⭐

影響:

  • hooks が正常に実行されるようになるため、git commit/git push/PR作成時の処理時間が増加する可能性がある
  • pre_git_quality_gates.py は複数のチェック(format, lint, test, shellcheck, security scan, complexity check)を実行するため、数秒〜数十秒の遅延が発生する

推奨事項:

  • 開発者に hooks が有効化されることを周知
  • 初回実行時の遅延について事前に説明

4. セキュリティへの考慮 ⭐⭐⭐⭐⭐

セキュリティ向上:

  • block_git_no_verify.py: --no-verifyHUSKY=0 のブロックが有効化され、品質ゲートのバイパスを防止
  • pre_git_quality_gates.py: セキュリティスキャン(認証情報漏洩チェック)が正常に実行されるようになる
  • security-credential-scan.sh --strict により、機密情報のコミットを事前にブロック

セキュリティリスク:

  • 検出されませんでした

5. テストカバレッジ ⭐⭐⭐⭐

現状:

  • 手動テストで動作確認済み(Elu-co-jp/cyber_ace_1on1 PR#1494)
  • 各 hook スクリプト(block_git_no_verify.py, pre_git_quality_gates.py など)は既に実装済み

改善提案:

  • CI で hooks の構文チェックを追加することを検討(JSON スキーマバリデーション)
  • hooks が意図通りにトリガーされることを確認する統合テストがあると理想的

🐛 発見された問題

🔴 Critical: ドキュメントの不整合

.claude/hooks/README.md古い構文のままになっています。

該当箇所:

  • .claude/hooks/README.md:31
  • .claude/hooks/README.md:73
  • .claude/hooks/README.md:99
  • .claude/hooks/README.md:109
  • .claude/hooks/README.md:185
  • .claude/hooks/README.md:225
  • .claude/hooks/README.md:264

修正が必要な例:

// ❌ 間違った例(READMEに記載されている)
"matcher": "tool_name == 'Bash'"

// ✅ 正しい例(実際のコードに適用済み)
"matcher": "Bash"

影響:

  • 新規開発者がREADMEを参照して設定をコピーした場合、hooks が動作しない
  • ドキュメントとコードの乖離により混乱を招く可能性がある

推奨対応:
このPRに追加コミットとして、.claude/hooks/README.md の全ての matcher 構文例を修正してください。


📝 推奨事項

必須対応

  1. README.md の修正: 上記の不整合を解消
  2. CHANGELOG.md への記載: Breaking Change として記録(既存の設定ファイルを持つユーザーへの影響があるため)

任意対応(将来の改善)

  1. JSON Schema による設定ファイルのバリデーション
  2. Hooks の統合テスト追加
  3. config-base イメージの再ビルド・公開手順のドキュメント化

✅ 承認条件

以下が対応されれば、このPRは承認可能です:

  • .claude/hooks/README.md の matcher 構文例を全て修正
  • (任意)CHANGELOG.md への変更内容の記載

Reviewed by: Claude Sonnet 4.5
Review Date: 2026-02-11 08:16:01 UTC
Standards: CLAUDE.md (.claude/CLAUDE.md, CLAUDE.md)

🤖 Generated with Claude Code

@github-actions

Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 1.69.1 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

@github-actions github-actions Bot added the released リリース済み label Feb 11, 2026
@keito4
keito4 deleted the fix/hooks-matcher-syntax-454 branch March 1, 2026 09:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

released リリース済み

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: Claude Code hooks の matcher 構文を修正

1 participant