From c49a52b65e63dadb3195f115b9e5173596cf0cb2 Mon Sep 17 00:00:00 2001 From: Tyler Stapler Date: Mon, 9 Nov 2026 10:14:00 -0800 Subject: [PATCH] fix(llm-sync): don't copy marketplace plugins' hooks into Claude's settings.json Claude Code loads /plugin install'd plugins' hooks itself with ${CLAUDE_PLUGIN_ROOT} set. llm-sync also merged them into settings.json, duplicating them and running them with the variable unset (the claude-magic-compact UserPromptSubmit hook ran 'bun /src/hook.ts'). Co-Authored-By: Claude Sonnet 5.5 --- stapler-scripts/llm-sync/src/core.py | 3 ++ .../llm-sync/src/sources/plugins.py | 2 + .../src/targets/claude_plugin_installer.py | 4 +- .../llm-sync/test_claude_plugin_installer.py | 40 +++++++++++++++++++ 4 files changed, 48 insertions(+), 1 deletion(-) diff --git a/stapler-scripts/llm-sync/src/core.py b/stapler-scripts/llm-sync/src/core.py index 63de77e0..71744cd5 100644 --- a/stapler-scripts/llm-sync/src/core.py +++ b/stapler-scripts/llm-sync/src/core.py @@ -112,6 +112,9 @@ class Plugin: # hooks: event_type -> list of hook entries (each entry has optional matcher + hooks list) hooks: Dict[str, List[Dict[str, Any]]] = field(default_factory=dict) source_dir: Optional[str] = None + # Installed via Claude Code's `/plugin install`: Claude loads its hooks natively + # (with ${CLAUDE_PLUGIN_ROOT} set), so the Claude target must not copy them. + from_marketplace: bool = False class SyncSource(ABC): def load_agents(self) -> List[Agent]: diff --git a/stapler-scripts/llm-sync/src/sources/plugins.py b/stapler-scripts/llm-sync/src/sources/plugins.py index a38d3222..2fb6a05f 100644 --- a/stapler-scripts/llm-sync/src/sources/plugins.py +++ b/stapler-scripts/llm-sync/src/sources/plugins.py @@ -149,6 +149,8 @@ def load_plugins(self) -> List[Plugin]: # Marketplace plugins load first so dotfiles-committed global/local plugins # keep winning on a name collision (see the comment in __init__ above). marketplace_loaded = self._load_entries(self.marketplace_plugin_dirs) + for p in marketplace_loaded: + p.from_marketplace = True plugins.update({p.name: p for p in marketplace_loaded}) if marketplace_loaded: console.print( diff --git a/stapler-scripts/llm-sync/src/targets/claude_plugin_installer.py b/stapler-scripts/llm-sync/src/targets/claude_plugin_installer.py index e41d5774..49879576 100644 --- a/stapler-scripts/llm-sync/src/targets/claude_plugin_installer.py +++ b/stapler-scripts/llm-sync/src/targets/claude_plugin_installer.py @@ -86,7 +86,9 @@ def _install_skills(self, plugin: Plugin, dry_run: bool) -> int: return count def _install_hooks(self, plugin: Plugin, dry_run: bool) -> int: - if not plugin.hooks: + # Claude registers marketplace plugins' hooks itself; a copy in settings.json + # duplicates them and runs with ${CLAUDE_PLUGIN_ROOT} unset, so it fails. + if not plugin.hooks or plugin.from_marketplace: return 0 settings = {} diff --git a/stapler-scripts/llm-sync/test_claude_plugin_installer.py b/stapler-scripts/llm-sync/test_claude_plugin_installer.py index 12cfa555..e2d0000f 100644 --- a/stapler-scripts/llm-sync/test_claude_plugin_installer.py +++ b/stapler-scripts/llm-sync/test_claude_plugin_installer.py @@ -8,6 +8,7 @@ sys.path.append(str(Path(__file__).parent / "src")) +from core import Plugin from targets.claude_plugin_installer import ClaudePluginInstaller, _effective_command @@ -91,3 +92,42 @@ def test_merge_does_not_duplicate_home_prefixed_hook(): from _test_runner import run_tests run_tests(globals()) + + +def test_install_hooks_skips_marketplace_plugins(tmp_path): + settings = tmp_path / "settings.json" + installer = ClaudePluginInstaller() + installer.settings_file = settings + plugin = Plugin( + name="claude-magic-compact", + description="", + version="1.3.1", + hooks={ + "UserPromptSubmit": [ + {"hooks": [{"type": "command", "command": "bun ${CLAUDE_PLUGIN_ROOT}/src/hook.ts"}]} + ] + }, + from_marketplace=True, + ) + + added = installer._install_hooks(plugin, dry_run=False) + + assert added == 0 + assert not settings.exists() + + +def test_install_hooks_still_installs_dotfiles_plugins(tmp_path): + settings = tmp_path / "settings.json" + installer = ClaudePluginInstaller() + installer.settings_file = settings + plugin = Plugin( + name="core-hooks", + description="", + version="1", + hooks={"Stop": [{"hooks": [{"type": "command", "command": "echo done"}]}]}, + ) + + added = installer._install_hooks(plugin, dry_run=False) + + assert added == 1 + assert "echo done" in settings.read_text()