Skip to content

save-session.sh: PROJECT_DIR and PIPELINE_DIR miscalculated when installed as global plugin cache #9

Closed

Description

@oliverames

Bug

When installed via the Claude Code plugin marketplace (global cache at ~/.claude/plugins/cache/), save-session.sh silently fails on every invocation. No session history is ever written.

Root Cause

save-session.sh calculates PROJECT_DIR by walking 3 levels up from its own script path:

PROJECT_DIR="$(cd "$(dirname "$0")/../../.." && pwd)"
PIPELINE_DIR="${PROJECT_DIR}/.claude/remember"

This assumes the script lives at $PROJECT_ROOT/.claude/remember/scripts/save-session.sh — which is correct for a local install, but wrong when installed to the global plugin cache.

When installed via the marketplace, the script is at:

~/.claude/plugins/cache/claude-plugins-official/remember/0.1.0/scripts/save-session.sh

3 levels up resolves to:

~/.claude/plugins/cache/claude-plugins-official   ← wrong PROJECT_DIR

So PIPELINE_DIR becomes:

~/.claude/plugins/cache/claude-plugins-official/.claude/remember   ← doesn't exist

The script then fails at cd "$PIPELINE_DIR" with:

cd: /Users/.../.claude/plugins/cache/claude-plugins-official/.claude/remember: No such file or directory

This error appears in every log file under .remember/logs/autonomous/.

Evidence

post-tool-hook.sh correctly sets PROJECT_DIR from $CLAUDE_PROJECT_DIR and PLUGIN_ROOT from $CLAUDE_PLUGIN_ROOT — but these are not exported to the backgrounded save-session.sh subprocess, and save-session.sh unconditionally overwrites PROJECT_DIR anyway.

Suggested Fix

In post-tool-hook.sh, export PROJECT_DIR before the nohup call:

export PROJECT_DIR
nohup "$SAVE_SCRIPT" "$SESSION_ID" > ...

In save-session.sh, respect the exported value and derive PIPELINE_DIR from CLAUDE_PLUGIN_ROOT:

PROJECT_DIR="${PROJECT_DIR:-$(cd "$(dirname "$0")/../../.." && pwd)}"
PIPELINE_DIR="${CLAUDE_PLUGIN_ROOT:-${PROJECT_DIR}/.claude/remember}"

This preserves backward compatibility with local installs while correctly handling the global cache case.

Environment

  • Claude Code v2.1.91
  • Plugin installed via claude-plugins-official marketplace
  • macOS, Apple Silicon
  • Plugin cache path: ~/.claude/plugins/cache/claude-plugins-official/remember/0.1.0/

Activity

  1. ryan6416 commented on Apr 3, 2026

    @ryan6416

    Can confirm — seeing identical symptoms on macOS (CLI v2.1.91, plugin v0.1.0).

    Our .remember/logs/autonomous/save-*.log files contain the same error:

    save-session.sh: line 135: cd: /Users/.../.claude/plugins/cache/claude-plugins-official/.claude/remember: No such file or directory
    

    Interesting data point: the bug is project-dependent. For one project (foam), CLAUDE_PROJECT_DIR reaches the backgrounded save-session.sh and extraction works. For another project (logos-app), it does not — same error as described here. Both are plugin-mode installs from the marketplace.

    The current save-session.sh:57 has the CLAUDE_PROJECT_DIR fallback from the #8 fix:

    PROJECT_DIR="${CLAUDE_PROJECT_DIR:-$(cd "$(dirname "$0")/../../.." && pwd)}"

    But as you noted, post-tool-hook.sh doesn't export PROJECT_DIR before the nohup call, and CLAUDE_PROJECT_DIR propagation from Claude Code seems inconsistent across projects. Your suggested fix (export in post-tool-hook.sh + respect in save-session.sh) matches what we'd recommend.

    Separately, we found an additional bug: even when extraction succeeds, _parse_response() in pipeline/haiku.py can't parse the CLI v2+ --output-format json output (expects dict, gets array). Filing that as a separate issue.

  2. fdaviddpt commented on Apr 3, 2026

    @fdaviddpt
    Contributor

    Thanks for the detailed report — this is the kind of analysis that actually helps.

    Fixed in v0.3.0 (just pushed). The inline ../../.. path traversal has been replaced with a centralized resolve-paths.sh that all scripts source. Marketplace installs without CLAUDE_PROJECT_DIR now fail with a clear FATAL error instead of silently computing wrong paths. All hooks now log their resolved paths to .remember/logs/ and stderr is captured to .remember/logs/hook-errors.log.

    To update: /plugin → find "remember" → update (marketplace plugins are pinned at install time, they don't auto-update).

    One question: was the failure consistent (every project, every time) or intermittent (some projects worked, others didn't)? We're trying to understand whether Claude Code sometimes doesn't set CLAUDE_PROJECT_DIR for marketplace plugins, or if there's a race condition with nohup subprocesses. Your insight from seeing it work in one project but not another would really help narrow it down.

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