Skip to content

SessionStart/PostToolUse hooks fail on first run when .remember/logs/ doesn't exist #43

@varunkasi

Description

@varunkasi

Bug

In a fresh project that has never run the remember plugin before, the SessionStart hook fails with:

SessionStart:startup hook error
Failed with non-blocking status code: /bin/sh: <project>/.remember/logs/hook-errors.log: No such file or directory

The same applies to the PostToolUse hook.

Root cause

hooks/hooks.json redirects stderr to ${CLAUDE_PROJECT_DIR}/.remember/logs/hook-errors.log:

"command": "bash \"${CLAUDE_PLUGIN_ROOT}/scripts/session-start-hook.sh\" 2>> \"${CLAUDE_PROJECT_DIR:-.}/.remember/logs/hook-errors.log\""

The shell opens the redirect target before the script runs. session-start-hook.sh does mkdir -p "$PROJECT/.remember/logs" internally, but that runs too late — /bin/sh has already failed to open the file because the directory doesn't exist yet on a fresh project.

Result: every brand-new project shows the hook error on first launch (it's reported as non-blocking, so the session still starts, but it's noisy and confusing).

Proposed fix

Prepend mkdir -p to the hook command itself so the directory exists before the redirection is parsed:

{
  "hooks": {
    "SessionStart": [
      {
        "hooks": [
          {
            "type": "command",
            "command": "mkdir -p \"${CLAUDE_PROJECT_DIR:-.}/.remember/logs\" && bash \"${CLAUDE_PLUGIN_ROOT}/scripts/session-start-hook.sh\" 2>> \"${CLAUDE_PROJECT_DIR:-.}/.remember/logs/hook-errors.log\""
          }
        ]
      }
    ],
    "PostToolUse": [
      {
        "hooks": [
          {
            "type": "command",
            "command": "mkdir -p \"${CLAUDE_PROJECT_DIR:-.}/.remember/logs\" && bash \"${CLAUDE_PLUGIN_ROOT}/scripts/post-tool-hook.sh\" 2>> \"${CLAUDE_PROJECT_DIR:-.}/.remember/logs/hook-errors.log\""
          }
        ]
      }
    ]
  }
}

Verified locally — applying this patch eliminates the first-run error without changing any other behavior. Happy to send a PR if useful.

Environment

  • Plugin version: 0.5.0
  • Claude Code on macOS (darwin 25.4.0)

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