Repository navigation
fix(hooks): remove only Coucou's own nb-hook entries in the Claude paths - #944
Open
rahul05ranjan wants to merge 1 commit into
Open
rahul05ranjan wants to merge 1 commit into
rahul05ranjan wants to merge 1 commit into
Conversation
Install and uninstall removed a whole Claude Code hook group when any command in it mentioned coucou or NotchBuddy, so a user hook like ~/dev/coucou/scripts/lint.sh was deleted. Both paths now use the Gemini path's removeNbHookEntries, which removes only nb-hook commands and drops a group only when every entry in it was ours. Fixes Louis-CFM#854 Co-authored-by: rahul05ranjan <11793455+rahul05ranjan@users.noreply.github.com>
This branch has not been deployed
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.
Fixes #854.
What was wrong
The Claude Code install and uninstall paths (
HookServer.swift) removed a whole hook group from~/.claude/settings.jsonwhen any command inside it contained the substringscoucouorNotchBuddy:buildHooksData()(~L1481) — the per-event cleanup before reinstalling;uninstallClaudeHooks()(~L1506);buildHooksData(claudeURL:)(~L1719) anduninstallClaudeHooksAppStore(claudeURL:)(~L1682).So a user hook like
~/dev/coucou/scripts/lint.sh(likely for contributors to this repo), or any user hook sharing a matcher group with one of ours, was deleted on every install or uninstall. The Gemini path never had this problem:removeNbHookEntries(~L2011) removes only the entries whose command containsnb-hook, and drops a group only when every entry in it was ours.The fix
All four Claude sites now call the same
removeNbHookEntriesthe Gemini and Codex paths already use. Both builds' own commands always containnb-hook(<supportDir>/nb-hooknon-App Store,<~/.claude>/coucou/nb-hookApp Store, incl. the--askand status-line variants), andnb-hookis already the marker the rest of the file uses for "this one is ours" (statusLineInstalled,codexHooksInstalled, the Codex and Gemini cleanup). The doc comment onremoveNbHookEntriesnow says it serves both formats.Also added
NotchBuddy/Tests/ClaudeHookRemovalTests.swift, a standalone script in theHermesConfigMergerTests.swiftstyle:It keeps a copy of
removeNbHookEntriesplus the per-event install cleanup in sync, and covers: a user~/dev/coucou/...group surviving install, no duplicate nb-hook entries on reinstall,echo coucousurviving uninstall while the nb-hook entry goes, coucou-only groups dropped entirely, a/opt/NotchBuddy/...path that is not our hook surviving uninstall, and the legacy flat format.Verification
No Swift toolchain on this machine (arm64 Linux CI box), so:
removeAllon the two substrings vs per-entrynb-hookremoval), run on the settings shapes from Installing/uninstalling hooks removes user hooks whose command contains "coucou" #854:~/dev/coucou/scripts/lint.shgroupecho coucou+ our nb-hookecho coucoukept, nb-hook entry removed/opt/NotchBuddy/something-else~/dev/coucou/...on macOS App Store paths (lowercasecoucou)grep -n 'NotchBuddy.*removeAll\|coucou.*removeAll' NotchBuddy/Sources/App/HookServer.swiftfound the four group-level sites and nothing else; the status-line path already usedcmd.contains("nb-hook")("not ours — leave unchanged"), which is the behavior this PR extends to the group paths.swift NotchBuddy/Tests/ClaudeHookRemovalTests.swiftlocally (no toolchain); the script follows the same copy-and-assert pattern as the existingHermesConfigMergerTests.swift, so it runs the same way.Two deliberate non-changes: the detection reads (
hooksNeedUpdate,claudeHooksInstalled) still match the broad substrings — they only answer "are our hooks installed?" and removing nothing; and a user hook whose command itself containsnb-hookwould still be treated as ours, exactly as in the Gemini and Codex paths today.