fix(hooks): try GNU stat before BSD stat in orphan-sweep throttle#1611
Open
timothyfroehlich wants to merge 1 commit into
Open
fix(hooks): try GNU stat before BSD stat in orphan-sweep throttle#1611timothyfroehlich wants to merge 1 commit into
timothyfroehlich wants to merge 1 commit into
Conversation
On Linux, GNU stat's `-f` flag is valid (filesystem-status mode) and silently "succeeds" with unrelated verbose text instead of erroring on the invalid %m directive, poisoning the throttle timestamp and tripping `set -u` on the arithmetic check. BSD stat has no `-c`, so trying GNU syntax first fails cleanly there, making this order safe on both macOS and Linux (e.g. Bazzite). Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a cross-platform throttling bug in the Claude Code SessionStart orphan-sweep hook by ensuring the script reads the throttle file’s mtime correctly on GNU/Linux as well as macOS/BSD.
Changes:
- Reorders the
statinvocation to try GNUstat -c %Ybefore BSDstat -f %m, avoiding GNUstat -f’s filesystem-status output from poisoning the timestamp value. - Adds in-script commentary explaining the platform-specific
statbehavior and why the ordering is safe.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
Summary
session-start-orphan-sweep.shSessionStart hook was failing withline 37: File: unbound variableon Bazzite/Linux (GNU coreutils), while working fine on macOS.stat -f %mfirst, assuming it would fail on Linux and fall through tostat -c %Y. But GNU stat's-fflag is a valid (different) flag — filesystem-status mode — so it "succeeds" and dumps unrelated verbose filesystem text instead of erroring on the invalid%mdirective. That garbage became$last, and$((now - last))then tried to evaluate the leading word "File" as a variable, trippingset -u.stat -c %Yfirst, then BSD-stylestat -f %mas fallback. Safe on both platforms — each flavor fails cleanly when its syntax doesn't match, so the ordering only matters for which one is tried first and succeeds correctly.Test plan
bash -x .claude/hooks/session-start-orphan-sweep.shshowedlastgetting set to a multi-linestat -ffilesystem dump, then failing on the arithmetic line.stat -c %Ysucceeding cleanly,agecomputed correctly, script exits 0.shellcheckclean on the modified script.stat -f/stat -ccross-platform usages — this was the only occurrence.pnpm run check(pre-commit hooks) passed clean.🤖 Generated with Claude Code