The best way to control Claude Code, Codex and more from any computer or phone
fix(desktop): close focused DevTools with Cmd+W (#33518)
Add a native Cmd/Ctrl+W shortcut that closes focused DevTools while retaining renderer tab and terminal shortcuts and repeated-key protection. Validation: 31 focused tests, check:changed, and CI passed. Electron runtime checks verified the close handler; automated native keypress verification remains unconfirmed. Model: GPT 6.1 Sol. Harness: Codex.
Yash Singh committed
Nov 9, 2026 at 13:50 UTC
206a8e69371d3d79cbeadeafb944815c294ae6e5
4 files changed
+61
-7
apps/desktop/src/window/DesktopApplicationMenu.test.ts
+32
-5
@@ -4,7 +4,12 @@ import * as Deferred from "effect/Deferred";
4
import * as Effect from "effect/Effect";
5
import * as Layer from "effect/Layer";
6
7
-import type * as Electron from "electron";
7
+import * as Electron from "electron";
8
+import { vi } from "vite-plus/test";
9
+
10
+vi.mock("electron", () => ({
11
+ webContents: { getAllWebContents: vi.fn(() => []) },
12
+}));
13
14
import * as ElectronApp from "../electron/ElectronApp.ts";
15
import * as ElectronDialog from "../electron/ElectronDialog.ts";
@@ -227,10 +232,32 @@ describe("DesktopApplicationMenu", () => {
232
items.find((item) => item.role === "windowMenu" && item.submenu === undefined),
233
platform,
234
);
230
- assert.isUndefined(
231
- items.find((item) => item.accelerator?.toLowerCase().endsWith("+w")),
232
- platform,
233
- );
235
+ const closeTools = items.find((item) => item.accelerator === "CmdOrCtrl+W");
236
+ assert.equal(closeTools?.label, "Close Developer Tools", platform);
237
+ assert.isFunction(closeTools?.click);
238
+ const appContents = {
239
+ isDestroyed: () => false,
240
+ isDevToolsFocused: () => false,
241
+ closeDevTools: vi.fn(),
242
+ };
243
+ const inspectedContents = {
244
+ ...appContents,
245
+ isDevToolsFocused: () => true,
246
+ closeDevTools: vi.fn(),
247
+ };
248
+ using allContents = vi
249
+ .spyOn(Electron.webContents, "getAllWebContents")
250
+ .mockReturnValue([
251
+ appContents as unknown as Electron.WebContents,
252
+ inspectedContents as unknown as Electron.WebContents,
253
+ ]);
254
+ closeTools?.click?.({} as Electron.MenuItem, undefined, {} as KeyboardEvent);
255
+ assert.equal(inspectedContents.closeDevTools.mock.calls.length, 1);
256
+ assert.equal(appContents.closeDevTools.mock.calls.length, 0);
257
+
258
+ allContents.mockReturnValue([appContents as unknown as Electron.WebContents]);
259
+ closeTools?.click?.({} as Electron.MenuItem, undefined, {} as KeyboardEvent);
260
+ assert.equal(appContents.closeDevTools.mock.calls.length, 0);
261
}
262
}),
263
);
apps/desktop/src/window/DesktopApplicationMenu.ts
+12
-1
@@ -4,7 +4,7 @@ import * as Layer from "effect/Layer";
4
import * as Option from "effect/Option";
5
import * as Schema from "effect/Schema";
6
7
-import type * as Electron from "electron";
7
+import * as Electron from "electron";
8
9
import { makeComponentLogger } from "../app/DesktopObservability.ts";
10
import * as ElectronDialog from "../electron/ElectronDialog.ts";
@@ -200,6 +200,17 @@ export const make = Effect.gen(function* () {
200
},
201
{ type: "separator" as const },
202
]),
203
+ {
204
+ label: "Close Developer Tools",
205
+ accelerator: "CmdOrCtrl+W",
206
+ visible: false,
207
+ click: () => {
208
+ Electron.webContents
209
+ .getAllWebContents()
210
+ .find((contents) => !contents.isDestroyed() && contents.isDevToolsFocused())
211
+ ?.closeDevTools();
212
+ },
213
+ },
214
// Cmd/Ctrl+W belongs to the renderer's tab close; it must never close the window.
215
environment.platform === "darwin"
216
? { label: "Close Window", click: (_item, window) => window?.close() }
apps/desktop/src/window/DesktopWindow.test.ts
+10
-1
@@ -94,6 +94,7 @@ function makeFakeBrowserWindow() {
94
replaceMisspelling: vi.fn(),
95
send: vi.fn(),
96
setBackgroundThrottling: vi.fn(),
97
+ setIgnoreMenuShortcuts: vi.fn(),
98
setWindowOpenHandler: vi.fn(),
99
toggleDevTools: vi.fn(),
100
};
@@ -143,6 +144,7 @@ function makeFakeBrowserWindow() {
144
reloadIgnoringCache: webContents.reloadIgnoringCache,
145
toggleDevTools: webContents.toggleDevTools,
146
navigationHistory: webContents.navigationHistory,
147
+ setIgnoreMenuShortcuts: webContents.setIgnoreMenuShortcuts,
148
send: webContents.send,
149
setZoomLevel: webContents.setZoomLevel,
150
setWindowButtonPosition: window.setWindowButtonPosition,
@@ -646,7 +648,7 @@ describe("DesktopWindow", () => {
648
}),
649
);
650
649
- it.effect("blocks only repeated Cmd+W input before it reaches the native window menu", () =>
651
+ it.effect("leaves Cmd+W to the renderer and blocks repeated presses", () =>
652
Effect.gen(function* () {
653
const fakeWindow = makeFakeBrowserWindow();
654
const createCount = yield* Ref.make(0);
@@ -687,6 +689,13 @@ describe("DesktopWindow", () => {
689
prevented = false;
690
beforeInput(event, { ...input, meta: false });
691
assert.isFalse(prevented);
692
+
693
+ assert.deepEqual(
694
+ fakeWindow.setIgnoreMenuShortcuts.mock.calls.map(([ignore]) => ignore),
695
+ [true, true, false],
696
+ );
697
+ beforeInput(event, { ...input, key: "r", isAutoRepeat: false });
698
+ assert.isFalse(fakeWindow.setIgnoreMenuShortcuts.mock.lastCall?.[0]);
699
}).pipe(Effect.provide(layer));
700
}),
701
);
apps/desktop/src/window/DesktopWindow.ts
+7
@@ -677,6 +677,13 @@ export const make = Effect.gen(function* () {
677
});
678
window.webContents.on("before-input-event", (event, input) => {
679
quitShortcutHandler(event, input);
680
+ // Cmd/Ctrl+W reaches the renderer; DevTools uses the native menu shortcut.
681
+ window.webContents.setIgnoreMenuShortcuts(
682
+ (environment.platform === "darwin" ? input.meta : input.control) &&
683
+ !input.alt &&
684
+ !input.shift &&
685
+ input.key.toLowerCase() === "w",
686
+ );
687
// A held Cmd/Ctrl+W closes one tab or terminal, not each one behind it.
688
if (input.type !== "keyDown" || !input.isAutoRepeat) return;
689
const modifier = environment.platform === "darwin" ? input.meta : input.control;