> For the complete documentation index, see [llms.txt](https://www.openclawbook.xyz/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://www.openclawbook.xyz/en/ch36-native-client-apps/36.1-macos-app.md). Agents can also search and read this documentation through its [MCP server](https://www.openclawbook.xyz/~gitbook/mcp).

# 36.1 macOS Application (OpenClaw\.app)

> **Generated by**: Claude Opus 4.6 (initial draft) / Claude Opus 5 (`v2026.3.9` revision) **Token usage**: Input \~175k tokens, Output \~8k tokens (this section) **Source baseline**: `v2026.3.9` (`v2026.3.8-170-g665f67726`)

***

The OpenClaw macOS application is a **menu bar application** that resides in the system menu bar, providing voice wake, conversation mode, and Gateway process management features. It is written in Swift 6.2 + SwiftUI and connects to a Gateway instance via WebSocket.

## 36.1.1 Swift + SwiftUI Architecture

### Project Structure

The macOS application is located in `apps/macos/` and uses Swift Package Manager (SPM) to manage dependencies:

```swift
// apps/macos/Package.swift
let package = Package(
    name: "OpenClaw",
    platforms: [.macOS(.v15)],   // Minimum macOS 15 (Sequoia)
    products: [
        .library(name: "OpenClawIPC", targets: ["OpenClawIPC"]),
        .library(name: "OpenClawDiscovery", targets: ["OpenClawDiscovery"]),
        .executable(name: "OpenClaw", targets: ["OpenClaw"]),        // Main app
        .executable(name: "openclaw-mac", targets: ["OpenClawMacCLI"]), // CLI tool
    ],
    dependencies: [
        .package(url: "MenuBarExtraAccess", exact: "1.2.2"),  // Menu bar extension
        .package(url: "swift-subprocess", from: "0.1.0"),     // Process management
        .package(url: "swift-log", from: "1.8.0"),
        .package(url: "Sparkle", from: "2.8.1"),              // Auto-update
        .package(url: "Peekaboo", branch: "main"),            // Automation
        .package(path: "../shared/OpenClawKit"),               // Shared library
    ],
)
```

The project consists of four targets:

| Target              | Type       | Responsibility                   |
| ------------------- | ---------- | -------------------------------- |
| `OpenClaw`          | Executable | Menu bar main application        |
| `OpenClawMacCLI`    | Executable | `openclaw-mac` command-line tool |
| `OpenClawIPC`       | Library    | Inter-process communication      |
| `OpenClawDiscovery` | Library    | Gateway service discovery        |

### Source Code Scale

The `Sources/OpenClaw/` directory contains approximately **191 Swift files**, covering all functional modules of the application:

```
Sources/OpenClaw/
├── AppState.swift                    # Global state (@Observable)
├── MenuBar.swift                     # @main entry point + MenuBarExtra
├── GatewayConnection.swift           # WebSocket client (actor)
├── GatewayProcessManager.swift       # Gateway process lifecycle
├── VoiceWake*.swift (15+ files)      # Voice wake system
├── TalkMode*.swift (6 files)          # Conversation mode
├── Canvas*.swift (8 files)            # Canvas surface
├── Channels*.swift (8 files)          # Channel management UI
├── Onboarding*.swift (8 files)        # First-time onboarding
├── *Settings.swift (12 files)         # Settings panels for each feature
├── *Store.swift (8 files)             # Data storage
└── ...
```

### State Management

The application uses Swift 5.9+ `@Observable` macro (Observation framework) to manage global state:

```swift
// apps/macos/Sources/OpenClaw/AppState.swift
@MainActor
@Observable
final class AppState {
    enum ConnectionMode: String {
        case unconfigured
        case local     // Run Gateway locally
        case remote    // Connect to remote Gateway
    }

    var isPaused: Bool { didSet { UserDefaults.standard.set(isPaused, forKey: key) } }
    var launchAtLogin: Bool { didSet { AppStateStore.updateLaunchAtLogin(enabled: self) } }
    var swabbleEnabled: Bool { didSet { VoiceWakeRuntime.shared.refresh(state: self) } }
    var swabbleTriggerWords: [String] { didSet { ... } }
    // ... 30+ observable properties
}
```

> **Sidebar — @Observable and @MainActor**
>
> `@Observable` is a macro introduced in Swift 5.9 that replaces the older `ObservableObject` protocol. It automatically generates change-tracking code at compile time for properties, and SwiftUI views only redraw when properties they actually use change—more precise than `@Published`'s "notify on any property change" approach. `@MainActor` ensures all methods of the class execute on the main thread, which is necessary for safe UI state management.

## 36.1.2 Menu Bar Control

### Entry Point

The application's entry point is a `MenuBarExtra`—a persistent icon in the macOS menu bar:

```swift
// apps/macos/Sources/OpenClaw/MenuBar.swift
@main
struct OpenClawApp: App {
    @State private var state: AppState
    private let gatewayManager = GatewayProcessManager.shared
    private let controlChannel = ControlChannel.shared

    var body: some Scene {
        MenuBarExtra {
            MenuContent(state: self.state, updater: ...)
        } label: {
            CritterStatusLabel(
                isPaused: self.state.isPaused,
                isWorking: self.state.isWorking,
                gatewayStatus: self.gatewayManager.status,
                animationsEnabled: self.state.iconAnimationsEnabled,
                ...)
        }
        .menuBarExtraStyle(.menu)
        .menuBarExtraAccess(isPresented: self.$isMenuPresented) { item in
            MenuSessionsInjector.shared.install(into: item)
        }
        
        Settings {
            SettingsRootView(state: self.state, ...)
        }
    }
}
```

The menu bar icon is an animated "critter" (small creature) whose state reflects the Gateway's running status:

| Icon State         | Meaning                  |
| ------------------ | ------------------------ |
| Normal animation   | Gateway running normally |
| Paused/Gray        | User manually paused     |
| Sleeping           | Gateway in sleep mode    |
| Working            | Agent processing task    |
| Ears up (earBoost) | Voice wake activated     |

### Connection Modes

The application supports two Gateway connection modes:

* **Local mode**: The application launches and manages a Gateway subprocess itself
* **Remote mode**: Connects to another Gateway instance on the network

Mode switching is coordinated by `ConnectionModeCoordinator`:

```swift
.onChange(of: self.state.connectionMode) { _, mode in
    Task { await ConnectionModeCoordinator.shared.apply(
        mode: mode, paused: self.state.isPaused) }
}
```

## 36.1.3 Voice Wake + Push-to-Talk

### Voice Wake System

Voice wake is one of the core features of the macOS application. It uses Apple's **Speech framework** (`SFSpeechRecognizer`) for real-time speech recognition, listening for user-defined trigger words.

```swift
// apps/macos/Sources/OpenClaw/VoiceWakeRuntime.swift
actor VoiceWakeRuntime {
    static let shared = VoiceWakeRuntime()
    
    enum ListeningState { case idle, voiceWake, pushToTalk }
    
    private var recognizer: SFSpeechRecognizer?
    private var audioEngine: AVAudioEngine?
    private var recognitionRequest: SFSpeechAudioBufferRecognitionRequest?
    // ...
    
    // Tunable parameters
    private let silenceWindow: TimeInterval = 2.0        // Silence threshold after speech
    private let triggerOnlySilenceWindow: TimeInterval = 5.0
    private let captureHardStop: TimeInterval = 120.0     // Maximum capture duration
    private let minSpeechRMS: Double = 1e-3               // Minimum speech RMS
    private let speechBoostFactor: Double = 6.0           // Multiplier above noise floor
}
```

> **Sidebar — SFSpeechRecognizer and RMS**
>
> `SFSpeechRecognizer` is Apple's speech recognition API that supports real-time streaming recognition. It converts audio buffers captured from the microphone (`AVAudioPCMBuffer`) into text. RMS (Root Mean Square) is a common metric for measuring audio signal strength—OpenClaw determines whether the user is speaking by comparing the current RMS to the noise floor (`noiseFloorRMS`).

The voice wake flow:

1. Start `AVAudioEngine` to continuously capture audio
2. Feed audio buffers into `SFSpeechAudioBufferRecognitionRequest` for real-time recognition
3. In the recognition callback, check if the text contains trigger words (e.g., "Hey OpenClaw")
4. After triggering, enter "capture mode"—continue recording until 2 seconds of silence is detected
5. Send the captured speech to the Gateway

The audio engine is **lazily created**: `AVAudioEngine` is only initialized when the voice wake feature is actually enabled, because merely creating it causes Bluetooth headsets to switch to a lower-quality headset profile.

## 36.1.4 Talk Mode Overlay

Talk Mode is a full-screen overlay conversation mode, similar to a voice assistant's "conversation interface":

```swift
// apps/macos/Sources/OpenClaw/TalkModeController.swift
@MainActor
@Observable
final class TalkModeController {
    static let shared = TalkModeController()
    
    private(set) var phase: TalkModePhase = .idle
    private(set) var isPaused: Bool = false
    
    func setEnabled(_ enabled: Bool) async {
        if enabled {
            TalkOverlayController.shared.present()   // Show full-screen overlay
        } else {
            TalkOverlayController.shared.dismiss()
        }
        await TalkModeRuntime.shared.setEnabled(enabled)
    }
    
    func updatePhase(_ phase: TalkModePhase) {
        self.phase = phase
        TalkOverlayController.shared.updatePhase(phase)
        // Sync state to Gateway
        Task { await GatewayConnection.shared.talkMode(
            enabled: AppStateStore.shared.talkEnabled,
            phase: effectivePhase) }
    }
}
```

Talk Mode phases include: idle (idle), listening (listening), thinking (thinking), speaking (speaking), and others. Each phase change is synced to the Gateway so it can coordinate behavior across other clients.

## 36.1.5 Remote Gateway Control

In remote mode, the macOS application connects to a remote Gateway via SSH tunnel or direct WebSocket:

```swift
// apps/macos/Sources/OpenClaw/GatewayConnection.swift
actor GatewayConnection {
    static let shared = GatewayConnection()
    
    enum Method: String, Sendable {
        case agent, status, health
        case channelsStatus = "channels.status"
        case configGet = "config.get"
        case configSet = "config.set"
        case chatHistory = "chat.history"
        case chatSend = "chat.send"
        case chatAbort = "chat.abort"
        case talkMode = "talk.mode"
        case voicewakeGet = "voicewake.get"
        case voicewakeSet = "voicewake.set"
        // ... 20+ RPC methods
    }
}
```

`GatewayConnection` uses Swift's `actor` concurrency model to ensure thread safety—all WebSocket operations are automatically serialized without manual locking. Remote connections support establishing SSH tunnels via `RemoteTunnelManager`.

## 36.1.6 macOS Permissions and TCC

macOS has a strict **TCC (Transparency, Consent, and Control)** permission system. OpenClaw requires multiple system permissions to work fully:

```swift
// apps/macos/Sources/OpenClaw/PermissionManager.swift
enum PermissionManager {
    static func ensure(_ caps: [Capability], interactive: Bool) async -> [Capability: Bool] {
        var results: [Capability: Bool] = [:]
        for cap in caps {
            results[cap] = await ensureCapability(cap, interactive: interactive)
        }
        return results
    }
}
```

Required permissions include:

| Permission         | Purpose                           | API                                               |
| ------------------ | --------------------------------- | ------------------------------------------------- |
| Microphone         | Voice wake/conversation mode      | `AVCaptureDevice.requestAccess(for: .audio)`      |
| Speech Recognition | Speech-to-text                    | `SFSpeechRecognizer.requestAuthorization()`       |
| Camera             | Vision capabilities               | `AVCaptureDevice.requestAccess(for: .video)`      |
| Screen Recording   | Screenshot/screen recording tools | `CGPreflightScreenCaptureAccess()`                |
| AppleScript        | Automation operations             | AppleScript permission                            |
| Accessibility      | Keyboard listening                | Accessibility API                                 |
| Notifications      | Message alerts                    | `UNUserNotificationCenter.requestAuthorization()` |
| Location           | Location query tools              | `CLLocationManager.requestAlwaysAuthorization()`  |

> **Sidebar — TCC (Transparency, Consent, and Control)**
>
> TCC is the privacy protection framework for macOS and iOS. Applications must obtain explicit user authorization before accessing sensitive resources (camera, microphone, folders, etc.). Permission states are stored in the system database `TCC.db`, and users can manage them in the "Privacy & Security" panel of System Settings. For developers, you must declare usage descriptions in Info.plist (e.g., `NSMicrophoneUsageDescription`), otherwise permission requests will fail silently.

`PermissionManager` in interactive mode guides users through authorization (showing system dialogs or navigating to Settings), while in non-interactive mode it only checks without requesting.

***

## Summary of This Section

1. **The macOS application is a menu bar resident application** built with Swift 6.2 + SwiftUI + SPM, supporting both local and remote Gateway connection modes.
2. **The menu bar icon** is an animated state indicator reflecting Gateway running status, work status, and voice wake status.
3. **Voice wake** is implemented based on Apple's Speech framework for real-time speech recognition, supporting custom trigger words and using RMS energy detection for voice activity detection.
4. **Talk Mode** provides a full-screen overlay conversation interface with state changes synced to the Gateway in real-time.
5. **GatewayConnection** encapsulates WebSocket communication using Swift's actor model, supporting 20+ RPC methods.
6. **Permission management** covers 8 system permissions, unified through `PermissionManager` for request and status checking.
