Skip to content

post-tool-hook.sh and user-prompt-hook.sh consult REMEMBER_HOOK_CWD without ever setting, clearing or validating it #417

Closed

Description

@fdaviddpt

Symptom

On a host that reuses one process environment across hook invocations, PostToolUse and UserPromptSubmit can resolve the project root from a REMEMBER_HOOK_CWD exported by a different session's SessionStart -- writing memory into the wrong project's store, with no diagnostic. Reachability is not established: whether any supported host reuses an environment that way is unknown, which is why this is filed rather than fixed.

Location

scripts/resolve-paths.sh:150 consults the variable:

elif [ -n "${REMEMBER_HOOK_CWD:-}" ] && [ -d "${REMEMBER_HOOK_CWD:-}" ]; then
    PROJECT_DIR="$REMEMBER_HOOK_CWD"

Only two of the hooks that source it manage the variable -- scripts/session-start-hook.sh:136-140 and scripts/session-end-hook.sh:167-171, each extracting cwd from its own stdin payload, rejecting embedded newlines, then exporting. scripts/post-tool-hook.sh and scripts/user-prompt-hook.sh source resolve-paths.sh and set nothing: they inherit whatever the environment already holds.

Mechanism

resolve-paths.sh's precedence is CLAUDE_PROJECT_DIR, then REMEMBER_HOOK_CWD, then the local-install derivation. On Claude Code the first arm always wins, so the second is unreachable there. On a host that sets neither -- the case #411 exists for -- the second arm is load-bearing, and for PostToolUse/UserPromptSubmit its value came from outside that hook's own invocation. A per-invocation process (the normal case) inherits nothing and correctly falls through to the local-install derivation; a reused one inherits a value nobody re-validated for this session.

Same shape as #407's REMEMBER_TRANSCRIPT_PATH: a variable trusted by any caller that happens to have it set.

What would settle it

Either observing a host that reuses a hook process environment across invocations -- which makes this reachable and worth a fix, each hook clearing or re-deriving the variable itself -- or establishing that no supported host does, which makes it a comment on resolve-paths.sh:150 naming the assumption.

Found by the self-review on #411's lane (PR #414), out of that lane's scope.

Activity

  1. added
    priority:low
    on Aug 28, 2026
  2. self-assigned this
    on Aug 28, 2026
  3. added 4 commits that reference this issue on Oct 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

priority:low

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions