Conversation
mcp-server-wrapper.js already probes for missing node_modules (deps externalized from the esbuild bundle, e.g. @anthropic-ai/claude-agent-sdk) and runs npm install before launching the server. cli/episodic-memory.js had no equivalent check, so the SessionStart `sync` hook — invoked directly, not through the wrapper — crashed with ERR_MODULE_NOT_FOUND on a fresh install/update, before the MCP server had a chance to self-heal node_modules for the plugin root. Reuses the existing install-check.js/install-runner.js utilities so both entry points share one self-heal path and one install lock. Co-Authored-By: Claude <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
`mcp-server-wrapper.js` already probes for missing `node_modules` (deps
externalized from the esbuild bundle — `@anthropic-ai/claude-agent-sdk`,
`better-sqlite3`, etc.) and runs `npm install` before launching the MCP
server (see the `#95`/`#161` fixes already in this repo).
`cli/episodic-memory.js`, the dispatcher the SessionStart hook invokes
directly (`episodic-memory sync --background`), had no equivalent check.
On a fresh plugin install/update — before the MCP server has had a chance
to self-heal `node_modules` for the plugin root — the SessionStart hook
crashes:
```
node:internal/modules/package_json_reader:301
Error [ERR_MODULE_NOT_FOUND]: Cannot find package '@anthropic-ai/claude-agent-sdk'
imported from .../dist/summarizer.js
```
This surfaces to the user as a Claude Code "SessionStart:startup hook
error," and recurs on every fresh install/update until something happens
to populate `node_modules` in that specific version directory (a manual
`npm install`, or an MCP connection racing ahead of the sync hook).
Fix
Give the CLI dispatcher the same self-heal check the MCP wrapper already
has, reusing the existing `install-check.js`/`install-runner.js`
utilities (same missing-deps probe, same single-flight install lock) so
both entry points share one code path instead of diverging further.
Skipped for `--help`/`-h`/no-args, since showing help doesn't need the
runtime deps.
Testing
existing `mcp-server-wrapper` integration test pattern in
`test/mcp-install-runner.test.ts`: spawns the real dispatcher against an
empty `CLAUDE_PLUGIN_ROOT` with a stub `npm` on `PATH`, and asserts the
install path is (and isn't, for `--help`) taken.