[Chore ]Add HEAD check gate to Stop hook to skip expensive work on most turns #27
Merged
HeshamHM28 merged 4 commits intomainfrom Mar 18, 2026
Merged
[Chore ]Add HEAD check gate to Stop hook to skip expensive work on most turns #27HeshamHM28 merged 4 commits intomainfrom
HeshamHM28 merged 4 commits intomainfrom
Conversation
Store the HEAD cache file in $REPO_ROOT/.claude/ (the project-specific Claude directory) instead of /tmp/codeflash-state/. This is consistent with how the plugin already uses .claude/ for settings.json and avoids polluting /tmp. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Store the HEAD cache file in the Claude-managed transcript directory (alongside codeflash-seen) instead of /tmp/codeflash-state/. The transcript directory is already used for per-session state and is the proper plugin-specific location for this kind of data. Also fixes a bug where the HEAD cache was never written after the check, so the gate would never actually skip subsequent invocations. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The Stop hook (suggest-optimize.sh) fires on every Claude response and runs ~8 process spawns (git log, stat, jq, sort, grep, etc.) before deciding there's nothing to do. On most turns, no commit has happened, so this
work is wasted.
Solution
Added a cheap gate early in the script that compares git rev-parse HEAD against a cached value in /tmp/codeflash-state/. If HEAD hasn't changed since the last check, the hook exits immediately — skipping all the expensive
git log scanning, transcript stat calls, pyproject discovery, and venv detection.
How it works