Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions stapler-scripts/llm-sync/src/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]:
Expand Down
2 changes: 2 additions & 0 deletions stapler-scripts/llm-sync/src/sources/plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}
Expand Down
40 changes: 40 additions & 0 deletions stapler-scripts/llm-sync/test_claude_plugin_installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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()