fix: self-install Defender deps and load from plugin root#8
Merged
Conversation
- Add SessionStart hook that runs npm install in CLAUDE_PLUGIN_ROOT on first use (no-op if node_modules already present) - Use createRequire pointed at plugin root so defender is loaded from the plugin's own node_modules, not the user's project directory Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
1 issue found across 2 files
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="hooks/hooks.json">
<violation number="1" location="hooks/hooks.json:8">
P2: The install guard is too broad: checking only `node_modules` can permanently skip dependency installation after a partial/corrupt install.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
There was a problem hiding this comment.
Pull request overview
This PR fixes Defender not running in Claude plugin environments by ensuring dependencies are installed into the plugin cache directory and by resolving @stackone/defender from the plugin’s own node_modules rather than the user’s project.
Changes:
- Add a
SessionStarthook to runnpm installinCLAUDE_PLUGIN_ROOT(guarded by presence ofnode_modules). - Update
scan-tool-result.mjsto load@stackone/defenderviacreateRequirerooted at the plugin directory.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| scripts/scan-tool-result.mjs | Switch Defender module resolution to the plugin root so the hook can actually load Defender in cached plugin installs. |
| hooks/hooks.json | Add a SessionStart hook to self-install Node dependencies into the plugin root on first run. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Check node_modules/@stackone/defender instead of node_modules/ to avoid permanently skipping a partial/corrupt install - Update script header: Defender is now loaded from plugin root, not the user's project (identified by cubic and Copilot review) Co-Authored-By: Claude Sonnet 4.6 <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.
Summary
SessionStarthook that runsnpm installinCLAUDE_PLUGIN_ROOTthe first time a session starts after plugin install. Subsequent sessions skip it (guarded by[ -d node_modules ]).scan-tool-result.mjsscript to load@stackone/defenderfrom the plugin's ownnode_modulesusingcreateRequire, instead of looking in the user's project directory (which would silently fail for most users).Why this was broken
The plugin cache at
~/.claude/plugins/cache/stackone-marketplace/...has nonode_modules. The previousimport("@stackone/defender")would silentlyprocess.exit(0)on every hook invocation, meaning Defender never actually ran.Test plan
npm installruns once in plugin rootWebFetchorBashreturning injection content is blocked (exit 2)🤖 Generated with Claude Code
Summary by cubic
Ensure the Defender hook runs by self-installing deps and resolving modules from the plugin root. Tightens the install guard to avoid skipping after a partial install, fixing silent no-ops where
@stackone/defenderfailed to load.SessionStarthook to runnpm install --prefix "$CLAUDE_PLUGIN_ROOT" --silenton first session; skip only whennode_modules/@stackone/defenderexists.scan-tool-result.mjsto load@stackone/defenderviacreateRequireanchored atCLAUDE_PLUGIN_ROOT, blocking maliciousBash/WebFetch/WebSearchoutput.Written for commit 7e13d63. Summary will update on new commits.