A tiny friend in your Mac's notch and on your iPhone that keeps an eye on your AI coding agents: Claude Code, Codex, Cursor, Gemini CLI, Antigravity and more. Approve from the notch or your Lock Screen.
Swift ai-agentsanthropicantigravityclaudeclaude-codecodexcursordynamic-islandgemini-cliiosiphonlinuxmacosmacos-appmenubar-appnotchopen-sourceswiftswiftuiwindows
Fix nb-hook blocking Claude Code — shell wrapper + exit-0 guarantee
Louis Raille50c26eb2c8ab
diff --git a/NotchBuddy/Resources/InfoAppStore.plist b/NotchBuddy/Resources/InfoAppStore.plistindex 010787a6..bdf7ea2d 100644--- a/NotchBuddy/Resources/InfoAppStore.plist+++ b/NotchBuddy/Resources/InfoAppStore.plist@@ -19,7 +19,7 @@<key>CFBundleShortVersionString</key><string>1.0</string><key>CFBundleVersion</key>- <string>1</string>+ <string>2</string><key>ITSAppUsesNonExemptEncryption</key><false/><key>LSApplicationCategoryType</key>diff --git a/NotchBuddy/Sources/App/HookServer.swift b/NotchBuddy/Sources/App/HookServer.swiftindex 8dd6c4ac..a021f8cc 100644--- a/NotchBuddy/Sources/App/HookServer.swift+++ b/NotchBuddy/Sources/App/HookServer.swift@@ -17,9 +17,9 @@ final class HookServer: @unchecked Sendable {static var socketPath: String { supportDir.appendingPathComponent("nb.sock").path }static var hookScriptPath: String {#if APPSTORE- // Written to ~/.claude/coucou/nb-hook via security-scoped bookmark during hook installation- return FileManager.default.homeDirectoryForCurrentUser- .appendingPathComponent(".claude/coucou/nb-hook").path+ // Use real user home (not container home) for the hook script path in settings.json+ let realHome = NSHomeDirectoryForUser(NSUserName()) ?? FileManager.default.homeDirectoryForCurrentUser.path+ return URL(fileURLWithPath: realHome).appendingPathComponent(".claude/coucou/nb-hook").path#elsereturn supportDir.appendingPathComponent("nb-hook").path#endif@@ -36,6 +36,8 @@ final class HookServer: @unchecked Sendable {// MARK: - Startfunc start() {+ // Ensure support directory exists before socket server tries to bind+ try? FileManager.default.createDirectory(at: Self.supportDir, withIntermediateDirectories: true)#if !APPSTOREinstallHookScript()#endif@@ -455,16 +457,18 @@ final class HookServer: @unchecked Sendable {func installHookScript() {#if APPSTORE// In App Store mode the script is written during settings hook installation- // (requires a security-scoped bookmark to ~/.claude chosen by the user)+ // (requires NSOpenPanel to ~/.claude chosen by the user)#elselet dir = Self.supportDirtry? FileManager.default.createDirectory(at: dir, withIntermediateDirectories: true)- let scriptURL = URL(fileURLWithPath: Self.hookScriptPath)- try? nbHookScript.write(to: scriptURL, atomically: true, encoding: .utf8)- _ = try? FileManager.default.setAttributes(- [.posixPermissions: 0o755 as NSNumber],- ofItemAtPath: scriptURL.path- )+ // nb-hook: shell wrapper (always exits 0, calls nb-hook.py via python3)+ let wrapperURL = URL(fileURLWithPath: Self.hookScriptPath)+ try? nbHookShellWrapper.write(to: wrapperURL, atomically: true, encoding: .utf8)+ _ = try? FileManager.default.setAttributes([.posixPermissions: 0o755 as NSNumber], ofItemAtPath: wrapperURL.path)+ // nb-hook.py: Python relay+ let pyURL = wrapperURL.deletingLastPathComponent().appendingPathComponent("nb-hook.py")+ try? nbHookPythonGitHub.write(to: pyURL, atomically: true, encoding: .utf8)+ _ = try? FileManager.default.setAttributes([.posixPermissions: 0o755 as NSNumber], ofItemAtPath: pyURL.path)#endif}@@ -586,26 +590,20 @@ final class HookServer: @unchecked Sendable {// MARK: - App Store: hooks via security-scoped bookmark#if APPSTORE- /// App Store variant — needs a security-scoped bookmark URL pointing to ~/.claude- func previewClaudeHooksAppStore(claudeURL: URL) throws -> String {- let accessing = claudeURL.startAccessingSecurityScopedResource()- defer { if accessing { claudeURL.stopAccessingSecurityScopedResource() } }+ /// Writes nb-hook script and updates settings.json in one shot.+ /// claudeURL must be a URL from NSOpenPanel (sandbox access is granted immediately — no security scope needed).+ func installAndWriteClaudeHooksAppStore(claudeURL: URL) throws {let data = try buildHooksData(claudeURL: claudeURL)- _pendingHooksData = data- return String(data: data, encoding: .utf8) ?? ""- }-- func writeClaudeHooksAppStore(claudeURL: URL) throws {- guard let data = _pendingHooksData else { return }- let accessing = claudeURL.startAccessingSecurityScopedResource()- defer { if accessing { claudeURL.stopAccessingSecurityScopedResource() } }- // Write the nb-hook script into ~/.claude/coucou/nb-hook+ // Write nb-hook (shell wrapper) + nb-hook.py (Python relay) into ~/.claude/coucou/let coucouDir = claudeURL.appendingPathComponent("coucou")try FileManager.default.createDirectory(at: coucouDir, withIntermediateDirectories: true)- let scriptURL = coucouDir.appendingPathComponent("nb-hook")- try nbHookScriptAppStore.write(to: scriptURL, atomically: true, encoding: .utf8)- _ = try? FileManager.default.setAttributes([.posixPermissions: 0o755 as NSNumber], ofItemAtPath: scriptURL.path)+ let wrapperURL = coucouDir.appendingPathComponent("nb-hook")+ try nbHookShellWrapper.write(to: wrapperURL, atomically: true, encoding: .utf8)+ _ = try? FileManager.default.setAttributes([.posixPermissions: 0o755 as NSNumber], ofItemAtPath: wrapperURL.path)+ let pyURL = coucouDir.appendingPathComponent("nb-hook.py")+ try nbHookPythonAppStore.write(to: pyURL, atomically: true, encoding: .utf8)+ _ = try? FileManager.default.setAttributes([.posixPermissions: 0o755 as NSNumber], ofItemAtPath: pyURL.path)// Write settings.json (with backup)let settingsURL = claudeURL.appendingPathComponent("settings.json")@@ -614,12 +612,10 @@ final class HookServer: @unchecked Sendable {let backupURL = claudeURL.appendingPathComponent("settings.json.bak-\(formatter.string(from: Date()))")try? FileManager.default.copyItem(at: settingsURL, to: backupURL)try data.write(to: settingsURL, options: .atomic)- _pendingHooksData = nil+ UserDefaults.standard.set(true, forKey: "coucouHooksInstalled")}func uninstallClaudeHooksAppStore(claudeURL: URL) throws {- let accessing = claudeURL.startAccessingSecurityScopedResource()- defer { if accessing { claudeURL.stopAccessingSecurityScopedResource() } }let settingsURL = claudeURL.appendingPathComponent("settings.json")guard let data = try? Data(contentsOf: settingsURL),var settings = try? JSONSerialization.jsonObject(with: data) as? [String: Any],@@ -639,6 +635,7 @@ final class HookServer: @unchecked Sendable {settings["hooks"] = hookslet newData = try JSONSerialization.data(withJSONObject: settings, options: [.prettyPrinted, .sortedKeys])try newData.write(to: settingsURL, options: .atomic)+ UserDefaults.standard.set(false, forKey: "coucouHooksInstalled")}private func buildHooksData(claudeURL: URL) throws -> Data {@@ -681,11 +678,31 @@ extension Notification.Name {static let hookExpand = Notification.Name("notchBuddy.hookExpand")}-// MARK: - nb-hook Python script content+// MARK: - nb-hook shell wrapper (same for both GitHub and App Store)+// Invoked by Claude Code via /bin/sh or directly via shebang.+// Always exits 0 — never blocks Claude Code.+// Checks xcode-select before running python3 to avoid triggering the+// "install developer tools" dialog on machines without Xcode CLI tools.++private let nbHookShellWrapper = """+#!/bin/sh+# Coucou hook relay — always exits 0, never blocks Claude Code+HOOK_DIR="$(dirname "$0")"+if xcode-select -p >/dev/null 2>&1; then+ out=$(/usr/bin/python3 "$HOOK_DIR/nb-hook.py" 2>/dev/null)+ rc=$?+ if [ "$rc" -eq 0 ] && [ -n "$out" ]; then+ printf '%s\\n' "$out"+ fi+fi+exit 0+"""++// MARK: - nb-hook Python relay (GitHub / non-sandboxed version)-private let nbHookScript = """+private let nbHookPythonGitHub = """#!/usr/bin/env python3-# nb-hook — Coucou hook relay for Claude Code+# nb-hook.py — Coucou hook relay for Claude Code (GitHub version)# Reads JSON from stdin, forwards to Coucou via Unix socket, translates response.import sys, json, os, socket@@ -773,11 +790,11 @@ main()sys.exit(0)"""-// MARK: - nb-hook script for App Store (socket in sandboxed container)+// MARK: - nb-hook Python relay (App Store — socket in sandboxed container)-private let nbHookScriptAppStore = """+private let nbHookPythonAppStore = """#!/usr/bin/env python3-# nb-hook — Coucou (App Store) hook relay for Claude Code+# nb-hook.py — Coucou (App Store) hook relay for Claude Code# Socket lives inside the sandboxed container; script runs outside the sandbox.import sys, json, os, socketdiff --git a/NotchBuddy/Sources/App/SettingsView.swift b/NotchBuddy/Sources/App/SettingsView.swiftindex 9af2afbb..95a1727a 100644--- a/NotchBuddy/Sources/App/SettingsView.swift+++ b/NotchBuddy/Sources/App/SettingsView.swift@@ -10,9 +10,6 @@ struct SettingsView: View {@State private var showDiff: Bool = false@State private var pendingHookJSON: String = ""@State private var hookNeedsUpdate: Bool = HookServer.hooksNeedUpdate()- #if APPSTORE- @State private var claudeAccessGranted: Bool = (UserDefaults.standard.data(forKey: "claudeDirectoryBookmark") != nil)- #endif// Integration keys@State private var resendKey: String = KeychainStore.shared.get("resend-api-key") ?? ""@@ -81,22 +78,14 @@ struct SettingsView: View {#endif}#if APPSTORE- if claudeAccessGranted {- Text("~/.claude/coucou/nb-hook")- .font(.system(size: 11, design: .monospaced))- .foregroundColor(.secondary)- HStack(spacing: 10) {- Button("Install hooks") { installHooksAppStore() }- .buttonStyle(.borderedProminent)- Button("Uninstall") { uninstallHooksAppStore() }- .buttonStyle(.bordered)- }- } else {- Text("Choose your ~/.claude folder so Coucou can add its hooks.")- .font(.system(size: 12))- .foregroundColor(.secondary)- Button("Choose .claude folder…") { chooseClaudeFolder() }+ Text("~/.claude/coucou/nb-hook")+ .font(.system(size: 11, design: .monospaced))+ .foregroundColor(.secondary)+ HStack(spacing: 10) {+ Button("Install hooks") { installHooksAppStore() }.buttonStyle(.borderedProminent)+ Button("Uninstall") { uninstallHooksAppStore() }+ .buttonStyle(.bordered)}#elseText("nb-hook : \(HookServer.hookScriptPath)")@@ -110,6 +99,7 @@ struct SettingsView: View {}#endif+ #if !APPSTOREif showDiff {ScrollView {Text(pendingHookJSON)@@ -121,17 +111,13 @@ struct SettingsView: View {.cornerRadius(6)HStack {- #if APPSTORE- Button("Confirm & write") { confirmInstallAppStore() }- .buttonStyle(.borderedProminent)- #elseButton("Confirm & write") { confirmInstall() }.buttonStyle(.borderedProminent)- #endifButton("Cancel") { showDiff = false; pendingHookJSON = "" }.buttonStyle(.bordered)}}+ #endif}.padding(6)}@@ -371,86 +357,46 @@ struct SettingsView: View {// MARK: - App Store: hooks via NSOpenPanel + security-scoped bookmark#if APPSTORE- private func chooseClaudeFolder() {+ /// Opens NSOpenPanel to select ~/.claude, then writes hooks directly.+ /// NSOpenPanel grants sandbox access immediately — no security-scoped bookmark needed.+ private func pickClaudeFolder(prompt: String) -> URL? {let panel = NSOpenPanel()- panel.message = "Choose your .claude folder so Coucou can add its hooks"- panel.prompt = "Choose"+ panel.message = "Select your .claude folder (press ⇧⌘. to show hidden files)"+ panel.prompt = promptpanel.canChooseFiles = falsepanel.canChooseDirectories = truepanel.allowsMultipleSelection = false- panel.directoryURL = FileManager.default.homeDirectoryForCurrentUser- if panel.runModal() == .OK, let url = panel.url {- do {- let data = try url.bookmarkData(- options: .withSecurityScope,- includingResourceValuesForKeys: nil,- relativeTo: nil- )- UserDefaults.standard.set(data, forKey: "claudeDirectoryBookmark")- claudeAccessGranted = true- statusMessage = "✓ .claude folder access granted."- } catch {- statusMessage = "❌ Bookmark error: \(error.localizedDescription)"- }- }- }-- private func resolveClaudeBookmark() -> URL? {- guard let data = UserDefaults.standard.data(forKey: "claudeDirectoryBookmark") else { return nil }- var isStale = false- guard let url = try? URL(resolvingBookmarkData: data,- options: .withSecurityScope,- relativeTo: nil,- bookmarkDataIsStale: &isStale) else { return nil }- if isStale {- // Re-prompt user if bookmark is stale- claudeAccessGranted = false- UserDefaults.standard.removeObject(forKey: "claudeDirectoryBookmark")+ panel.showsHiddenFiles = true+ let realHomePath = NSHomeDirectoryForUser(NSUserName()) ?? FileManager.default.homeDirectoryForCurrentUser.path+ panel.directoryURL = URL(fileURLWithPath: realHomePath)+ guard panel.runModal() == .OK, let url = panel.url else { return nil }+ guard url.lastPathComponent == ".claude" else {+ statusMessage = "❌ Select the .claude folder (hidden, in your Home directory)."return nil}return url}private func installHooksAppStore() {- guard let claudeURL = resolveClaudeBookmark() else {- claudeAccessGranted = false- statusMessage = "❌ .claude folder access lost — choose the folder again."- return- }- do {- let accessing = claudeURL.startAccessingSecurityScopedResource()- defer { if accessing { claudeURL.stopAccessingSecurityScopedResource() } }- pendingHookJSON = try HookServer.shared.previewClaudeHooksAppStore(claudeURL: claudeURL)- showDiff = true- statusMessage = "Review the JSON below before confirming."- } catch {- statusMessage = "❌ \(error.localizedDescription)"- }- }-- private func confirmInstallAppStore() {- guard let claudeURL = resolveClaudeBookmark() else {- claudeAccessGranted = false- statusMessage = "❌ .claude folder access lost."- return- }+ guard let claudeURL = pickClaudeFolder(prompt: "Select") else { return }+ let alert = NSAlert()+ alert.messageText = "Install Coucou hooks in ~/.claude?"+ alert.informativeText = "Will write:\n• ~/.claude/coucou/nb-hook\n• ~/.claude/settings.json (backup created first)"+ alert.addButton(withTitle: "Install")+ alert.addButton(withTitle: "Cancel")+ alert.alertStyle = .informational+ guard alert.runModal() == .alertFirstButtonReturn else { return }do {- try HookServer.shared.writeClaudeHooksAppStore(claudeURL: claudeURL)- showDiff = false- statusMessage = "✓ Hooks installed in ~/.claude/settings.json"- pendingHookJSON = ""+ try HookServer.shared.installAndWriteClaudeHooksAppStore(claudeURL: claudeURL)hookNeedsUpdate = false+ statusMessage = "✓ Hooks installed — restart VS Code to activate."} catch {- statusMessage = "❌ Write error: \(error.localizedDescription)"+ statusMessage = "❌ \(error.localizedDescription)"}}private func uninstallHooksAppStore() {- guard let claudeURL = resolveClaudeBookmark() else {- claudeAccessGranted = false- statusMessage = "❌ .claude folder access lost."- return- }+ guard let claudeURL = pickClaudeFolder(prompt: "Select") else { return }do {try HookServer.shared.uninstallClaudeHooksAppStore(claudeURL: claudeURL)statusMessage = "✓ Hooks removed."diff --git a/NotchBuddy/project.yml b/NotchBuddy/project.ymlindex c23dfc9d..c4c3fcc4 100644--- a/NotchBuddy/project.yml+++ b/NotchBuddy/project.yml@@ -94,7 +94,7 @@ targets:CFBundleName: CoucouCFBundleDisplayName: CoucouCFBundleIdentifier: fr.louisraille.Coucou- CFBundleVersion: "2"+ CFBundleVersion: "3"CFBundleShortVersionString: "1.0"CFBundlePackageType: APPLLSUIElement: YES