From 942d8f7c40535395acac3eb0c219482583448e2f Mon Sep 17 00:00:00 2001 From: Kakeru Nakabach Date: Sat, 20 Jun 2026 20:09:35 +0900 Subject: [PATCH 1/2] feat: add perm-count hooks to claude-code-best-practice plugin Count PermissionRequest events per session and suggest /fewer-permission-prompts at Stop when the count reaches 5. Replaces the now-removed suggest-permissions-cleanup.sh (SessionStart hook). --- .../hooks/hooks.json | 19 +++++++++++++++---- .../hooks/perm-count-check.sh | 12 ++++++++++++ .../hooks/perm-count-increment.sh | 6 ++++++ .../hooks/suggest-permissions-cleanup.sh | 8 -------- 4 files changed, 33 insertions(+), 12 deletions(-) create mode 100755 plugins/claude-code-best-practice/hooks/perm-count-check.sh create mode 100755 plugins/claude-code-best-practice/hooks/perm-count-increment.sh delete mode 100755 plugins/claude-code-best-practice/hooks/suggest-permissions-cleanup.sh diff --git a/plugins/claude-code-best-practice/hooks/hooks.json b/plugins/claude-code-best-practice/hooks/hooks.json index 7d85719..6ef6ab6 100644 --- a/plugins/claude-code-best-practice/hooks/hooks.json +++ b/plugins/claude-code-best-practice/hooks/hooks.json @@ -1,13 +1,24 @@ { - "description": "Suggests running /fewer-permission-prompts each time the user invokes /clear.", + "description": "Counts permission requests per session and suggests /fewer-permission-prompts at Stop when the count reaches the threshold.", "hooks": { - "SessionStart": [ + "PermissionRequest": [ { - "matcher": "clear", "hooks": [ { "type": "command", - "command": "${CLAUDE_PLUGIN_ROOT}/hooks/suggest-permissions-cleanup.sh" + "command": "${CLAUDE_PLUGIN_ROOT}/hooks/perm-count-increment.sh", + "async": true + } + ] + } + ], + "Stop": [ + { + "hooks": [ + { + "type": "command", + "command": "${CLAUDE_PLUGIN_ROOT}/hooks/perm-count-check.sh", + "timeout": 5 } ] } diff --git a/plugins/claude-code-best-practice/hooks/perm-count-check.sh b/plugins/claude-code-best-practice/hooks/perm-count-check.sh new file mode 100755 index 0000000..26176f6 --- /dev/null +++ b/plugins/claude-code-best-practice/hooks/perm-count-check.sh @@ -0,0 +1,12 @@ +#!/usr/bin/env bash +set -eu + +COUNT_FILE="$HOME/.claude/perm_count.txt" +count=$(cat "$COUNT_FILE" 2>/dev/null || echo 0) + +if [ "$count" -ge 5 ]; then + echo 0 > "$COUNT_FILE" + echo "{\"systemMessage\": \"このセッションで $count 回パーミッションの要求がありました。/fewer-permission-prompts を実行すると、よく使う操作を settings.json に自動追加してプロンプトを減らせます。\"}" +else + echo 0 > "$COUNT_FILE" +fi diff --git a/plugins/claude-code-best-practice/hooks/perm-count-increment.sh b/plugins/claude-code-best-practice/hooks/perm-count-increment.sh new file mode 100755 index 0000000..b382da4 --- /dev/null +++ b/plugins/claude-code-best-practice/hooks/perm-count-increment.sh @@ -0,0 +1,6 @@ +#!/usr/bin/env bash +set -eu + +COUNT_FILE="$HOME/.claude/perm_count.txt" +count=$(cat "$COUNT_FILE" 2>/dev/null || echo 0) +echo $((count + 1)) > "$COUNT_FILE" diff --git a/plugins/claude-code-best-practice/hooks/suggest-permissions-cleanup.sh b/plugins/claude-code-best-practice/hooks/suggest-permissions-cleanup.sh deleted file mode 100755 index 26291bf..0000000 --- a/plugins/claude-code-best-practice/hooks/suggest-permissions-cleanup.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/usr/bin/env bash -set -eu - -cat <<'EOF' -{ - "systemMessage": "💡 Tip: /clear したタイミングで許可設定の見直しをおすすめします。`/less-permission-prompts` を実行すると、繰り返し許可プロンプトが出るコマンドを検出し、allowlist に追加する候補を提案します。" -} -EOF From 759eda9f5060f7292061233b5b2c319031d0fcee Mon Sep 17 00:00:00 2001 From: Kakeru Nakabach Date: Sat, 20 Jun 2026 20:27:26 +0900 Subject: [PATCH 2/2] refactor: rename perm-count hooks to fewer-prompts-nudge --- .../{perm-count-check.sh => fewer-prompts-nudge-check.sh} | 0 ...rm-count-increment.sh => fewer-prompts-nudge-increment.sh} | 0 plugins/claude-code-best-practice/hooks/hooks.json | 4 ++-- 3 files changed, 2 insertions(+), 2 deletions(-) rename plugins/claude-code-best-practice/hooks/{perm-count-check.sh => fewer-prompts-nudge-check.sh} (100%) rename plugins/claude-code-best-practice/hooks/{perm-count-increment.sh => fewer-prompts-nudge-increment.sh} (100%) diff --git a/plugins/claude-code-best-practice/hooks/perm-count-check.sh b/plugins/claude-code-best-practice/hooks/fewer-prompts-nudge-check.sh similarity index 100% rename from plugins/claude-code-best-practice/hooks/perm-count-check.sh rename to plugins/claude-code-best-practice/hooks/fewer-prompts-nudge-check.sh diff --git a/plugins/claude-code-best-practice/hooks/perm-count-increment.sh b/plugins/claude-code-best-practice/hooks/fewer-prompts-nudge-increment.sh similarity index 100% rename from plugins/claude-code-best-practice/hooks/perm-count-increment.sh rename to plugins/claude-code-best-practice/hooks/fewer-prompts-nudge-increment.sh diff --git a/plugins/claude-code-best-practice/hooks/hooks.json b/plugins/claude-code-best-practice/hooks/hooks.json index 6ef6ab6..cc54485 100644 --- a/plugins/claude-code-best-practice/hooks/hooks.json +++ b/plugins/claude-code-best-practice/hooks/hooks.json @@ -6,7 +6,7 @@ "hooks": [ { "type": "command", - "command": "${CLAUDE_PLUGIN_ROOT}/hooks/perm-count-increment.sh", + "command": "${CLAUDE_PLUGIN_ROOT}/hooks/fewer-prompts-nudge-increment.sh", "async": true } ] @@ -17,7 +17,7 @@ "hooks": [ { "type": "command", - "command": "${CLAUDE_PLUGIN_ROOT}/hooks/perm-count-check.sh", + "command": "${CLAUDE_PLUGIN_ROOT}/hooks/fewer-prompts-nudge-check.sh", "timeout": 5 } ]