Skip to content

hooks.json: stderr redirect fails in fresh worktrees because .remember/logs/ does not exist yet #23

Closed

Description

@rmcarv

Summary

In hooks/hooks.json (v0.5.0), both the SessionStart and PostToolUse commands redirect stderr to ${CLAUDE_PROJECT_DIR:-.}/.remember/logs/hook-errors.log before the hook script runs. The shell opens the redirect target first, so if .remember/logs/ does not exist yet, /bin/sh emits:

/bin/sh: /path/to/project/.remember/logs/hook-errors.log: No such file or directory

on every hook invocation until something else creates the directory. The script own mkdir -p in scripts/log.sh runs too late — the redirect has already failed.

This reliably reproduces in every fresh git worktree: the worktree has no .remember/ tree yet, so the very first SessionStart and every PostToolUse spam the UI with PostToolUse:Bash hook error banners.

Reproduction

  1. git worktree add ../myrepo-feature feature/x
  2. Open Claude Code in ../myrepo-feature
  3. Every tool call shows Failed with non-blocking status code: /bin/sh: .../.remember/logs/hook-errors.log: No such file or directory

Current hooks/hooks.json

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

Suggested fix

Prepend mkdir -p so the log directory is guaranteed to exist before the shell evaluates the redirect:

"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\""

Same change for the PostToolUse entry. Tiny diff, no behavior change for existing projects, silences the error for fresh worktrees / new clones.

Environment

  • Plugin: claude-plugins-official/[email protected]
  • Claude Code on macOS (Tahoe)
  • Hit in a git worktree with no .remember/ directory

Activity

  1. Atreyu4EVR commented on Apr 23, 2026

    @Atreyu4EVR

    Confirming this also reproduces outside of git worktree — any project directory without a pre-existing .remember/logs/ tree hits it on the first tool call, not just worktrees.

    Repro (no worktree involved):

    1. cd into a directory with no prior .remember/ (e.g. a fresh project root, or just ~/Desktop/Projects as a working dir)
    2. First Bash tool call produces:
      PostToolUse:Bash hook blocking error: /bin/sh: 1: cannot create <cwd>/.remember/logs/hook-errors.log: Directory nonexistent
      
    3. Fires on every subsequent tool call until the dir is created manually.

    Environment: [email protected], Claude Code on Ubuntu 24.04 (arm64), no worktree.

    The proposed fix in the issue description (mkdir -p ... && bash ...) resolves it cleanly.

  2. mcmanusj-reninc commented on Apr 23, 2026

    @mcmanusj-reninc

    +1 — reproduces identically on Windows 11 + Git Bash + Claude Code 2.1.116 in a fresh clone of the project (not a worktree). No .remember/ tree existed, so every PostToolUse tool call printed:

    /usr/bin/bash: line 1: /d/projects/ren/.remember/logs/hook-errors.log: No such file or directory
    

    Confirmed mkdir -p /d/projects/ren/.remember/logs immediately silences it. The proposed fix (prepending mkdir -p to the hook command in hooks/hooks.json) would resolve this cleanly on Windows too — nothing Windows-specific about the shell redirect behavior.

  3. clearly commented on Apr 23, 2026

    @clearly

    Confirming this bug on plugin 0.5.0 with a slightly different repro worth flagging: Claude Code auto-creates worktrees for skills and parallel-agent invocations, so end users hit this without ever running git worktree add themselves. Every time Claude Code spawns a new worktree (e.g., .claude/worktrees/<adjective>-<verb>-<noun>/), the first SessionStart and all subsequent PostToolUse hooks in that worktree emit the non-blocking error because .remember/logs/ doesn't exist yet there.

    The suggested mkdir -p fix would also resolve this auto-worktree variant.

    Env:

    • Claude Code on macOS (Darwin 25.4.0)
    • Plugin: remember@claude-plugins-official v0.5.0
    • Reproduces on every auto-generated worktree directory
  4. leo-artuai commented on Apr 23, 2026

    @leo-artuai

    Also hitting this — confirming on Claude Code 2.1.118 / macOS Darwin 25.2. A few extra data points and a standalone workaround for anyone landing here looking to silence it before the fix ships:

    Also reproduces when .remember/ exists but .remember/logs/ was cleaned. Not just fresh worktrees — any time someone wipes the directory (e.g. rm -rf .remember) the next session starts spamming again until the inner script's mkdir -p runs.

    Workaround without patching the plugin — user-level SessionStart hook in ~/.claude/settings.json that creates the directories before any plugin hook fires:

    "SessionStart": [
      { "hooks": [ { "type": "command",
        "command": "mkdir -p \"${CLAUDE_PROJECT_DIR:-.}/.remember/logs/autonomous\" \"${CLAUDE_PROJECT_DIR:-.}/.remember/tmp\""
      } ] }
    ]

    SessionStart always runs before the first tool call, so by the time any PostToolUse hook fires, the redirect target exists. Idempotent, fast, applies to every project/worktree without per-repo setup.

    The in-hook mkdir -p && bash ... change proposed above is still the right fix — this only helps users who can't wait.

  5. gfreschi commented on Apr 24, 2026

    @gfreschi

    Reproduced on Claude Code 2.1.x, macOS (Darwin 25.4.0), plugin remember@claude-plugins-official v0.5.0.

    Same signature (PostToolUse:Bash hook error Failed with non-blocking status code: /bin/sh: .../.remember/logs/hook-errors.log: No such file or directory) fires on every tool call in a fresh project directory until something else creates .remember/logs/. Confirms this is not worktree-specific — any new clone or greenfield folder reproduces it.

    The one-line mkdir -p ... && bash ... prepend in hooks/hooks.json suggested above would fix it without behavior change for existing projects. Happy to open a PR if a maintainer wants one.

  6. fdaviddpt commented on Apr 25, 2026

    @fdaviddpt
    Contributor

    Fixed in #33 — bootstrap-dirs.sh now creates the .remember/logs/ directory before any stderr redirect. hooks.json no longer contains inline 2>> redirects.

    Thank you @rmcarv for being the first to report this! Your detailed reproduction steps and root cause analysis (bash opens the 2>> target before the script runs) directly shaped the fix. With 20k installs, every fresh-project bug report helps us catch what our own testing missed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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