(uri: string)
| 34 | * @returns exit code (0 = success) |
| 35 | */ |
| 36 | export async function handleDeepLinkUri(uri: string): Promise<number> { |
| 37 | logForDebugging(`Handling deep link URI: ${uri}`) |
| 38 | |
| 39 | let action |
| 40 | try { |
| 41 | action = parseDeepLink(uri) |
| 42 | } catch (error) { |
| 43 | const message = error instanceof Error ? error.message : String(error) |
| 44 | // biome-ignore lint/suspicious/noConsole: intentional error output |
| 45 | console.error(`Deep link error: ${message}`) |
| 46 | return 1 |
| 47 | } |
| 48 | |
| 49 | logForDebugging(`Parsed deep link action: ${jsonStringify(action)}`) |
| 50 | |
| 51 | // Always the running executable — no PATH lookup. The OS launched us via |
| 52 | // an absolute path (bundle symlink / .desktop Exec= / registry command) |
| 53 | // baked at registration time, and we want the terminal-launched Claude to |
| 54 | // be the same binary. process.execPath is that binary. |
| 55 | const { cwd, resolvedRepo } = await resolveCwd(action) |
| 56 | // Resolve FETCH_HEAD age here, in the trampoline process, so main.tsx |
| 57 | // stays await-free — the launched instance receives it as a precomputed |
| 58 | // flag instead of statting the filesystem on its own startup path. |
| 59 | const lastFetch = resolvedRepo ? await readLastFetchTime(cwd) : undefined |
| 60 | const launched = await launchInTerminal(process.execPath, { |
| 61 | query: action.query, |
| 62 | cwd, |
| 63 | repo: resolvedRepo, |
| 64 | lastFetchMs: lastFetch?.getTime(), |
| 65 | }) |
| 66 | if (!launched) { |
| 67 | // biome-ignore lint/suspicious/noConsole: intentional error output |
| 68 | console.error( |
| 69 | 'Failed to open a terminal. Make sure a supported terminal emulator is installed.', |
| 70 | ) |
| 71 | return 1 |
| 72 | } |
| 73 | |
| 74 | return 0 |
| 75 | } |
| 76 | |
| 77 | /** |
| 78 | * Handle the case where claude was launched as the app bundle's executable |
no test coverage detected