Skip to content

Commit f8bcec1

Browse files
George-iamclaude
andcommitted
fix: install SDK into CLAUDE_PLUGIN_ROOT for reliable ESM resolution
ESM import resolves packages relative to the importing file, not via NODE_PATH. Previous approach (SDK in CLAUDE_PLUGIN_DATA with NODE_PATH) failed because ESM ignores NODE_PATH. New approach: SessionStart hook runs npm install in CLAUDE_PLUGIN_ROOT itself, placing node_modules/ next to cli.mjs. ESM standard resolution finds SDK naturally. Simpler bin wrapper, no NODE_PATH hacks. Docs confirm CLAUDE_PLUGIN_ROOT is writable (but doesn't survive plugin updates — SDK re-installs on update, which is fine). Verified: LLM scan works (21 decisions, 8 from LLM, $0.39). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent b8e3a57 commit f8bcec1

1 file changed

Lines changed: 1 addition & 13 deletions

File tree

build.mjs

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,6 @@ await build({
6868
mkdirSync("dist/plugin/bin", { recursive: true });
6969
writeFileSync("dist/plugin/bin/axme-code", `#!/bin/bash
7070
PLUGIN_DIR="\$(cd "\$(dirname "\$0")/.." && pwd)"
71-
if [ -n "\$CLAUDE_PLUGIN_DATA" ]; then
72-
DATA_DIR="\$CLAUDE_PLUGIN_DATA"
73-
else
74-
# Find plugin data dir by pattern (name varies: axme-code, axme-code-inline, etc.)
75-
DATA_DIR="\$(ls -d \$HOME/.claude/plugins/data/axme-code* 2>/dev/null | head -1)"
76-
fi
77-
if [ -n "\$DATA_DIR" ]; then
78-
export NODE_PATH="\$DATA_DIR/node_modules:\$NODE_PATH"
79-
fi
8071
exec node "\$PLUGIN_DIR/cli.mjs" "\$@"
8172
`);
8273
chmodSync("dist/plugin/bin/axme-code", 0o755);
@@ -105,9 +96,6 @@ writeFileSync("dist/plugin/.mcp.json", JSON.stringify({
10596
axme: {
10697
command: "node",
10798
args: ["${CLAUDE_PLUGIN_ROOT}/server.mjs"],
108-
env: {
109-
NODE_PATH: "${CLAUDE_PLUGIN_DATA}/node_modules",
110-
},
11199
},
112100
},
113101
}, null, 2) + "\n");
@@ -119,7 +107,7 @@ writeFileSync("dist/plugin/hooks/hooks.json", JSON.stringify({
119107
SessionStart: [{
120108
hooks: [{
121109
type: "command",
122-
command: "diff -q ${CLAUDE_PLUGIN_ROOT}/package.json ${CLAUDE_PLUGIN_DATA}/package.json >/dev/null 2>&1 || (mkdir -p ${CLAUDE_PLUGIN_DATA} && cp ${CLAUDE_PLUGIN_ROOT}/package.json ${CLAUDE_PLUGIN_DATA}/ && cd ${CLAUDE_PLUGIN_DATA} && npm install --omit=dev --ignore-scripts 2>/dev/null) ; NODE_PATH=${CLAUDE_PLUGIN_DATA}/node_modules node ${CLAUDE_PLUGIN_ROOT}/cli.mjs check-init",
110+
command: "test -d ${CLAUDE_PLUGIN_ROOT}/node_modules/@anthropic-ai/claude-agent-sdk || (cd ${CLAUDE_PLUGIN_ROOT} && npm install --omit=dev --ignore-scripts 2>/dev/null) ; node ${CLAUDE_PLUGIN_ROOT}/cli.mjs check-init",
123111
timeout: 30,
124112
}],
125113
}],

0 commit comments

Comments
 (0)