Repository navigation
Closes #3602: Suppress ignored Claude notifications #3959
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 18 commits
25030ee
17f1477
636c344
bee9922
0cf31e7
5adc3d5
0a9029e
d9091ba
eb366d3
48ea5c2
a22d3b6
1a010d2
183a71a
9a613da
dcddc10
57574ad
23613f8
0d442bc
270a7c7
76ee9f0
4c7ba93
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -332,6 +332,7 @@ private struct ClaudeHookParsedInput { | |||||||||||||||||
| let rawObject: [String: Any]? | ||||||||||||||||||
| let object: [String: Any]? | ||||||||||||||||||
| let rawFallback: String? | ||||||||||||||||||
| let rawFallbackNotificationTypeValues: [String] | ||||||||||||||||||
| let sessionId: String? | ||||||||||||||||||
| let turnId: String? | ||||||||||||||||||
| let cwd: String? | ||||||||||||||||||
|
|
@@ -16696,6 +16697,16 @@ struct CMUXCLI { | |||||||||||||||||
|
|
||||||||||||||||||
| case "notification", "notify": | ||||||||||||||||||
| telemetry.breadcrumb("claude-hook.notification") | ||||||||||||||||||
| let notificationTypes = Self.claudeNotificationTypes(parsedInput: parsedInput) | ||||||||||||||||||
| let suppressedNotificationTypes = Self.suppressedClaudeNotificationTypes(for: notificationTypes) | ||||||||||||||||||
| if !suppressedNotificationTypes.isEmpty { | ||||||||||||||||||
| telemetry.breadcrumb( | ||||||||||||||||||
| "claude-hook.notification.suppressed", | ||||||||||||||||||
| data: ["types": suppressedNotificationTypes.sorted().joined(separator: ",")] | ||||||||||||||||||
| ) | ||||||||||||||||||
| print("OK") | ||||||||||||||||||
| return | ||||||||||||||||||
|
lawrencecchen marked this conversation as resolved.
Resolved
|
||||||||||||||||||
| } | ||||||||||||||||||
| var summary = summarizeClaudeHookNotification(parsedInput: parsedInput) | ||||||||||||||||||
|
|
||||||||||||||||||
| let mappedSession = parsedInput.sessionId.flatMap { try? sessionStore.lookup(sessionId: $0) } | ||||||||||||||||||
|
|
@@ -17312,7 +17323,7 @@ struct CMUXCLI { | |||||||||||||||||
| guard !trimmed.isEmpty, | ||||||||||||||||||
| let data = trimmed.data(using: .utf8), | ||||||||||||||||||
| let json = try? JSONSerialization.jsonObject(with: data, options: []), | ||||||||||||||||||
| let object = json as? [String: Any] else { | ||||||||||||||||||
| let object = Self.claudeHookObject(fromJSONValue: json) else { | ||||||||||||||||||
| let fallback = trimmed.isEmpty ? nil : truncate( | ||||||||||||||||||
| normalizedSingleLine(redactClaudeSensitiveSpans(trimmed)), | ||||||||||||||||||
| maxLength: 180 | ||||||||||||||||||
|
|
@@ -17321,6 +17332,7 @@ struct CMUXCLI { | |||||||||||||||||
| rawObject: nil, | ||||||||||||||||||
| object: nil, | ||||||||||||||||||
| rawFallback: fallback, | ||||||||||||||||||
| rawFallbackNotificationTypeValues: Self.claudeNotificationTypeValues(inRawFallback: trimmed), | ||||||||||||||||||
| sessionId: nil, | ||||||||||||||||||
| turnId: nil, | ||||||||||||||||||
| cwd: nil, | ||||||||||||||||||
|
|
@@ -17337,13 +17349,27 @@ struct CMUXCLI { | |||||||||||||||||
| rawObject: object, | ||||||||||||||||||
| object: compactObject, | ||||||||||||||||||
| rawFallback: nil, | ||||||||||||||||||
| rawFallbackNotificationTypeValues: [], | ||||||||||||||||||
| sessionId: sessionId, | ||||||||||||||||||
| turnId: turnId, | ||||||||||||||||||
| cwd: cwd, | ||||||||||||||||||
| transcriptPath: transcriptPath | ||||||||||||||||||
| ) | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| private static func claudeHookObject(fromJSONValue value: Any) -> [String: Any]? { | ||||||||||||||||||
| if let object = value as? [String: Any] { | ||||||||||||||||||
| return object | ||||||||||||||||||
| } | ||||||||||||||||||
| guard let string = value as? String, | ||||||||||||||||||
| let data = string.trimmingCharacters(in: .whitespacesAndNewlines).data(using: .utf8), | ||||||||||||||||||
| let nested = try? JSONSerialization.jsonObject(with: data, options: []), | ||||||||||||||||||
| let object = nested as? [String: Any] else { | ||||||||||||||||||
| return nil | ||||||||||||||||||
| } | ||||||||||||||||||
| return object | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| private func compactClaudeHookObject(_ object: [String: Any]) -> [String: Any] { | ||||||||||||||||||
| var compact: [String: Any] = [:] | ||||||||||||||||||
|
|
||||||||||||||||||
|
|
@@ -18722,6 +18748,231 @@ struct CMUXCLI { | |||||||||||||||||
| return ("Attention", "Claude needs your attention") | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| private static let claudeIgnoredNotificationTypesDefaultsKey = | ||||||||||||||||||
| ClaudeNotificationTypeNormalization.ignoredTypesDefaultsKey | ||||||||||||||||||
| private static let claudeIgnoredNotificationTypesEnvKey = | ||||||||||||||||||
| ClaudeNotificationTypeNormalization.ignoredTypesEnvironmentKey | ||||||||||||||||||
|
|
||||||||||||||||||
| private static func suppressedClaudeNotificationTypes(for types: Set<String>) -> Set<String> { | ||||||||||||||||||
| let ignoredTypes = ignoredClaudeNotificationTypes() | ||||||||||||||||||
| guard !ignoredTypes.isEmpty, !types.isEmpty else { | ||||||||||||||||||
| return [] | ||||||||||||||||||
| } | ||||||||||||||||||
| return ignoredTypes.intersection(types) | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| private static func ignoredClaudeNotificationTypes() -> Set<String> { | ||||||||||||||||||
| // Hook subprocess environments are immutable after terminal launch; read cmux.json first | ||||||||||||||||||
| // so existing terminals follow live settings changes. | ||||||||||||||||||
| if let settingsTypes = ignoredClaudeNotificationTypesFromSettingsFiles() { | ||||||||||||||||||
| return settingsTypes | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| if let env = ProcessInfo.processInfo.environment[claudeIgnoredNotificationTypesEnvKey] { | ||||||||||||||||||
| return normalizedClaudeNotificationTypes( | ||||||||||||||||||
| env.components(separatedBy: CharacterSet(charactersIn: ", \n\t")) | ||||||||||||||||||
| ) | ||||||||||||||||||
| } | ||||||||||||||||||
|
cursor[bot] marked this conversation as resolved.
Resolved
|
||||||||||||||||||
|
|
||||||||||||||||||
| if let stored = UserDefaults.standard.array(forKey: claudeIgnoredNotificationTypesDefaultsKey) as? [String] { | ||||||||||||||||||
| return normalizedClaudeNotificationTypes(stored) | ||||||||||||||||||
| } | ||||||||||||||||||
| if let stored = UserDefaults.standard.string(forKey: claudeIgnoredNotificationTypesDefaultsKey) { | ||||||||||||||||||
| return normalizedClaudeNotificationTypes( | ||||||||||||||||||
| stored.components(separatedBy: CharacterSet(charactersIn: ", \n\t")) | ||||||||||||||||||
| ) | ||||||||||||||||||
| } | ||||||||||||||||||
| return [] | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| private enum ClaudeIgnoredNotificationTypesFileLoadResult { | ||||||||||||||||||
| case missing | ||||||||||||||||||
| case invalid | ||||||||||||||||||
| case parsed([String]?) | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| private static func ignoredClaudeNotificationTypesFromSettingsFiles( | ||||||||||||||||||
| fileManager: FileManager = .default, | ||||||||||||||||||
| environment: [String: String] = ProcessInfo.processInfo.environment | ||||||||||||||||||
| ) -> Set<String>? { | ||||||||||||||||||
| let paths = claudeIgnoredNotificationTypesSettingsPaths( | ||||||||||||||||||
| fileManager: fileManager, | ||||||||||||||||||
| environment: environment | ||||||||||||||||||
| ) | ||||||||||||||||||
|
|
||||||||||||||||||
| for path in paths { | ||||||||||||||||||
| switch loadIgnoredClaudeNotificationTypes(at: path, fileManager: fileManager) { | ||||||||||||||||||
| case .missing: | ||||||||||||||||||
| continue | ||||||||||||||||||
| case .invalid: | ||||||||||||||||||
| continue | ||||||||||||||||||
|
coderabbitai[bot] marked this conversation as resolved.
Resolved
|
||||||||||||||||||
| case .parsed(let values): | ||||||||||||||||||
| if let values { | ||||||||||||||||||
| return normalizedClaudeNotificationTypes(values) | ||||||||||||||||||
| } | ||||||||||||||||||
| return [] | ||||||||||||||||||
| } | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| return nil | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| private static func claudeIgnoredNotificationTypesSettingsPaths( | ||||||||||||||||||
| fileManager: FileManager, | ||||||||||||||||||
| environment: [String: String] | ||||||||||||||||||
| ) -> [String] { | ||||||||||||||||||
| var paths: [String] = [] | ||||||||||||||||||
| var seen = Set<String>() | ||||||||||||||||||
|
|
||||||||||||||||||
| func append(_ path: String) { | ||||||||||||||||||
| let standardized = URL(fileURLWithPath: path).standardizedFileURL.path | ||||||||||||||||||
| if seen.insert(standardized).inserted { | ||||||||||||||||||
| paths.append(standardized) | ||||||||||||||||||
| } | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| append(expandedSettingsPath( | ||||||||||||||||||
| primarySettingsDisplayPath, | ||||||||||||||||||
| fileManager: fileManager, | ||||||||||||||||||
| environment: environment | ||||||||||||||||||
| )) | ||||||||||||||||||
| append(expandedSettingsPath( | ||||||||||||||||||
| legacySettingsDisplayPath, | ||||||||||||||||||
| fileManager: fileManager, | ||||||||||||||||||
| environment: environment | ||||||||||||||||||
| )) | ||||||||||||||||||
|
|
||||||||||||||||||
| for appSupportURL in CmuxApplicationSupportDirectories.userDirectories( | ||||||||||||||||||
| environment: environment, | ||||||||||||||||||
| fileManager: fileManager | ||||||||||||||||||
| ) { | ||||||||||||||||||
| append( | ||||||||||||||||||
| appSupportURL | ||||||||||||||||||
| .appendingPathComponent("com.cmuxterm.app", isDirectory: true) | ||||||||||||||||||
| .appendingPathComponent("settings.json", isDirectory: false) | ||||||||||||||||||
| .path | ||||||||||||||||||
| ) | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| return paths | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| private static func expandedSettingsPath( | ||||||||||||||||||
| _ rawPath: String, | ||||||||||||||||||
| fileManager: FileManager, | ||||||||||||||||||
| environment: [String: String] | ||||||||||||||||||
| ) -> String { | ||||||||||||||||||
| let homePath = environment["HOME"] ?? fileManager.homeDirectoryForCurrentUser.path | ||||||||||||||||||
| let expanded: String | ||||||||||||||||||
| if rawPath == "~" { | ||||||||||||||||||
| expanded = homePath | ||||||||||||||||||
| } else if rawPath.hasPrefix("~/") { | ||||||||||||||||||
| expanded = (homePath as NSString).appendingPathComponent(String(rawPath.dropFirst(2))) | ||||||||||||||||||
| } else { | ||||||||||||||||||
| expanded = rawPath | ||||||||||||||||||
| } | ||||||||||||||||||
| return URL(fileURLWithPath: expanded).standardizedFileURL.path | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| private static func loadIgnoredClaudeNotificationTypes( | ||||||||||||||||||
| at path: String, | ||||||||||||||||||
| fileManager: FileManager | ||||||||||||||||||
| ) -> ClaudeIgnoredNotificationTypesFileLoadResult { | ||||||||||||||||||
| var isDirectory = ObjCBool(false) | ||||||||||||||||||
| guard fileManager.fileExists(atPath: path, isDirectory: &isDirectory) else { | ||||||||||||||||||
| return .missing | ||||||||||||||||||
| } | ||||||||||||||||||
| guard !isDirectory.boolValue, | ||||||||||||||||||
| let data = fileManager.contents(atPath: path), | ||||||||||||||||||
| !data.isEmpty, | ||||||||||||||||||
| let sanitized = try? JSONCParser.preprocess(data: data), | ||||||||||||||||||
| let rootObject = try? JSONSerialization.jsonObject(with: sanitized, options: []), | ||||||||||||||||||
| let root = rootObject as? [String: Any] else { | ||||||||||||||||||
| return .invalid | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| guard let notifications = root["notifications"] as? [String: Any], | ||||||||||||||||||
| let rawValues = notifications["ignoredClaudeNotificationTypes"] else { | ||||||||||||||||||
| return .parsed(nil) | ||||||||||||||||||
|
cursor[bot] marked this conversation as resolved.
Resolved
|
||||||||||||||||||
| } | ||||||||||||||||||
| guard let values = rawValues as? [String] else { | ||||||||||||||||||
| return .parsed(nil) | ||||||||||||||||||
| } | ||||||||||||||||||
| return .parsed(values) | ||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| private static func claudeNotificationTypes(parsedInput: ClaudeHookParsedInput) -> Set<String> { | ||||||||||||||||||
| var rawValues: [String] = [] | ||||||||||||||||||
| if let object = parsedInput.rawObject ?? parsedInput.object { | ||||||||||||||||||
| rawValues.append(contentsOf: claudeNotificationTypeValues(inJSONValue: object)) | ||||||||||||||||||
| } | ||||||||||||||||||
| rawValues.append(contentsOf: parsedInput.rawFallbackNotificationTypeValues) | ||||||||||||||||||
| return normalizedClaudeNotificationTypes(rawValues) | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| private enum ClaudeNotificationTypeExtractionScope { | ||||||||||||||||||
| case root | ||||||||||||||||||
| case notificationPayload | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| private static func claudeNotificationTypeValues( | ||||||||||||||||||
| inRawFallback fallback: String, | ||||||||||||||||||
| scope: ClaudeNotificationTypeExtractionScope = .root | ||||||||||||||||||
| ) -> [String] { | ||||||||||||||||||
| let trimmed = fallback.trimmingCharacters(in: .whitespacesAndNewlines) | ||||||||||||||||||
| guard !trimmed.isEmpty, | ||||||||||||||||||
| let data = trimmed.data(using: .utf8), | ||||||||||||||||||
| let json = try? JSONSerialization.jsonObject(with: data, options: []) else { | ||||||||||||||||||
| return [] | ||||||||||||||||||
| } | ||||||||||||||||||
| return claudeNotificationTypeValues(inJSONValue: json, scope: scope) | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| private static func claudeNotificationTypeValues( | ||||||||||||||||||
| inJSONValue value: Any, | ||||||||||||||||||
| scope: ClaudeNotificationTypeExtractionScope = .root | ||||||||||||||||||
| ) -> [String] { | ||||||||||||||||||
| if let object = value as? [String: Any] { | ||||||||||||||||||
| var values = claudeNotificationTypeValues(in: object, scope: scope) | ||||||||||||||||||
| for key in ["notification", "data"] { | ||||||||||||||||||
| if let nested = object[key] { | ||||||||||||||||||
| values.append(contentsOf: claudeNotificationTypeValues( | ||||||||||||||||||
| inJSONValue: nested, | ||||||||||||||||||
| scope: .notificationPayload | ||||||||||||||||||
| )) | ||||||||||||||||||
| } | ||||||||||||||||||
| } | ||||||||||||||||||
| return values | ||||||||||||||||||
| } | ||||||||||||||||||
| if let values = value as? [Any] { | ||||||||||||||||||
| return values.flatMap { claudeNotificationTypeValues(inJSONValue: $0, scope: scope) } | ||||||||||||||||||
| } | ||||||||||||||||||
| if let string = value as? String { | ||||||||||||||||||
| return claudeNotificationTypeValues(inRawFallback: string, scope: scope) | ||||||||||||||||||
| } | ||||||||||||||||||
| return [] | ||||||||||||||||||
| } | ||||||||||||||||||
|
cursor[bot] marked this conversation as resolved.
Resolved
|
||||||||||||||||||
|
|
||||||||||||||||||
| private static func claudeNotificationTypeValues( | ||||||||||||||||||
| in object: [String: Any], | ||||||||||||||||||
| scope: ClaudeNotificationTypeExtractionScope | ||||||||||||||||||
| ) -> [String] { | ||||||||||||||||||
| let keys: [String] | ||||||||||||||||||
| switch scope { | ||||||||||||||||||
| case .root: | ||||||||||||||||||
| keys = ["notification_type", "matcher", "reason"] | ||||||||||||||||||
| case .notificationPayload: | ||||||||||||||||||
| keys = ["notification_type", "matcher", "reason", "type", "kind"] | ||||||||||||||||||
| } | ||||||||||||||||||
| return keys.compactMap { key in | ||||||||||||||||||
| object[key] as? String | ||||||||||||||||||
| } | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| private static func normalizedClaudeNotificationTypes(_ values: [String]) -> Set<String> { | ||||||||||||||||||
| ClaudeNotificationTypeNormalization.normalizedSet(values) | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| private func firstString(in object: [String: Any], keys: [String]) -> String? { | ||||||||||||||||||
| for key in keys { | ||||||||||||||||||
| guard let value = object[key] else { continue } | ||||||||||||||||||
|
|
||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| import Foundation | ||
|
|
||
| enum ClaudeNotificationTypeNormalization { | ||
| static let ignoredTypesDefaultsKey = "claudeCodeIgnoredNotificationTypes" | ||
| static let ignoredTypesEnvironmentKey = "CMUX_CLAUDE_IGNORED_NOTIFICATION_TYPES" | ||
| static let defaultIgnoredTypes: [String] = [] | ||
|
|
||
| static func normalized(_ raw: String) -> String? { | ||
| let collapsedWhitespace = raw | ||
| .trimmingCharacters(in: .whitespacesAndNewlines) | ||
| .components(separatedBy: .whitespacesAndNewlines) | ||
| .filter { !$0.isEmpty } | ||
| .joined(separator: "_") | ||
| let normalized = collapsedWhitespace | ||
| .replacingOccurrences(of: "-", with: "_") | ||
| .lowercased() | ||
| return normalized.isEmpty ? nil : normalized | ||
| } | ||
|
|
||
| static func normalizedSet(_ values: [String]) -> Set<String> { | ||
| Set(values.compactMap(normalized)) | ||
| } | ||
|
|
||
| static func normalizedUniqueList(_ values: [String]) -> [String] { | ||
| var seen = Set<String>() | ||
| return values.compactMap { raw in | ||
| guard let normalized = normalized(raw), | ||
| seen.insert(normalized).inserted else { | ||
| return nil | ||
| } | ||
| return normalized | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -452,6 +452,13 @@ final class CmuxSettingsFileStore { | |
| if let raw = jsonString(section["command"]) { | ||
| snapshot.managedUserDefaults[NotificationSoundSettings.customCommandKey] = .string(raw) | ||
| } | ||
| if let values = jsonStringArray(section["ignoredClaudeNotificationTypes"]) { | ||
| snapshot.managedUserDefaults[ClaudeCodeIntegrationSettings.ignoredNotificationTypesKey] = .stringArray( | ||
| ClaudeCodeIntegrationSettings.normalizedIgnoredNotificationTypes(values) | ||
| ) | ||
| } else if section.keys.contains("ignoredClaudeNotificationTypes") { | ||
| logInvalid("notifications.ignoredClaudeNotificationTypes", sourcePath: sourcePath) | ||
| } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. App merge ignores hook precedenceMedium Severity When a valid primary Additional Locations (1)Reviewed by Cursor Bugbot for commit 4c7ba93. Configure here. |
||
| } | ||
|
|
||
| private func parseTerminalSection( | ||
|
|
||


Uh oh!
There was an error while loading. Please reload this page.