Skip to content

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.

fix: launch Claude Desktop via its registered protocol

unknown355e02d5c94f
diff --git a/windows/src-tauri/Cargo.toml b/windows/src-tauri/Cargo.toml
index 54b1bd18..b40da89b 100644
--- a/windows/src-tauri/Cargo.toml
+++ b/windows/src-tauri/Cargo.toml
@@ -33,13 +33,16 @@ windows = { version = "0.61", features = [
"Win32_Foundation",
"Win32_Security",
"Win32_Security_Authorization",
+ "Win32_System_Com",
# "Open terminal": the relay's process tree leads to the session's window.
"Win32_System_Diagnostics_ToolHelp",
"Win32_System_Ole",
"Win32_System_Pipes",
+ "Win32_System_Registry",
"Win32_System_SystemInformation",
"Win32_System_Threading",
"Win32_UI_Input_KeyboardAndMouse",
+ "Win32_UI_Shell",
"Win32_UI_WindowsAndMessaging",
] }
diff --git a/windows/src-tauri/src/platform/windows.rs b/windows/src-tauri/src/platform/windows.rs
index 1085da69..cbe8e18b 100644
--- a/windows/src-tauri/src/platform/windows.rs
+++ b/windows/src-tauri/src/platform/windows.rs
@@ -8,10 +8,15 @@ use std::process::Command;
use tauri::{AppHandle, Manager, WebviewWindow};
-use ::windows::core::{BOOL, PWSTR};
-use ::windows::Win32::Foundation::{CloseHandle, HANDLE, HLOCAL, HWND, LPARAM, LocalFree, POINT};
+use ::windows::core::{w, BOOL, PWSTR};
+use ::windows::Win32::Foundation::{
+ CloseHandle, HANDLE, HLOCAL, HWND, LPARAM, LocalFree, POINT, RPC_E_CHANGED_MODE,
+};
use ::windows::Win32::Security::Authorization::ConvertSidToStringSidW;
use ::windows::Win32::Security::{GetTokenInformation, TokenUser, TOKEN_QUERY, TOKEN_USER};
+use ::windows::Win32::System::Com::{
+ CoInitializeEx, CoUninitialize, COINIT_APARTMENTTHREADED, COINIT_DISABLE_OLE1DDE,
+};
use ::windows::Win32::System::Diagnostics::ToolHelp::{
CreateToolhelp32Snapshot, Process32FirstW, Process32NextW, PROCESSENTRY32W, TH32CS_SNAPPROCESS,
};
@@ -23,10 +28,13 @@ use ::windows::Win32::UI::Input::KeyboardAndMouse::{
GetAsyncKeyState, GetKeyboardLayoutList, MapVirtualKeyExW, ToUnicodeEx, HKL, MAPVK_VK_TO_VSC,
VK_CONTROL, VK_LBUTTON, VK_MENU, VK_SHIFT,
};
+use ::windows::Win32::UI::Shell::{
+ ShellExecuteExW, SHELLEXECUTEINFOW, SEE_MASK_FLAG_NO_UI, SEE_MASK_NOASYNC,
+};
use ::windows::Win32::UI::WindowsAndMessaging::{
EnumChildWindows, EnumWindows, GetClassNameW, GetCursorPos, GetWindow, GetWindowLongPtrW,
GetWindowTextW, GetWindowThreadProcessId, IsIconic, IsWindowVisible, SetForegroundWindow,
- SetWindowLongPtrW, ShowWindow, GWL_EXSTYLE, GW_OWNER, SW_RESTORE, WS_EX_NOACTIVATE,
+ SetWindowLongPtrW, ShowWindow, GWL_EXSTYLE, GW_OWNER, SW_RESTORE, SW_SHOWNORMAL, WS_EX_NOACTIVATE,
WS_EX_TOOLWINDOW,
};
@@ -471,14 +479,85 @@ fn focus_app(exe: &str) -> bool {
/// The Claude desktop app: brought forward when it runs (Claude Code's own
/// `claude.exe` has no window of its own, so it is never the one picked),
-/// started from where its installer puts it otherwise.
+/// started from the Squirrel path or its registered MSIX protocol otherwise.
pub fn open_claude_desktop() -> bool {
- if focus_app("claude.exe") {
- return true;
+ open_claude_with(
+ || focus_app("claude.exe"),
+ || {
+ std::env::var_os("LOCALAPPDATA").is_some_and(|base| {
+ let exe = PathBuf::from(base).join("AnthropicClaude").join("claude.exe");
+ exe.is_file() && Command::new(exe).spawn().is_ok()
+ })
+ },
+ activate_claude_protocol,
+ )
+}
+
+fn open_claude_with(
+ focus: impl FnOnce() -> bool,
+ squirrel: impl FnOnce() -> bool,
+ protocol: impl FnOnce() -> bool,
+) -> bool {
+ focus() || squirrel() || protocol()
+}
+
+/// The MSIX manifest registers `claude`; let Windows resolve its current install.
+fn activate_claude_protocol() -> bool {
+ unsafe {
+ let initialized = CoInitializeEx(None, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);
+ // A Tauri thread may already use MTA. Keep that apartment: the Shell can
+ // delegate activation, and we must not uninitialize someone else's COM.
+ if initialized.is_err() && initialized != RPC_E_CHANGED_MODE {
+ return false;
+ }
+ let mut info = SHELLEXECUTEINFOW {
+ cbSize: std::mem::size_of::<SHELLEXECUTEINFOW>() as u32,
+ fMask: SEE_MASK_FLAG_NO_UI | SEE_MASK_NOASYNC,
+ lpVerb: w!("open"),
+ lpFile: w!("claude://"),
+ nShow: SW_SHOWNORMAL.0,
+ ..Default::default()
+ };
+ let opened = ShellExecuteExW(&mut info).is_ok();
+ if initialized.is_ok() {
+ CoUninitialize();
+ }
+ opened
+ }
+}
+
+#[cfg(test)]
+mod claude_launch_tests {
+ use super::open_claude_with;
+ use std::cell::RefCell;
+
+ #[test]
+ fn tries_launchers_in_order_and_stops_after_success() {
+ for (focus, squirrel, protocol, expected, calls) in [
+ (true, true, true, true, vec!["focus"]),
+ (false, true, true, true, vec!["focus", "squirrel"]),
+ (false, false, true, true, vec!["focus", "squirrel", "protocol"]),
+ (false, false, false, false, vec!["focus", "squirrel", "protocol"]),
+ ] {
+ let seen = RefCell::new(Vec::new());
+ let result = open_claude_with(
+ || {
+ seen.borrow_mut().push("focus");
+ focus
+ },
+ || {
+ seen.borrow_mut().push("squirrel");
+ squirrel
+ },
+ || {
+ seen.borrow_mut().push("protocol");
+ protocol
+ },
+ );
+ assert_eq!(result, expected);
+ assert_eq!(seen.into_inner(), calls);
+ }
}
- let Some(base) = std::env::var_os("LOCALAPPDATA") else { return false };
- let exe = PathBuf::from(base).join("AnthropicClaude").join("claude.exe");
- exe.is_file() && Command::new(exe).spawn().is_ok()
}
// ── Global shortcuts ──────────────────────────────────────────────────────────