setup-workflow-hooks.sh
1 #!/bin/bash 2 # Setup global Claude Code hooks for workflow runner 3 # Run once on CI server: ./setup-workflow-hooks.sh 4 # 5 # This copies compression hooks to ~/.claude/hooks/ so they apply 6 # to all repos, not just alpha-delta-context. 7 8 set -euo pipefail 9 10 SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" 11 CONTEXT_DIR="$(dirname "$SCRIPT_DIR")" 12 HOOKS_SRC="$CONTEXT_DIR/.claude/hooks" 13 HOOKS_DST="$HOME/.claude/hooks" 14 15 echo "=== Claude Hooks Setup ===" 16 echo "Source: $HOOKS_SRC" 17 echo "Target: $HOOKS_DST" 18 echo 19 20 # Create target directory 21 mkdir -p "$HOOKS_DST" 22 23 # Copy hooks 24 HOOKS=( 25 "posttool-output-compression.py" 26 "pretool-alias-expansion.py" 27 "pretool-token-injection.py" 28 "config.yaml" 29 ) 30 31 for hook in "${HOOKS[@]}"; do 32 if [ -f "$HOOKS_SRC/$hook" ]; then 33 cp -v "$HOOKS_SRC/$hook" "$HOOKS_DST/" 34 chmod +x "$HOOKS_DST/$hook" 2>/dev/null || true 35 else 36 echo "Warning: $hook not found in source" 37 fi 38 done 39 40 # Create settings.json if not exists 41 SETTINGS="$HOME/.claude/settings.json" 42 if [ ! -f "$SETTINGS" ]; then 43 echo '{"hooks": {"enabled": true}}' > "$SETTINGS" 44 echo "Created: $SETTINGS" 45 fi 46 47 echo 48 echo "=== Token Savings ===" 49 echo "Output compression: ~60-80% reduction on build/test output" 50 echo "Input optimization: cspec-style prompts (~80% reduction)" 51 echo 52 echo "Verify with: claude -p 'echo test' --cwd /tmp" 53 echo "Should see compression messages in stderr"