Skip to content

Stop/Session hooks fail on Windows when CWD is on a different drive than %USERPROFILE% #285

@gowerlin

Description

@gowerlin

Summary

On Windows with Claude Code running in Git Bash / MSYS2, all three plugin hooks (SessionStart, SessionEnd, Stop) fail with MODULE_NOT_FOUND whenever the current working directory is on a different drive than %USERPROFILE%.

Observed error (project on D:\, plugin cache on C:\):

Stop hook error: Failed with non-blocking status code: node:internal/modules/cjs/loader:1386
Error: Cannot find module 'D:\c\Users\Gower\.claude\plugins\cache\openai-codex\codex\1.0.4\scripts\stop-review-gate-hook.mjs'
  code: 'MODULE_NOT_FOUND'

Note the bogus D:\c\ prefix.

Root Cause

hooks/hooks.json passes ${CLAUDE_PLUGIN_ROOT} directly to node:

"command": "node \"${CLAUDE_PLUGIN_ROOT}/scripts/stop-review-gate-hook.mjs\""

In Git Bash / MSYS2, Claude Code injects CLAUDE_PLUGIN_ROOT in POSIX form (e.g. /c/Users/Gower/.claude/plugins/...). Native node.exe does not understand /c/... — it interprets it as a drive-relative path under the current drive, prepending D: (the project drive) to produce D:\c\Users\..., which does not exist.

This affects all three hooks in 1.0.4/hooks/hooks.json: SessionStart, SessionEnd, Stop.

Repro

  1. Windows 11 + Claude Code in Git Bash / MSYS2.
  2. Install openai/codex-plugin-cc (cached under C:\Users\<user>\.claude\plugins\cache\...).
  3. Open Claude Code in a project located on a different drive (e.g. D:\some\project).
  4. Run anything that triggers the Stop hook (e.g. session ending).
  5. Observe Cannot find module 'D:\c\Users\...' error.

Suggested Fix

Wrap the env var with cygpath -w and fall back to the original value when cygpath is unavailable (Linux/macOS). Apply to all three hook commands:

"command": "node \"$(cygpath -w \"${CLAUDE_PLUGIN_ROOT}\" 2>/dev/null || echo \"${CLAUDE_PLUGIN_ROOT}\")/scripts/stop-review-gate-hook.mjs\""

Alternative: normalize CLAUDE_PLUGIN_ROOT inside the .mjs scripts via path.win32 / url.fileURLToPath so the JSON command stays simple.

Local Workaround

Patched hooks.json in the cache copy with the cygpath wrapper above. After the patch, sessions end cleanly with no MODULE_NOT_FOUND. (The patch is lost on plugin update, hence this report.)

Environment

  • OS: Windows 11 Pro for Workstations (10.0.26200)
  • Shell: Git Bash / MSYS2 (via Claude Code)
  • Node.js: v22.22.2
  • Plugin: openai-codex (codex 1.0.4)
  • Project drive ≠ %USERPROFILE% drive

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions