#!/bin/bash # Hook profile gate — wraps hooks to enable/disable by profile # Profiles: minimal (safety only), standard (safety + quality), strict (everything) # # Usage in settings.json: # "command": "$CLAUDE_PROJECT_DIR/.claude/hooks/run-with-profile.sh standard $CLAUDE_PROJECT_DIR/.claude/hooks/some-hook.sh" # # Environment variables: # CLAUDE_HOOK_PROFILE — Override profile (minimal|standard|strict). Default: standard # CLAUDE_DISABLED_HOOKS — Comma-separated list of hook filenames to skip. E.g.: "suggest-compact.sh,auto-tmux-dev.sh" REQUIRED_PROFILE="${1:?Usage: run-with-profile.sh }" HOOK_SCRIPT="${2:?Usage: run-with-profile.sh }" shift 2 # Current profile (default: standard) CURRENT_PROFILE="${CLAUDE_HOOK_PROFILE:-standard}" # Profile hierarchy: minimal < standard < strict profile_level() { case "$1" in minimal) echo 1 ;; standard) echo 2 ;; strict) echo 3 ;; *) echo 2 ;; # default to standard esac } CURRENT_LEVEL=$(profile_level "$CURRENT_PROFILE") REQUIRED_LEVEL=$(profile_level "$REQUIRED_PROFILE") # Skip if current profile is lower than required if [ "$CURRENT_LEVEL" -lt "$REQUIRED_LEVEL" ]; then exit 0 fi # Check if hook is explicitly disabled HOOK_NAME=$(basename "$HOOK_SCRIPT") if [ -n "$CLAUDE_DISABLED_HOOKS" ]; then if echo ",$CLAUDE_DISABLED_HOOKS," | grep -q ",$HOOK_NAME,"; then exit 0 fi fi # Execute the hook, passing stdin through exec "$HOOK_SCRIPT" "$@"