.claude/settings.json: skip tests hook when no files changed#21640
.claude/settings.json: skip tests hook when no files changed#21640MikeMcQuaid merged 4 commits intoHomebrew:mainfrom
Conversation
`brew tests --changed` exits non-zero with "No files have been changed from the `main` branch!" when a session ends without editing any files (e.g. read-only/analysis sessions). Guard the Stop hook so it only invokes `brew tests --changed` when there are actually changed files, while still propagating test failures when it does run.
There was a problem hiding this comment.
Pull request overview
This PR modifies the Claude Stop hook to conditionally run ./bin/brew tests --changed only when there are changed files, preventing spurious errors in read-only sessions where no files have been modified.
Changes:
- Added a guard condition using
git diffto check for changed files before running the tests command
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
fix stupid oversight on my part Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Instead: I'd be 👍🏻 on just making this not an error (like it isn't for |
@carlocab's idea Co-authored-by: Carlo Cabrera <github@carlo.cab>
@MikeMcQuaid i.e. changing the return status of brew tests --changed when there are no changes? Want me to try my hand at that instead of the hook? That definitely feels like the correct approach to me now that I think about it. |
@zbeekman Yes please! |
Makes claude usage less noisy/saves tokens
|
OK, I implemented the change. LMK if you want me to squash and/or rebase from main. The only downside is ruby may be slower than git so, claude hook may be slightly slower. will test. But this way we won't get out of sync with code base. LMK your thoughts @carlocab and team |
|
vs
Worth adding the hook gaurd back? And if so should we match behavior of brew tests --changed (compare vs main) or just I'm inclined to have claude get those ~ 2 seconds back |
I think it'd be nicer to e.g. add something to |
EDIT: I understand that this is a pretty minimal annoyance, but in the interest of token efficiency and maybe speed, it might be worth considering. It is a very small change. One down side is that the behavior of
brew tests --changedis sort of encoded in the hook, so it's possible that it could become out of sync. If you think this is a dumb PR, I won't be offended, but I was sick of looking at the error message myself, so I thought I'd see if anyone else thought this was a good idea.Problem
The Stop hook runs
./bin/brew tests --changedunconditionally. When a session ends without editing any files (e.g. read-only/analysis work), this exits non-zero:This surfaces as a spurious hook error at the end of every read-only session.
Fix
Guard the command so it only runs when
git diff --name-only main...HEADreturns results. Test failures still propagate normally when the command does run — this is not a silent ignore.Disclosure
This fix was identified and implemented with assistance from Claude Code (claude-sonnet-4-6) and reviewed/tested by me before submission.