@devries-cameron20 / t3code-1 / commits / eef57db955
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Add open-in-editor feature with Cmd+O shortcut (#2)

* Add open-in-editor feature with Cmd+O shortcut Add dropdown in header to open workspace in Cursor or system file manager (Finder/Explorer/Files). Include Cmd+O/Ctrl+O global keyboard shortcut to open in last-used editor, persisted to localStorage. Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com> * Move editor definitions to contracts for strict IPC typing EDITORS config and EditorId type now live in @acme/contracts so the shell.openInEditor IPC channel is strictly typed end-to-end. The main process uses the contract's command field (null = file manager via shell.openPath). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * Fix biome formatting issues Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix: add error handling and address review feedback - Validate cwd is non-empty in shell:open-in-editor IPC handler - Check shell.openPath() return value and throw on error - Attach spawn error listener to prevent crashes from missing CLI - Validate localStorage lastEditor against known EDITORS list - Only call preventDefault() for Cmd+O when action will run Co-authored-by: Julius Marminge <juliusmarminge@users.noreply.github.com> --------- Co-authored-by: Claude Haiku 4.5 <noreply@anthropic.com> Co-authored-by: Cursor Agent <cursoragent@cursor.com> Co-authored-by: Julius Marminge <juliusmarminge@users.noreply.github.com>

Julius Marminge committed Feb 9, 2026 at 01:06 UTC eef57db955614e346091769bc6d4e80e0068e9b6
4 files changed +135 -1
apps/desktop/src/main.ts
+25 -1
@@ -3,9 +3,10 @@ fixPath();
3
4 import { spawn } from "node:child_process";
5 import path from "node:path";
6 -import { BrowserWindow, app, dialog, ipcMain, session } from "electron";
6 +import { BrowserWindow, app, dialog, ipcMain, session, shell } from "electron";
7
8 import {
9 + EDITORS,
10 IPC_CHANNELS,
11 type TerminalCommandInput,
12 type TerminalCommandResult,
@@ -126,6 +127,29 @@ function registerIpcHandlers(): void {
127 }),
128 );
129
130 + // Shell handlers
131 + ipcMain.handle(
132 + IPC_CHANNELS.shellOpenInEditor,
133 + async (_event, cwd: string, editor: string) => {
134 + if (!cwd) throw new Error("cwd is required");
135 + const editorDef = EDITORS.find((e) => e.id === editor);
136 + if (!editorDef) throw new Error(`Unknown editor: ${editor}`);
137 + if (!editorDef.command) {
138 + const error = await shell.openPath(cwd);
139 + if (error) throw new Error(error);
140 + return;
141 + }
142 + const child = spawn(editorDef.command, [cwd], {
143 + detached: true,
144 + stdio: "ignore",
145 + });
146 + child.on("error", () => {
147 + /* ignore spawn failures for detached editors */
148 + });
149 + child.unref();
150 + },
151 + );
152 +
153 // Agent handlers
154 ipcMain.handle(
155 IPC_CHANNELS.agentSpawn,
apps/desktop/src/preload.ts
+4
@@ -54,6 +54,10 @@ const nativeApi: NativeApi = {
54 ipcRenderer.removeListener(IPC_CHANNELS.providerEvent, listener);
55 },
56 },
57 + shell: {
58 + openInEditor: (cwd: string, editor: string) =>
59 + ipcRenderer.invoke(IPC_CHANNELS.shellOpenInEditor, cwd, editor),
60 + },
61 };
62
63 contextBridge.exposeInMainWorld("nativeApi", nativeApi);
apps/renderer/src/components/ChatView.tsx
+95
@@ -9,6 +9,7 @@ import {
9 useState,
10 } from "react";
11
12 +import { EDITORS, type EditorId } from "@acme/contracts";
13 import {
14 DEFAULT_MODEL,
15 DEFAULT_REASONING,
@@ -33,6 +34,18 @@ function formatMessageMeta(createdAt: string, duration: string | null): string {
34 return `${formatTimestamp(createdAt)} • ${duration}`;
35 }
36
37 +const FILE_MANAGER_LABEL = navigator.platform.includes("Mac")
38 + ? "Finder"
39 + : navigator.platform.includes("Win")
40 + ? "Explorer"
41 + : "Files";
42 +
43 +function editorLabel(editor: (typeof EDITORS)[number]): string {
44 + return editor.command ? editor.label : FILE_MANAGER_LABEL;
45 +}
46 +
47 +const LAST_EDITOR_KEY = "codething:last-editor";
48 +
49 function workToneClass(tone: "thinking" | "tool" | "info" | "error"): string {
50 if (tone === "error") return "text-rose-300/50";
51 if (tone === "tool") return "text-[#8a8a8a]";
@@ -111,6 +124,13 @@ export default function ChatView() {
124 const [isSending, setIsSending] = useState(false);
125 const [isConnecting, setIsConnecting] = useState(false);
126 const [isModelMenuOpen, setIsModelMenuOpen] = useState(false);
127 + const [isEditorMenuOpen, setIsEditorMenuOpen] = useState(false);
128 + const [lastEditor, setLastEditor] = useState<EditorId>(() => {
129 + const stored = localStorage.getItem(LAST_EDITOR_KEY);
130 + return EDITORS.some((e) => e.id === stored)
131 + ? (stored as EditorId)
132 + : EDITORS[0].id;
133 + });
134 const [selectedEffort, setSelectedEffort] =
135 useState<string>(DEFAULT_REASONING);
136 const [isSwitchingRuntimeMode, setIsSwitchingRuntimeMode] = useState(false);
@@ -121,6 +141,7 @@ export default function ChatView() {
141 const messagesEndRef = useRef<HTMLDivElement>(null);
142 const textareaRef = useRef<HTMLTextAreaElement>(null);
143 const modelMenuRef = useRef<HTMLDivElement>(null);
144 + const editorMenuRef = useRef<HTMLDivElement>(null);
145
146 const activeThread = state.threads.find((t) => t.id === state.activeThreadId);
147 const activeProject = state.projects.find(
@@ -291,6 +312,47 @@ export default function ChatView() {
312 };
313 }, [isModelMenuOpen]);
314
315 + useEffect(() => {
316 + if (!isEditorMenuOpen) return;
317 +
318 + const handleClickOutside = (event: MouseEvent) => {
319 + if (!editorMenuRef.current) return;
320 + if (
321 + event.target instanceof Node &&
322 + !editorMenuRef.current.contains(event.target)
323 + ) {
324 + setIsEditorMenuOpen(false);
325 + }
326 + };
327 +
328 + window.addEventListener("mousedown", handleClickOutside);
329 + return () => {
330 + window.removeEventListener("mousedown", handleClickOutside);
331 + };
332 + }, [isEditorMenuOpen]);
333 +
334 + // Cmd+O / Ctrl+O to open in last-used editor
335 + useEffect(() => {
336 + const handler = (e: globalThis.KeyboardEvent) => {
337 + if (e.key === "o" && (e.metaKey || e.ctrlKey) && !e.shiftKey) {
338 + if (api && activeProject) {
339 + e.preventDefault();
340 + void api.shell.openInEditor(activeProject.cwd, lastEditor);
341 + }
342 + }
343 + };
344 + window.addEventListener("keydown", handler);
345 + return () => window.removeEventListener("keydown", handler);
346 + }, [api, activeProject, lastEditor]);
347 +
348 + const openInEditor = (editorId: EditorId) => {
349 + if (!api || !activeProject) return;
350 + void api.shell.openInEditor(activeProject.cwd, editorId);
351 + setLastEditor(editorId);
352 + localStorage.setItem(LAST_EDITOR_KEY, editorId);
353 + setIsEditorMenuOpen(false);
354 + };
355 +
356 const ensureSession = async (): Promise<string | null> => {
357 if (!api || !activeThread || !activeProject) return null;
358 if (activeThread.session && activeThread.session.status !== "closed") {
@@ -458,6 +520,39 @@ export default function ChatView() {
520 </h2>
521 </div>
522 <div className="flex items-center gap-3">
523 + {/* Open in editor */}
524 + {activeProject && (
525 + <div className="relative" ref={editorMenuRef}>
526 + <button
527 + type="button"
528 + className="rounded-md px-2 py-1 text-[10px] text-[#a0a0a0]/40 transition-colors duration-150 hover:text-[#a0a0a0]/60"
529 + onClick={() => setIsEditorMenuOpen((v) => !v)}
530 + >
531 + Open in&hellip;
532 + </button>
533 + {isEditorMenuOpen && (
534 + <div className="absolute right-0 top-full z-50 mt-1 min-w-[120px] rounded-md border border-white/[0.08] bg-[#1b1b1d] py-1 shadow-xl">
535 + {EDITORS.map((editor) => (
536 + <button
537 + key={editor.id}
538 + type="button"
539 + className="flex w-full items-center gap-2 px-3 py-1.5 text-left text-[11px] text-[#e0e0e0] hover:bg-white/[0.06]"
540 + onClick={() => openInEditor(editor.id)}
541 + >
542 + {editorLabel(editor)}
543 + {editor.id === lastEditor && (
544 + <kbd className="ml-auto text-[9px] text-[#a0a0a0]/40">
545 + {navigator.platform.includes("Mac")
546 + ? "\u2318O"
547 + : "Ctrl+O"}
548 + </kbd>
549 + )}
550 + </button>
551 + ))}
552 + </div>
553 + )}
554 + </div>
555 + )}
556 {/* Diff toggle */}
557 <button
558 type="button"
packages/contracts/src/ipc.ts
+11
@@ -12,6 +12,13 @@ import type {
12 import type { TerminalCommandInput, TerminalCommandResult } from "./terminal";
13 import type { NewTodoInput, Todo } from "./todo";
14
15 +export const EDITORS = [
16 + { id: "cursor", label: "Cursor", command: "cursor" },
17 + { id: "file-manager", label: "File Manager", command: null },
18 +] as const;
19 +
20 +export type EditorId = (typeof EDITORS)[number]["id"];
21 +
22 export const IPC_CHANNELS = {
23 todosList: "todos:list",
24 todosAdd: "todos:add",
@@ -31,6 +38,7 @@ export const IPC_CHANNELS = {
38 providerSessionList: "provider:session:list",
39 providerRequestRespond: "provider:request:respond",
40 providerEvent: "provider:event",
41 + shellOpenInEditor: "shell:open-in-editor",
42 } as const;
43
44 export interface NativeApi {
@@ -66,4 +74,7 @@ export interface NativeApi {
74 listSessions: () => Promise<ProviderSession[]>;
75 onEvent: (callback: (event: ProviderEvent) => void) => () => void;
76 };
77 + shell: {
78 + openInEditor: (cwd: string, editor: EditorId) => Promise<void>;
79 + };
80 }