perf(hooks): improve hook efficiency with early exits and cooldowns

Sprint 8 - Hook Efficiency Quick Wins (v5.5.0)

- Remove viz-platform SessionStart hook (zero value, just echoed "loaded")
- Add early git check to git-flow branch-check.sh (skip JSON parsing for non-git commands)
- Add early git check to git-flow commit-msg-check.sh (skip Python spawn for non-commit commands)
- Add 60-second cooldown to project-hygiene cleanup.sh (reduce find operations)

Closes #321, #322, #323, #324

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-01-30 13:19:03 -05:00
parent 3839575272
commit 63327ecf65
4 changed files with 26 additions and 8 deletions

View File

@@ -6,6 +6,11 @@
# Read tool input from stdin (JSON format) # Read tool input from stdin (JSON format)
INPUT=$(cat) INPUT=$(cat)
# Quick check - exit immediately if not a git command
if ! echo "$INPUT" | grep -q '"command".*git'; then
exit 0
fi
# Extract command from JSON input # Extract command from JSON input
# The Bash tool sends {"command": "..."} format # The Bash tool sends {"command": "..."} format
COMMAND=$(echo "$INPUT" | grep -o '"command"[[:space:]]*:[[:space:]]*"[^"]*"' | head -1 | sed 's/.*"command"[[:space:]]*:[[:space:]]*"\([^"]*\)".*/\1/') COMMAND=$(echo "$INPUT" | grep -o '"command"[[:space:]]*:[[:space:]]*"[^"]*"' | head -1 | sed 's/.*"command"[[:space:]]*:[[:space:]]*"\([^"]*\)".*/\1/')

View File

@@ -6,6 +6,12 @@
# Read tool input from stdin # Read tool input from stdin
INPUT=$(cat) INPUT=$(cat)
# Quick check - exit immediately if not a git commit command
# This avoids spawning Python for 99% of Bash commands
if ! echo "$INPUT" | grep -q '"command".*git.*commit'; then
exit 0
fi
# Use Python to properly parse JSON and extract the command # Use Python to properly parse JSON and extract the command
COMMAND=$(echo "$INPUT" | python3 -c "import sys,json; d=json.load(sys.stdin); print(d.get('command',''))" 2>/dev/null) COMMAND=$(echo "$INPUT" | python3 -c "import sys,json; d=json.load(sys.stdin); print(d.get('command',''))" 2>/dev/null)

View File

@@ -10,6 +10,17 @@ PREFIX="[project-hygiene]"
# Read tool input from stdin (discard - we don't need it for cleanup) # Read tool input from stdin (discard - we don't need it for cleanup)
cat > /dev/null cat > /dev/null
# Cooldown - skip if ran in last 60 seconds
# Using $PPID ties cooldown to the Claude session
LAST_RUN_FILE="/tmp/project-hygiene-${PPID}-last-run"
if [[ -f "$LAST_RUN_FILE" ]]; then
LAST_RUN=$(cat "$LAST_RUN_FILE")
NOW=$(date +%s)
if (( NOW - LAST_RUN < 60 )); then
exit 0
fi
fi
PROJECT_ROOT="${PROJECT_ROOT:-.}" PROJECT_ROOT="${PROJECT_ROOT:-.}"
DELETED_COUNT=0 DELETED_COUNT=0
@@ -25,4 +36,7 @@ if [[ $DELETED_COUNT -gt 0 ]]; then
echo "$PREFIX Cleaned $DELETED_COUNT temp files" echo "$PREFIX Cleaned $DELETED_COUNT temp files"
fi fi
# Record this run for cooldown
date +%s > "$LAST_RUN_FILE"
exit 0 exit 0

View File

@@ -1,10 +1,3 @@
{ {
"hooks": [ "hooks": []
{
"event": "SessionStart",
"type": "command",
"command": "echo 'viz-platform plugin loaded'",
"timeout": 5000
}
]
} }