Skip to content

fix: session-orient hook crashes on Linux due to stat -f flag ambiguity#16

Open
ajmeese7 wants to merge 1 commit intoagenticnotetaking:mainfrom
ajmeese7:fix/stat-linux-compat
Open

fix: session-orient hook crashes on Linux due to stat -f flag ambiguity#16
ajmeese7 wants to merge 1 commit intoagenticnotetaking:mainfrom
ajmeese7:fix/stat-linux-compat

Conversation

@ajmeese7
Copy link

@ajmeese7 ajmeese7 commented Feb 21, 2026

Problem

The session-orient SessionStart hook crashes on Linux with an arithmetic syntax error at line 146. This causes a "SessionStart hook error" on every session start and resume.

The root cause is stat -f %m -- intended as macOS syntax to get file modification time. On Linux, -f is a valid flag meaning "filesystem stats" (statfs), so instead of failing and falling through to the || stat -c %Y fallback, it succeeds and dumps multi-line filesystem info to stdout. That garbage then gets fed into a bash arithmetic expression, producing:

line 146: File: "ops/config.yaml" ... syntax error in expression

Fix

  • hooks/scripts/session-orient.sh: Detect the platform once by testing which stat syntax returns a valid mtime, trying Linux (-c %Y) first since -f is the ambiguous flag. Wraps the detection in a helper function to avoid repeating the logic.
  • skill-sources/rethink/SKILL.md: Swap stat flag order to try Linux syntax first.
  • skills/health/SKILL.md: Same fix.

Testing

Tested on Ubuntu (Linux 6.17.0) where the hook was consistently failing.
Verified the hook completes successfully with exit code 0 after the fix.

On Linux, `stat -f %m` does not fail -- `-f` invokes filesystem stats
(statfs) which succeeds with multi-line output instead of a file mtime.
This means the `|| stat -c %Y` fallback never triggers, and the
garbage output gets fed into an arithmetic expression on line 146,
crashing the hook with a syntax error.

The fix detects the platform once by testing which stat syntax actually
returns a valid mtime, trying Linux (`-c %Y`) first since `-f` is the
ambiguous flag. Also fixes the same macOS-first stat pattern in
skills/health/SKILL.md and skill-sources/rethink/SKILL.md.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant