[Sprint 8] perf: Add cooldown to project-hygiene cleanup hook #324

Closed
opened 2026-01-29 22:02:59 +00:00 by lmiranda · 2 comments
Owner

Summary

Add a cooldown period to the project-hygiene cleanup hook to avoid running find on every file edit.

Implementation: Change V5.5.0 (Sprint 8)

Problem

The hook runs find across the entire project directory on every Write or Edit operation, looking for temp files. This adds overhead to every file edit, even when there are no temp files to clean.

Solution

Add a 60-second cooldown using a temp file:

# Cooldown - skip if ran in last 60 seconds
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

# ... existing cleanup logic ...

# Record this run
date +%s > "$LAST_RUN_FILE"

Using $PPID ties the cooldown to the Claude session.

Acceptance Criteria

  • Hook skips execution if ran within last 60 seconds
  • Cleanup still works when cooldown expires
  • Temp file cleanup happens once per minute max (not every edit)
  • Different sessions have independent cooldowns

Files to Modify

  • plugins/project-hygiene/hooks/cleanup.sh

Milestone: Sprint 8 - Hook Efficiency Quick Wins

## Summary Add a cooldown period to the project-hygiene cleanup hook to avoid running `find` on every file edit. **Implementation:** [Change V5.5.0 (Sprint 8)](https://gitea.hotserv.cloud/personal-projects/leo-claude-mktplace/wiki/Change-V5.5.0%3A-Hook-Efficiency-Quick-Wins-%28Sprint-8-Implementation%29) ## Problem The hook runs `find` across the entire project directory on every `Write` or `Edit` operation, looking for temp files. This adds overhead to every file edit, even when there are no temp files to clean. ## Solution Add a 60-second cooldown using a temp file: ```bash # Cooldown - skip if ran in last 60 seconds 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 # ... existing cleanup logic ... # Record this run date +%s > "$LAST_RUN_FILE" ``` Using `$PPID` ties the cooldown to the Claude session. ## Acceptance Criteria - [ ] Hook skips execution if ran within last 60 seconds - [ ] Cleanup still works when cooldown expires - [ ] Temp file cleanup happens once per minute max (not every edit) - [ ] Different sessions have independent cooldowns ## Files to Modify - `plugins/project-hygiene/hooks/cleanup.sh` **Milestone:** Sprint 8 - Hook Efficiency Quick Wins
lmiranda added the Type/RefactorEffort/SComplexity/SimplePriority/Medium labels 2026-01-29 22:02:59 +00:00
lmiranda added this to the Sprint 8 - Hook Efficiency Quick Wins milestone 2026-01-30 18:14:02 +00:00
Author
Owner

Progress Update

Status: In Progress
Phase: Implementation
Tool Calls: 6 (budget: 100)

Completed

  • Read issue #324 and acceptance criteria
  • Read current cleanup.sh file (29 lines)
  • Confirmed on development branch (full access)

In Progress

  • Adding cooldown logic to cleanup.sh

Blockers

  • None

Next

  • Add cooldown check at start of script
  • Add run timestamp recording at end
  • Verify bash syntax is valid
## Progress Update **Status:** In Progress **Phase:** Implementation **Tool Calls:** 6 (budget: 100) ### Completed - [x] Read issue #324 and acceptance criteria - [x] Read current cleanup.sh file (29 lines) - [x] Confirmed on `development` branch (full access) ### In Progress - [ ] Adding cooldown logic to cleanup.sh ### Blockers - None ### Next - Add cooldown check at start of script - Add run timestamp recording at end - Verify bash syntax is valid
Author
Owner

Progress Update

Status: Complete (not committed)
Phase: Implementation Done
Tool Calls: 12 (budget: 100)

Completed

  • Read issue #324 and acceptance criteria
  • Read current cleanup.sh file (29 lines)
  • Confirmed on development branch (full access)
  • Added cooldown check at start of script (after stdin consumption)
  • Added run timestamp recording at end (before exit)
  • Verified bash syntax is valid

Implementation Summary

File Modified: plugins/project-hygiene/hooks/cleanup.sh

Changes Made:

  1. Added cooldown check after stdin consumption (lines 13-22):

    • Uses /tmp/project-hygiene-${PPID}-last-run to store last run timestamp
    • Reads timestamp and compares with current time
    • Exits early if less than 60 seconds have passed
    • $PPID ensures different Claude sessions have independent cooldowns
  2. Added timestamp recording at end (line 40):

    • Records current timestamp after cleanup logic completes
    • Only runs if cooldown allowed execution

Acceptance Criteria Verification:

  • Hook skips execution if ran within last 60 seconds - Early exit at line 20
  • Cleanup still works when cooldown expires - Full logic runs when 60s have passed
  • Temp file cleanup happens once per minute max - Cooldown enforces this
  • Different sessions have independent cooldowns - $PPID creates unique temp files

File grew from 29 to 43 lines (+14 lines)

Not Done (per instructions)

  • Commit not created (as requested)
## Progress Update **Status:** Complete (not committed) **Phase:** Implementation Done **Tool Calls:** 12 (budget: 100) ### Completed - [x] Read issue #324 and acceptance criteria - [x] Read current cleanup.sh file (29 lines) - [x] Confirmed on `development` branch (full access) - [x] Added cooldown check at start of script (after stdin consumption) - [x] Added run timestamp recording at end (before exit) - [x] Verified bash syntax is valid ### Implementation Summary **File Modified:** `plugins/project-hygiene/hooks/cleanup.sh` **Changes Made:** 1. Added cooldown check after stdin consumption (lines 13-22): - Uses `/tmp/project-hygiene-${PPID}-last-run` to store last run timestamp - Reads timestamp and compares with current time - Exits early if less than 60 seconds have passed - `$PPID` ensures different Claude sessions have independent cooldowns 2. Added timestamp recording at end (line 40): - Records current timestamp after cleanup logic completes - Only runs if cooldown allowed execution **Acceptance Criteria Verification:** - [x] Hook skips execution if ran within last 60 seconds - Early exit at line 20 - [x] Cleanup still works when cooldown expires - Full logic runs when 60s have passed - [x] Temp file cleanup happens once per minute max - Cooldown enforces this - [x] Different sessions have independent cooldowns - `$PPID` creates unique temp files **File grew from 29 to 43 lines (+14 lines)** ### Not Done (per instructions) - [ ] Commit not created (as requested)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: personal-projects/leo-claude-mktplace#324