Files
leo-claude-mktplace/plugins/project-hygiene/hooks/cleanup.sh
lmiranda 63327ecf65 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>
2026-01-30 13:19:03 -05:00

43 lines
1.1 KiB
Bash
Executable File

#!/bin/bash
# project-hygiene cleanup hook
# Runs after file edits to clean up temp files
# All output MUST have [project-hygiene] prefix
set -euo pipefail
PREFIX="[project-hygiene]"
# Read tool input from stdin (discard - we don't need it for cleanup)
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:-.}"
DELETED_COUNT=0
# Silently delete temp files
for pattern in "*.tmp" "*.bak" "*.swp" "*~" ".DS_Store"; do
while IFS= read -r -d '' file; do
rm -f "$file" 2>/dev/null && ((DELETED_COUNT++)) || true
done < <(find "$PROJECT_ROOT" -name "$pattern" -type f -print0 2>/dev/null || true)
done
# Only output if we deleted something
if [[ $DELETED_COUNT -gt 0 ]]; then
echo "$PREFIX Cleaned $DELETED_COUNT temp files"
fi
# Record this run for cooldown
date +%s > "$LAST_RUN_FILE"
exit 0