Summary
The SessionStart and PreCompact hooks fail with a non-blocking error on every session start when the current working directory does not contain a package.json (e.g. a monorepo root or a non-Node project). The user sees this on every startup:
SessionStart:startup hook error
Failed with non-blocking status code: No stderr output
Root cause
hooks/hooks.json runs:
npm install --silent --prefix ${CLAUDE_PLUGIN_ROOT} --omit=dev --no-audit --no-fund >/dev/null 2>&1 && node ${CLAUDE_PLUGIN_ROOT}/hooks/session-start.js
On Windows (npm 10.9.x, Node 22), npm install --prefix <dir> still tries to read package.json from the cwd, not from the prefix dir. When the cwd has no package.json, npm fails:
npm error code ENOENT
npm error syscall open
npm error path C:\Users\<user>\<project>\package.json
npm error enoent Could not read package.json: Error: ENOENT: no such file or directory
exit code 127. Because the command chains with &&, session-start.js never runs — so besides the error banner, the compact-state injection is silently skipped. 2>&1 >/dev/null swallows stderr, hence "No stderr output", which makes this hard to diagnose.
(Presumably worse in the other direction too: when the cwd does have a package.json, npm may resolve the install against the user's project instead of the plugin dir.)
Fix that works
cd into the plugin root instead of relying on --prefix, and don't let an npm hiccup kill the context injection once deps exist:
"command": "cd \"${CLAUDE_PLUGIN_ROOT}\" && npm install --silent --omit=dev --no-audit --no-fund >/dev/null 2>&1; node \"${CLAUDE_PLUGIN_ROOT}/hooks/session-start.js\""
Verified locally on Windows 11 / npm 10.9.8: original command exits 127 from a cwd without package.json; patched command exits 0 and session-start.js runs.
Related: #14 (npm install on every invocation — fixing that would also shrink this failure surface) and #13 (quoting ${CLAUDE_PLUGIN_ROOT}, folded into the snippet above).
Environment
- Windows 11 Pro, PowerShell/Git Bash
- Node 22 (
C:\Program Files\nodejs), npm 10.9.8
- morph-compact 0.2.8 via marketplace
- Project root without
package.json (app lives in a subdirectory)
Summary
The
SessionStartandPreCompacthooks fail with a non-blocking error on every session start when the current working directory does not contain apackage.json(e.g. a monorepo root or a non-Node project). The user sees this on every startup:Root cause
hooks/hooks.jsonruns:On Windows (npm 10.9.x, Node 22),
npm install --prefix <dir>still tries to readpackage.jsonfrom the cwd, not from the prefix dir. When the cwd has nopackage.json, npm fails:exit code 127. Because the command chains with
&&,session-start.jsnever runs — so besides the error banner, the compact-state injection is silently skipped.2>&1 >/dev/nullswallows stderr, hence "No stderr output", which makes this hard to diagnose.(Presumably worse in the other direction too: when the cwd does have a
package.json, npm may resolve the install against the user's project instead of the plugin dir.)Fix that works
cdinto the plugin root instead of relying on--prefix, and don't let an npm hiccup kill the context injection once deps exist:Verified locally on Windows 11 / npm 10.9.8: original command exits 127 from a cwd without
package.json; patched command exits 0 andsession-start.jsruns.Related: #14 (npm install on every invocation — fixing that would also shrink this failure surface) and #13 (quoting
${CLAUDE_PLUGIN_ROOT}, folded into the snippet above).Environment
C:\Program Files\nodejs), npm 10.9.8package.json(app lives in a subdirectory)