Skip to content

[BUG] ccplugin: derive-collection.sh crashes on macOS — BSD realpath does not support -m flag #95

@svidskiy

Description

@svidskiy

Bug

ccplugin fails silently or crashes on macOS when deriving the Milvus collection name from the project path. The derive-collection.sh script calls realpath -m, which is a GNU coreutils flag not available in the BSD realpath shipped with macOS.

Environment

  • memsearch: current main (post-0.2.0 ccplugin)
  • OS: macOS (any version — BSD userland)
  • ccplugin: installed via ~/.claude/plugins/

Steps to Reproduce

  1. Install ccplugin on macOS (without brew install coreutils)
  2. Open any Claude Code session in a project directory
  3. The SessionStart hook sources common.sh → calls derive-collection.sh

Error

realpath: illegal option -- m
usage: realpath [-q] [path ...]

The script exits non-zero due to set -euo pipefail, which causes the hook to fail. On some setups this surfaces as a silent empty collection name, breaking all subsequent memsearch calls.

Root Cause

derive-collection.sh line 16 checks only for the existence of realpath:

if command -v realpath &>/dev/null; then
  PROJECT_DIR="$(realpath -m "$PROJECT_DIR")"

macOS ships /bin/realpath (BSD), which exists but does not support the -m flag (--canonicalize-missing — resolve path without requiring it to exist). Only GNU realpath (Linux / brew install coreutils) supports -m.

The check passes on macOS → the next line crashes immediately.

Expected Behavior

The script should fall through to the existing elif [ -d "$PROJECT_DIR" ] fallback, which uses cd && pwd and works correctly on all platforms.

Fix

Replace the existence check with a functional test:

# before
if command -v realpath &>/dev/null; then

# after
if realpath -m "$PROJECT_DIR" &>/dev/null 2>&1; then

This tests whether -m actually works rather than whether the binary exists. On macOS the test fails silently and the fallback takes over. On Linux with GNU realpath it succeeds as before.

Platform matrix after fix:

Platform Before After
Linux (GNU realpath) ✅ works ✅ works
macOS (BSD realpath) ❌ crashes ✅ falls through to cd fallback
Windows (WSL / Git Bash) ✅ no realpath, skips ✅ unchanged

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions