Skip to content

Fix stat mtime read on GNU/Linux (SessionStart hook crashes during compact) - #49

Open
Shibachan1015 wants to merge 1 commit into
agenticnotetaking:mainfrom
Shibachan1015:fix/stat-mtime-gnu-linux
Open

Fix stat mtime read on GNU/Linux (SessionStart hook crashes during compact)#49
Shibachan1015 wants to merge 1 commit into
agenticnotetaking:mainfrom
Shibachan1015:fix/stat-mtime-gnu-linux

Conversation

@Shibachan1015

Copy link
Copy Markdown

Problem

stat -f %m FILE is BSD/macOS syntax. On GNU/Linux, -f means --file-system, so the command:

  1. fails on the bogus %m argument (exit 1), and
  2. prints filesystem info to stdout ( File: "ops/config.yaml" ...).

Since only stderr is redirected (2>/dev/null), that stdout leaks into CONFIG_MTIME / METH_MTIME. The subsequent arithmetic then aborts:

session-orient.sh: line 146: File: "ops/config.yaml"

This runs on every SessionStart:compact, so Linux users hit a hook crash whenever a session compacts.

Reproduce (Linux)

$ stat -f %m ops/config.yaml
stat: cannot read file system information for '%m': No such file or directory
  File: "ops/config.yaml"
    ID: ... Namelen: 255  Type: ext2/ext3
...

Fix

Try the GNU form (stat -c %Y) first, fall back to BSD (stat -f %m). Works on both Linux and macOS. Applied to all three files using the pattern:

  • hooks/scripts/session-orient.sh (lines 142, 145)
  • skill-sources/rethink/SKILL.md
  • skills/health/SKILL.md

Verified on GNU/Linux: CONFIG_MTIME now resolves to a clean epoch integer and the arithmetic runs without error.

🤖 Generated with Claude Code

https://claude.ai/code/session_01XvXshgWoaTKx7jAFNeyv77

…act)

`stat -f %m FILE` is BSD/macOS syntax. On GNU/Linux, `-f` means
`--file-system`, so the command fails on the bogus `%m` argument and
prints filesystem info to *stdout*. Because only stderr is redirected
(`2>/dev/null`), that output leaks into CONFIG_MTIME / METH_MTIME, and
the following arithmetic aborts:

    session-orient.sh: line 146: File: "ops/config.yaml"

This fires on every SessionStart:compact, so Linux users crash the hook
whenever a session compacts.

Fix: try the GNU form (`stat -c %Y`) first and fall back to BSD
(`stat -f %m`). Works on both Linux and macOS. Applied to all three
files using the pattern.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XvXshgWoaTKx7jAFNeyv77
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