fix(plugins): stop stripLegacyHooks from deleting the plugin's own hooks

claude plugin install materializes the plugin's inline hooks into
~/.claude/settings.json itself, with \${CLAUDE_PLUGIN_ROOT} resolved to the
actual cache path — confirmed by installing the plugin for real and
inspecting the file. Those entries also contain "hook-handler.js", so
isOurEntry()'s plain substring match could not tell a legitimate
plugin-installed hook from a leftover npm run install-hooks entry: every
SessionStart would have stripped the plugin's own working hooks right back
out. isCheckoutHookEntry() only removes entries whose command does NOT
resolve under ~/.claude/plugins/cache/. plugin-doctor.js's duplicate-hook
count uses the same predicate.
This commit is contained in:
2026-08-10 16:28:59 +07:00
parent a65ee1512e
commit 205f40c29c
5 changed files with 103 additions and 17 deletions
+2 -2
View File
@@ -14,7 +14,6 @@ const os = require("os");
const path = require("path");
const boot = require("./plugin-bootstrap");
const { isOurEntry } = require("./install-hooks");
const { getSettingsPath, getDataDir } = require("../server/lib/claude-home");
const { mcpBuildStatus } = require("./check-mcp-build");
@@ -104,9 +103,10 @@ function countLegacyHookEntries() {
try {
const settings = JSON.parse(fs.readFileSync(getSettingsPath(), "utf8"));
if (!settings.hooks) return 0;
const isLegacy = boot.isCheckoutHookEntry();
return Object.values(settings.hooks)
.filter(Array.isArray)
.reduce((n, entries) => n + entries.filter(isOurEntry).length, 0);
.reduce((n, entries) => n + entries.filter(isLegacy).length, 0);
} catch {
return 0;
}