Skip to content

SessionStart/PreCompact hooks run npm install on every invocation: 5-minute stall on claude --resume #14

Description

@memmmmike

Problem

hooks/hooks.json prefixes both the SessionStart and PreCompact hooks with:

npm install --silent --prefix ${CLAUDE_PLUGIN_ROOT} --omit=dev --no-audit --no-fund >/dev/null 2>&1 && node ...

This runs a full npm install on every session start and every compaction, even when node_modules is already populated. With the shipped 73MB package-lock.json, that install takes ~5 minutes of pure CPU on my machine (Fedora, npm 10.x):

real    5m2.947s
user    5m2.375s
sys     0m3.994s

Net effect: every claude --continue / claude --resume hangs for ~5 minutes before the prompt is usable, and PreCompact stalls compaction the same way. Because the install is silenced, there is no indication of what is blocking.

Fix

Guard the install so it only runs when dependencies are missing:

[ -d "${CLAUDE_PLUGIN_ROOT}/node_modules" ] || 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

(and the same for the PreCompact command.)

With the guard, the hook completes in 0.11s. npm ci with the guard would also work and is more reproducible. Alternatively, run the install once at plugin install time rather than per-hook.

Plugin version: 0.2.8.

Activity

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