Skip to content

Linux: stat -f %m fallback ordering causes session-orient hook error and arithmetic failures #43

@nmwoods1

Description

@nmwoods1

Summary

Several scripts use stat -f %m <file> || stat -c %Y <file> to read mtime, putting the BSD form first. On Linux (GNU coreutils), stat -f means --file-system, not "format" — so the first command does not fail. It succeeds and prints filesystem-info text like File: "ops/config.yaml" to stdout. The || fallback never triggers, the non-numeric output flows into arithmetic, and the script errors.

Observed on session start:

SessionStart:startup hook error
Failed with non-blocking status code:
/root/.claude/plugins/cache/agenticnotetaking/arscontexta/0.8.0/hooks/scripts/session-orient.sh: line 146: File: "ops/config.yaml"

Affected files (v0.8.0)

  • hooks/scripts/session-orient.sh — lines ~142, ~145
  • skills/health/SKILL.md — line ~410
  • skill-sources/rethink/SKILL.md — lines ~89, ~91

Fix

Swap the order so the GNU/Linux form is tried first and BSD/macOS is the fallback:

# was:
stat -f %m "$f" 2>/dev/null || stat -c %Y "$f" 2>/dev/null
# fixed:
stat -c %Y "$f" 2>/dev/null || stat -f %m "$f" 2>/dev/null

This works on both platforms: GNU stat -c succeeds on Linux; on macOS it cleanly errors (unknown option) and falls through to BSD stat -f. The original order fails because GNU stat -f produces non-failing-but-wrong output rather than erroring.

Environment

  • Linux 6.8.0 (Ubuntu)
  • GNU coreutils stat
  • arscontexta plugin v0.8.0
  • Claude Code

Happy to send a PR if useful.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions