Skip to content

fix: hooks スクリプト未存在時の graceful fallback - #607

Merged
keito4 merged 1 commit into
mainfrom
fix/hooks-graceful-fallback
Mar 21, 2026
Merged

fix: hooks スクリプト未存在時の graceful fallback#607
keito4 merged 1 commit into
mainfrom
fix/hooks-graceful-fallback

Conversation

@keito4

@keito4 keito4 commented Mar 21, 2026

Copy link
Copy Markdown
Owner

Summary

  • hooks スクリプトがないリポジトリで Claude を使用すると No such file or directory エラーでブロックされる問題を修正
  • スクリプト未存在時はエラーにせず /repo-maintenance の実行を推奨するメッセージを表示するように変更
  • グローバル設定(~/.claude/settings.json)とプロジェクト設定の両方に適用

Test plan

  • hooks スクリプトがないリポジトリで git checkout 等がブロックされないことを確認
  • hooks スクリプトがあるリポジトリ(config)では従来通り hooks が実行されることを確認
  • スクリプト未存在時に /repo-maintenance 推奨メッセージが表示されることを確認

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Chores
    • Enhanced hook configuration to gracefully detect missing hook scripts and display clear setup instructions directing users to run /repo-maintenance for complete quality hook installation.

hooks スクリプトがないリポジトリで Claude を使用すると
"No such file or directory" エラーでブロックされていた問題を修正。
スクリプト未存在時は /repo-maintenance の実行を推奨するメッセージを表示する。

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Mar 21, 2026

Copy link
Copy Markdown

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 2a2a4727-f80b-46b3-bd4b-4dfafb706eb0

📥 Commits

Reviewing files that changed from the base of the PR and between e80373b and e97b4d4.

📒 Files selected for processing (1)
  • .claude/settings.json

📝 Walkthrough

Walkthrough

Configuration file .claude/settings.json was updated to conditionally verify the existence of hook scripts before executing them. All hook command entries for PreToolUse, PostToolUse, and Stop hooks now include file existence checks before running their corresponding Python scripts, with fallback messaging if scripts are missing.

Changes

Cohort / File(s) Summary
Hook Configuration
.claude/settings.json
Added file-existence conditionals to 9 hook command entries across PreToolUse, PostToolUse, and Stop hooks. Commands now check if the hook script exists before execution; if not, a message instructs users to run /repo-maintenance to set up quality hooks.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Possibly related PRs

  • keito4/config#602: Adds new hook entries to .claude/settings.json that are directly affected by the conditional script-existence checks introduced in this PR
  • keito4/config#451: Adds hook entries running Python hook scripts; this PR now makes those invocations defensive with existence checks
  • keito4/config#458: Modifies the same .claude/settings.json hook command entries with portable path configuration

Suggested labels

released

Poem

🐰 A hook must be wise, before it takes flight,
Check if the script exists—avoid the blight!
When files go missing, no crash nor despair,
Just guidance to run /repo-maintenance with care. ✨

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/hooks-graceful-fallback

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 commented Mar 21, 2026

Copy link
Copy Markdown
Owner Author

🔍 AI Code Review (Local Hook)

Models: Codex (default) / Gemini (default)

🤖 Codex Review

指摘事項(重大度順)

  1. 品質ゲートの強制力が低下しています
    python3 .claude/hooks/*.py が存在しない場合にエラーで止まらず、警告出力のみで続行するため、フック未配置時に品質・安全チェックが黙ってスキップされます。これにより本来ブロックすべき操作(--no-verify など)が通るリスクがあります。
    影響範囲: .claude/settings.json の各 hook 定義(例: 173-176, 182-185, 191-194, 200-203, 211-214, 220-223, 229-232, 238-241, 249-252)

結論: patch is incorrect
理由: フックが欠落しているケースで、品質・安全チェックが実質無効化される挙動変更が導入されているため。
信頼度: 0.62


⚠️ 修正が必要です

上記のレビューで問題が指摘されています。修正してからマージしてください。


🤖 Generated by post_pr_ai_review.py hook

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e97b4d4ce7

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread .claude/settings.json
{
"type": "command",
"command": "bash -c 'cd \"$(git rev-parse --show-toplevel 2>/dev/null || echo .)\" && python3 .claude/hooks/block_git_no_verify.py'"
"command": "bash -c 'cd \"$(git rev-parse --show-toplevel 2>/dev/null || echo .)\" && { [ -f .claude/hooks/block_git_no_verify.py ] && python3 .claude/hooks/block_git_no_verify.py || echo \"[hooks] .claude/hooks/block_git_no_verify.py not found. Run /repo-maintenance to set up quality hooks.\"; }'"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Preserve hook failure exit codes when adding fallback

The new A && B || echo ... pattern turns real hook failures into success: when python3 .claude/hooks/block_git_no_verify.py exists but exits non-zero (e.g., it intentionally returns 2 to block forbidden commands), the || echo ... branch runs and the overall shell command exits 0, so Claude no longer blocks the action. This regresses the enforcement behavior documented for these hooks and applies to each similarly updated command in this file.

Useful? React with 👍 / 👎.

@keito4
keito4 merged commit 3fb7057 into main Mar 21, 2026
14 of 15 checks passed
@keito4
keito4 deleted the fix/hooks-graceful-fallback branch March 21, 2026 07:35
@github-actions

Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 1.101.2 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

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.

1 participant