Skip to content

feat(terminal): move a terminal tab to its own window - #28963

Closed
kimyk0120 wants to merge 25 commits into
stablyai:mainfrom
kimyk0120:feat/detach-terminal-tab-window
Closed

kimyk0120 wants to merge 25 commits into
stablyai:mainfrom
kimyk0120:feat/detach-terminal-tab-window

Conversation

@kimyk0120

@kimyk0120 kimyk0120 commented Oct 15, 2026 •

Copy link
Copy Markdown

ELI5

Right-click a terminal tab and choose "Move to New Window": the same live terminal opens in its own window you can put on another monitor. Close that window (or click "Move Back to Main Window") and the terminal is back in the main window, still running.

What Changed

Before: a terminal could only be shown inside the main window (or the in-window floating workspace), so a large editor or preview covered it.

After:

  • Terminal tab context menu → Move to New Window, plus a tab.moveToNewWindow keybinding action that is unassigned by default.
  • The terminal opens in a companion OS window attached to the same PTY (no restart, scrollback kept), with a Move Back to Main Window button.
  • In the main window the tab keeps its place with a small detached indicator; selecting it shows "This terminal is open in another window" with Show Window and Move Back to Main Window.
  • Closing the companion window re-docks the tab. So does the tab binding another PTY (a reattach or agent restart) or splitting, because the companion streams only the PTY it opened with. Nothing in this flow ever kills the PTY.
  • Not persisted: after restart every tab is docked as usual. Closing, reloading or crashing the main window closes the companions; a crashed companion closes itself so the tab re-docks; removing a worktree closes its companions.
  • v1 scope: single-pane terminal tabs on local/WSL. Split tabs, SSH and remote-runtime terminals show the item disabled ("Local only" for remote), and split actions are disabled while a tab is detached.

Mechanism: the main window stays the only owner of app state, session persistence and PTY lifecycle; the companion is a view.

  • Main: detached-terminal-window.ts creates one sandboxed BrowserWindow per tab on the existing popout.html entry (modelled on dashboard-popout-window.ts; own partition, no webview, privileged navigation policy, permissions denied). Its closed handler is the single place that forgets the window and notifies the main renderer. detached-terminal.ts registers the detachedTerminal:* handlers once with the core handlers (trusted UI for open/close and the pane's input facts, the owning companion for return and for reading those facts).
  • Transport: the companion uses the existing terminalPreview IPC and AgentTerminalPreview; terminal-preview.ts now admits a companion renderer only for the PTY it was opened with (dashboard pop-out and the trusted UI are unchanged). The companion holds the preview grid claim while the hidden main pane does not fit, so the two never fight over PTY size. The main renderer sends the pane's host-input facts (ConPTY, agent paste and key rules, resolved as for a dashboard card) whenever they change, and the companion gets the same text-only clipboard access as the dashboard pop-out.
  • Renderer: detach state is in-memory (terminal-detachment.ts, not part of the workspace session); TerminalPaneOverlayLayer keeps the pane mounted but hidden and renders the placeholder.

Why

Keeping an agent visible on a second screen is a common request (#22167, #7811). #16203 explores full multi-window workbenches with tab transfer, which needs session merging, control-window election and PTY ownership hand-off. This PR deliberately takes the smallest useful step instead: a view-only companion window for one terminal, built from the existing pop-out window and preview transport, so none of those cross-window ownership problems can arise. It doesn't preclude a fuller multi-window design later.

Linked Issue

Fixes #28955

Visual Proof

Before (tab menu) After (tab menu)
before-tab-menu after-tab-menu
After (companion window) After (main window placeholder)
after-companion-window after-main-placeholder

(Captured headlessly with the repo's Playwright electron-headless setup against the seeded e2e repo.)

Testing

  • New unit tests: companion window creation/dedupe/focus, closed notifies exactly once even when close() is asynchronous, render-process-gone closes the companion, main-window close/reload/crash closes companions, handlers registered once, terminalPreview per-PTY admission for companions (allowed/denied on every channel), detach/re-dock store transitions and non-persistence, split / SSH / remote-runtime gating, worktree removal closes companions, tab context menu item and keybinding (unassigned by default), companion view attach/input/unsubscribe.

  • pnpm test:node over src/main/window, terminal-preview, core handlers, dashboard pop-out, tab-bar, terminal-pane, src/renderer/src/store, src/renderer/src/hooks, dashboard-popout, src/shared — 2,453 files / 25,770 tests, 0 failures (this includes the existing react185 update-depth guards and the useIpcEvents suites).

  • pnpm typecheck and every pnpm lint step pass (the Bun-launched verify:localization-catalogs step was run with Node because Bun isn't installed here).

  • Headless Electron run (screenshots above): detach, companion rendering and the main-window placeholder.

  • Platforms: macOS only. The window uses the same construction as the existing dashboard pop-out; I did not run Windows/Linux builds.

  • I manually tested these changes locally

  • Automated tests added/updated, or explained why not below

AI Disclosure

Implemented with AI coding agents (Claude Code with Claude Opus 5.5 for design, review and verification; Cursor Agent and Antigravity for implementation, review passes and screenshots). I reviewed the diff and the test results.

Review

AI code review summary:

  • Security: companion renderers can reach only their own PTY through terminalPreview; open/close and input facts are accepted only from the trusted UI, and return only from the owning companion; input facts are validated like the dashboard's; companion windows are sandboxed with no webview and denied permissions, and get text-only clipboard access like the dashboard pop-out. They share the app preload with the main window and the dashboard pop-out.
  • Lifecycle: PTYs are never killed by companion or detach code; companions cannot outlive the main window, its reload/crash, or their worktree; a crashed companion re-docks.
  • Cross-platform: same BrowserWindow construction as the dashboard pop-out; no platform-specific code.
  • SSH / remote: disabled with "Local only" because the preview transport has no SSH/remote snapshot.
  • Performance: no new work while nothing is detached; the hidden main pane stops fitting while detached.
  • UI: shadcn Button, existing tokens and icons.

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

Ensure no issues in: Security, Cross-platoform support (Linux, Windows, Mac), Remote SSH, Mobile, general backwards compatibility, performance

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

🤖 Generated with Claude Code

https://claude.ai/code/session_01QCGg3xzzG6zeVE2aanNY4S

Terminal tabs get "Move to New Window" (plus an unassigned keybinding). The
same live PTY opens in a thin companion window built on the existing pop-out
window and terminalPreview transport; the main window keeps the tab with a
detached indicator and a placeholder. Closing the companion, or "Move Back to
Main Window", re-docks the tab and never kills the PTY.

The main window stays the only owner of state, persistence and PTY lifecycle:
detach state is in-memory, companions only reach their own PTY, and they close
with the main window, its reload or crash, their own crash, or their worktree.
v1 covers single-pane local/WSL terminals; split, SSH and remote are disabled.

Fixes stablyai#28955

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01QCGg3xzzG6zeVE2aanNY4S
@coderabbitai

coderabbitai Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • Resume reviews
  • Trigger review

No actionable comments were generated in the recent review.

Walkthrough

The change adds detached terminal windows for supported terminal tabs. The main process manages companion windows and exposes IPC for window controls and terminal input. The renderer tracks detached tabs, synchronizes terminal input, and shows controls to open, focus, or return a terminal. Detached renderers receive PTY-scoped preview access, and detached windows close during tab, worktree, main-window, and renderer lifecycle cleanup.

Merge Risk: Minimal · up to 551b8

No actionable issue remains from the reviewed behavior; the change is mergeable after normal checks.

Pre-merge checks: Passed 5

Check name Status Explanation
Title check Passed The title clearly describes the main change: moving a terminal tab to its own window.
Description check Passed The description is mostly complete. It explains the change, links an issue, provides visual proof, and reports testing. It lacks a Risk section with a risk level and rollback plan. It also omits the t…
Linked Issues check Passed [#28955] The tab menu and unassigned keybinding open a companion on the same PTY. The indicator, placeholder and return controls support showing and re-docking the terminal. Detachment is not persiste…
Out of Scope Changes check Passed [#28955] The window, IPC, preview, renderer state, UI and lifecycle changes support the detached terminal feature. The tests, clipboard text access, input handling and labels support the companion vie…
Docstring Coverage Passed Docstring coverage is inconclusive: files from earlier reviews still need to be rechecked within the check's analysis limits. Not blocking.
Full details: Description check

Explanation

The description is mostly complete. It explains the change, links an issue, provides visual proof, and reports testing. It lacks a Risk section with a risk level and rollback plan. It also omits the test anti-pattern checkbox and leaves build and CI coverage unconfirmed.

Full details: Linked Issues check

Explanation

[#28955] The tab menu and unassigned keybinding open a companion on the same PTY. The indicator, placeholder and return controls support showing and re-docking the terminal. Detachment is not persisted, and main-window closure closes companions. Eligibility checks limit detachment to single-pane local or WSL terminals and show the remote hint. The main window retains ownership, and terminalPreview restricts each companion to its PTY. Automated tests cover the actions, eligibility, lifecycle and transport authorization. The reported test results were not independently rerun.

Full details: Out of Scope Changes check

Explanation

[#28955] The window, IPC, preview, renderer state, UI and lifecycle changes support the detached terminal feature. The tests, clipboard text access, input handling and labels support the companion view. The small tab-name refactor is incidental. No unrelated product change is established by the available evidence.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Tip

🎯 Customize your risk assessments

Guide how CodeRabbit assesses merge risk and security architecture risk. Highlight sensitive changes and explain your security boundaries using Merge Risk Instructions and Security Risk Instructions in your review settings. Security architecture risk assessments require the Advanced plan or above.

✅ Automatic approvals, with your rules

Let CodeRabbit approve pull requests once required threads are resolved, pre-merge checks pass, and your risk limits are met. Enable Automatic approvals in review settings, with overrides for teams or file paths.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 41520ca7-0644-4f5c-b072-081cb695928c
Commits

Reviewing files that changed from the base of the PR and between ca2a53f and 551b830.

Files selected for processing: 7

  • src/main/window/createMainWindow.test.ts
  • src/preload/api-types.ts
  • src/preload/index.ts
  • src/renderer/src/components/settings/shortcuts/keybinding-title-copy.ts
  • src/renderer/src/components/tab-bar/SortableTabContextMenu.detached-window.test.tsx
  • src/renderer/src/i18n/locales/en.json
  • src/shared/keybindings/types.ts
Files skipped from review as they are similar to previous changes: 2

  • src/renderer/src/components/settings/shortcuts/keybinding-title-copy.ts
  • src/renderer/src/i18n/locales/en.json

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: f426b8ab-2533-4d6a-8682-c7f2238ce980
📥 Commits

Reviewing files that changed from the base of the PR and between 6448b2f and 3ed6d07.

📒 Files selected for processing: 44
  • src/main/ipc/detached-terminal.ts
  • src/main/ipc/register-core-handlers/register-core-handlers.test.ts
  • src/main/ipc/register-core-handlers/register-core-handlers.ts
  • src/main/ipc/terminal-preview.test.ts
  • src/main/ipc/terminal-preview.ts
  • src/main/window/createMainWindow.test.ts
  • src/main/window/createMainWindow.ts
  • src/main/window/detached-terminal-window.test.ts
  • src/main/window/detached-terminal-window.ts
  • src/main/window/main-window-focus-lifecycle.ts
  • src/preload/api-types.ts
  • src/preload/api/detached-terminal-api.ts
  • src/preload/api/detached-terminal-bridge.ts
  • src/preload/index.ts
  • src/renderer/src/components/detached-terminal/DetachedTerminalWindow.test.tsx
  • src/renderer/src/components/detached-terminal/DetachedTerminalWindow.tsx
  • src/renderer/src/components/tab-bar/DetachedTerminalTabIndicator.tsx
  • src/renderer/src/components/tab-bar/SortableTab.tsx
  • src/renderer/src/components/tab-bar/SortableTabContextMenu.test.tsx
  • src/renderer/src/components/tab-bar/SortableTabContextMenu.tsx
  • src/renderer/src/components/tab-bar/TerminalSortableTab.tsx
  • src/renderer/src/components/terminal-pane/DetachedTerminalPlaceholder.tsx
  • src/renderer/src/components/terminal-pane/TerminalPaneOverlayLayer.tsx
  • src/renderer/src/components/terminal-workspace-keydown.test.ts
  • src/renderer/src/components/terminal-workspace-keydown.ts
  • src/renderer/src/hooks/ipc-events/app-lifetime-ipc-bridge.ts
  • src/renderer/src/hooks/ipc-events/detached-terminal-ipc-bridge.ts
  • src/renderer/src/hooks/useIpcEvents-lifecycle.test.ts
  • src/renderer/src/i18n/locales/en.json
  • src/renderer/src/popout.tsx
  • src/renderer/src/store/slices/terminals.ts
  • src/renderer/src/store/slices/worktrees-removal-state-cleanup.test.ts
  • src/renderer/src/store/slices/worktrees-slice-test-harness.ts
  • src/renderer/src/store/slices/worktrees/teardown/remove-worktree-map-identity.test.ts
  • src/renderer/src/store/slices/worktrees/teardown/remove-worktree-store-cleanup.ts
  • src/renderer/src/store/slices/worktrees/teardown/removed-worktree-renderer-teardown.ts
  • src/renderer/src/store/slices/worktrees/teardown/worktree-purge-state.ts
  • src/renderer/src/store/terminals/terminal-actions.ts
  • src/renderer/src/store/terminals/terminal-detachment.test.ts
  • src/renderer/src/store/terminals/terminal-detachment.ts
  • src/renderer/src/store/terminals/terminal-state.ts
  • src/renderer/src/store/terminals/terminal-tab-close.ts
  • src/shared/keybindings/definitions-core-2.ts
  • src/shared/keybindings/types.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review.

Comment thread src/main/ipc/detached-terminal.ts Resolved
resetShortcutRecorderFocus()
})
mainWindow.webContents.on('did-finish-load', () => {
closeAllDetachedTerminalWindows()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win

🔎 Supported by static analysis

🏁 Script executed:

set -u
printf '%s\n' '--- lifecycle references ---'
rg -n -F -- 'did-finish-load' src package.json pnpm-lock.yaml 2>/dev/null || true
rg -n -F -- 'registerRendererDocumentNavigation' src || true
printf '%s\n' '--- target file ---'
nl -ba src/main/window/main-window-focus-lifecycle.ts | sed -n '220,305p'
printf '%s\n' '--- relevant definitions/callers ---'
rg -n -F -- 'closeAllDetachedTerminalWindows' src || true
rg -n -F -- 'registerRendererDocumentNavigation' src || true
printf '%s\n' '--- electron version declarations ---'
rg -n -F -e '"electron"' -e 'electron@' package.json pnpm-lock.yaml 2>/dev/null | head -40 || true

Repository: stablyai/orca

Length of output: 18963


🏁 Script executed:

set -u
printf '%s\n' '--- navigation registration ---'
nl -ba src/main/window/renderer-document-navigation.ts
printf '%s\n' '--- navigation tests ---'
nl -ba src/main/window/renderer-document-navigation.test.ts
printf '%s\n' '--- focus lifecycle navigation block ---'
nl -ba src/main/window/main-window-focus-lifecycle.ts | sed -n '120,155p'
printf '%s\n' '--- detached window close implementation ---'
nl -ba src/main/window/detached-terminal-window.ts | sed -n '1,175p'
printf '%s\n' '--- lifecycle tests around did-finish-load ---'
nl -ba src/main/window/createMainWindow.test.ts | sed -n '110,215p'

Repository: stablyai/orca

Length of output: 23710


🌐 Web query:

Electron 43.7.5 WebContents did-finish-load subframe hash navigation event contract

💡 Result:

**In Electron 43.7.5, `did-finish-load` is not the event for a subframe hash change.**

- `did-finish-load` fires after the **main frame’s** load completes and its `onload` has been dispatched. The v43.7.5 implementation emits it only when the finished frame is the main frame. ([raw.githubusercontent.com](https://raw.githubusercontent.com/electron/electron/v43.7.5/docs/api/web-contents.md))
- A hash navigation is an **in-page, same-document** navigation—not a document load. Electron documents `did-navigate-in-page` for in-page navigation in any frame, with an `isMainFrame` flag; `did-start-navigation` also fires and marks same-document navigation. ([raw.githubusercontent.com](https://raw.githubusercontent.com/electron/electron/v43.7.5/docs/api/web-contents.md))
- So for a subframe hash change, listen for `did-navigate-in-page` and filter for `isMainFrame === false`. Don’t expect `did-finish-load` or `did-frame-finish-load`: the latter is emitted on frame load completion, while a same-document hash change does not finish a new document load. ([raw.githubusercontent.com](https://raw.githubusercontent.com/electron/electron/v43.7.5/docs/api/web-contents.md))

This is based on the **v43.7.5** documentation and implementation, not just the current docs. ([raw.githubusercontent.com](https://raw.githubusercontent.com/electron/electron/v43.7.5/docs/api/web-contents.md))

Citations:

- 1: https://raw.githubusercontent.com/electron/electron/v43.7.5/docs/api/web-contents.md
- 2: https://raw.githubusercontent.com/electron/electron/v43.7.5/docs/api/web-contents.md
- 3: https://raw.githubusercontent.com/electron/electron/v43.7.5/docs/api/web-contents.md
- 4: https://raw.githubusercontent.com/electron/electron/v43.7.5/docs/api/web-contents.md

🏁 Script executed:

set -u
printf '%s\n' '--- detached terminal action bindings ---'
rg -n -F -e 'createOrFocusDetachedTerminalWindow' -e 'detachedTerminal' -e 'moveToNewWindow' -e 'detach' src/main src/renderer src/preload | head -160 || true
printf '%s\n' '--- exact handler blocks ---'
rg -n -F --glob '*.ts' -e 'createOrFocusDetachedTerminalWindow(' -e 'detachedTerminal:open' -e 'detachedTerminal:detach' -e 'moveToNewWindow' src || true

Repository: stablyai/orca

Length of output: 19449


🏁 Script executed:

set -u
printf '%s\n' '--- detached terminal IPC handler ---'
nl -ba src/main/ipc/detached-terminal.ts | sed -n '1,90p'
printf '%s\n' '--- terminal workspace keybinding block ---'
nl -ba src/renderer/src/components/terminal-workspace-keydown.ts | sed -n '1,115p'

Repository: stablyai/orca

Length of output: 7445


🏁 Script executed:

set -u
printf '%s\n' '--- detach action definitions and calls ---'
rg -n -F -e 'detachTerminalTab' -e 'detachedTerminal.open' -e 'detachedTerminalApi.open' -e 'detachedTerminal:open' src/renderer/src src/preload src/main | head -120 || true

Repository: stablyai/orca

Length of output: 2714


🏁 Script executed:

nl -ba src/renderer/src/store/terminals/terminal-detachment.ts | sed -n '1,125p'

Repository: stablyai/orca

Length of output: 4124


Remove the unconditional companion close from did-finish-load.

A main-frame navigation already closes existing companions at did-start-navigation. A detach request can still call window.api.detachedTerminal.open(...) before the renderer finishes unloading. The IPC handler then creates the companion, and this listener closes it when did-finish-load fires. Hash and subframe navigations do not emit this event for the main WebContents, so they are not the concern.

🐛 Suggested fix
--- "a/src/main/window/main-window-focus-lifecycle.ts"
+++ "b/src/main/window/main-window-focus-lifecycle.ts"
@@ -275,9 +275,8 @@
     resetFloatingTerminalInputFocus()
     resetShortcutRecorderFocus()
   })
   mainWindow.webContents.on('did-finish-load', () => {
-    closeAllDetachedTerminalWindows()
     rendererProcessGone = false
     attachBrowserClientPageRenderer(rendererWebContents)
     clearRendererRecoveryTimer()
     launchFailureBackoff.reset()
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
closeAllDetachedTerminalWindows()

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 476a63c5-eb2c-46d7-9f11-73540c110a74
📥 Commits

Reviewing files that changed from the base of the PR and between 3ed6d07 and 2a6c617.

📒 Files selected for processing: 11
  • src/main/ipc/detached-terminal.test.ts
  • src/main/ipc/detached-terminal.ts
  • src/main/window/createMainWindow.test.ts
  • src/preload/api/detached-terminal-api.ts
  • src/renderer/src/i18n/locales/en.json
  • src/renderer/src/store/slices/worktrees/teardown/remove-worktree-store-cleanup.ts
  • src/renderer/src/store/slices/worktrees/teardown/worktree-purge-state.ts
  • src/renderer/src/store/terminals/terminal-actions.ts
  • src/renderer/src/store/terminals/terminal-detachment.test.ts
  • src/renderer/src/store/terminals/terminal-detachment.ts
  • src/shared/detached-terminal-limits.ts
🚧 Files skipped from review as they are similar to previous changes: 1
  • src/renderer/src/i18n/locales/en.json

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to GitHub limitations.

⚠️ Outside diff range comments (2)

🟡 Minor · Reject a stale detach after PTY replacement. · terminal-detachment.ts:65-105

src/renderer/src/store/terminals/terminal-detachment.ts:65-105
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Reject a stale detach after PTY replacement.

detachTerminalTab captures the PTY before open resolves. The tab can receive a replacement during this await. The current guards check only the open token and tab presence, so the old PTY can be committed to detachedTerminalByTabId while the companion renders the old PTY and the main window hides the live replacement.

Suggested fix
         if (!locateTerminalTab(get().tabsByWorktree, tabId)) {
           void window.api.detachedTerminal.close(tabId)
           return false
         }
+        if (resolveTerminalDetachTarget(get(), tabId)?.ptyId !== ptyId) {
+          void window.api.detachedTerminal.close(tabId)
+          return false
+        }
         set((state) => ({
🟡 Minor · Close the companion when redocking invalidates its pending open. · terminal-detachment.ts:74-112

src/renderer/src/store/terminals/terminal-detachment.ts:74-112
🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win

Close the companion when redocking invalidates its pending open.

detachedTerminal:open creates the companion before its IPC promise resolves. If redockDetachedTerminalTab clears the token during that await, the invalid-token branch returns without calling detachedTerminal.close. The tab is docked, but the companion remains open.

Suggested fix
         // Why: companion closed or re-docked while open was in flight.
         if (pendingOpenTokenByTabId.get(tabId) !== openToken) {
+          if (!pendingOpenTokenByTabId.has(tabId)) {
+            void window.api.detachedTerminal.close(tabId)
+          }
           return false
         }

Update the redock test to model the main-process create-before-resolve ordering and expect the close request.


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 55abc91f-00e5-4750-b790-e1b271061bf6
📥 Commits

Reviewing files that changed from the base of the PR and between 2a6c617 and c8880d4.

📒 Files selected for processing: 2
  • src/renderer/src/store/terminals/terminal-detachment.test.ts
  • src/renderer/src/store/terminals/terminal-detachment.ts
🚧 Files skipped from review as they are similar to previous changes: 2
  • src/renderer/src/store/terminals/terminal-detachment.test.ts
  • src/renderer/src/store/terminals/terminal-detachment.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.

kimyk0120 and others added 5 commits October 16, 2026 08:31
…tab-window

# Conflicts:
#	src/main/ipc/register-core-handlers/register-core-handlers.test.ts
#	src/main/ipc/register-core-handlers/register-core-handlers.ts
#	src/main/window/createMainWindow.ts
#	src/main/window/main-window-focus-lifecycle.ts
#	src/renderer/src/components/tab-bar/SortableTab.tsx
#	src/renderer/src/components/tab-bar/SortableTabContextMenu.tsx
#	src/renderer/src/components/terminal-pane/TerminalPaneOverlayLayer.tsx
#	src/renderer/src/hooks/useIpcEvents-lifecycle.test.ts
#	src/renderer/src/i18n/locales/en.json
#	src/renderer/src/store/slices/terminals.ts
#	src/renderer/src/store/slices/worktrees/teardown/remove-worktree-map-identity.test.ts
#	src/renderer/src/store/slices/worktrees/teardown/worktree-purge-state.ts
#	src/renderer/src/store/terminals/terminal-state.ts

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01QCGg3xzzG6zeVE2aanNY4S
…tab-window

# Conflicts:
#	src/renderer/src/store/slices/worktrees/teardown/worktree-purge-state.ts

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01QCGg3xzzG6zeVE2aanNY4S
… gone

main replaced @electron-toolkit/utils with Electron APIs (stablyai#31824), so the
detached terminal window picks the dev renderer URL the same way the
dashboard pop-out does.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01QCGg3xzzG6zeVE2aanNY4S
…tab-window

# Conflicts:
#	src/renderer/src/store/slices/terminals.ts
#	src/renderer/src/store/slices/worktrees/teardown/worktree-purge-state.ts
#	src/renderer/src/store/terminals/terminal-state.ts

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01QCGg3xzzG6zeVE2aanNY4S
kimyk0120 and others added 2 commits October 26, 2026 08:32
…tab-window

# Conflicts:
#	src/main/ipc/terminal-preview.ts
#	src/renderer/src/popout.tsx
#	src/renderer/src/store/slices/worktrees-slice-test-harness.ts
#	src/renderer/src/store/slices/worktrees/teardown/worktree-purge-state.ts
#	src/renderer/src/store/terminals/terminal-state.ts

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01QCGg3xzzG6zeVE2aanNY4S
…tab-window

# Conflicts:
#	src/renderer/src/components/tab-bar/SortableTabContextMenu.tsx
#	src/renderer/src/components/terminal-workspace-keydown.test.ts
#	src/renderer/src/hooks/ipc-events/app-lifetime-ipc-bridge.ts

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01QCGg3xzzG6zeVE2aanNY4S

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2


Review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: a5e02812-cb09-4870-9c05-aeb55eca0771
Commits

Reviewing files that changed from the base of the PR and between 7b5c4fa and d6f7033.

Files selected for processing: 29
  • src/main/ipc/terminal-preview.ts
  • src/main/startup/main-process-ipc-bootstrap.ts
  • src/main/window/createMainWindow.test.ts
  • src/main/window/createMainWindow.ts
  • src/main/window/detached-terminal-window.test.ts
  • src/main/window/detached-terminal-window.ts
  • src/main/window/main-window-focus-lifecycle.ts
  • src/preload/api-types.ts
  • src/preload/index.ts
  • src/renderer/src/components/tab-bar/DetachedTerminalTabIndicator.tsx
  • src/renderer/src/components/tab-bar/SortableTab.tsx
  • src/renderer/src/components/tab-bar/SortableTabContextMenu.test.tsx
  • src/renderer/src/components/tab-bar/SortableTabContextMenu.tsx
  • src/renderer/src/components/terminal-pane/TerminalPaneOverlayLayer.tsx
  • src/renderer/src/components/terminal-workspace-keydown.test.ts
  • src/renderer/src/components/terminal-workspace-keydown.ts
  • src/renderer/src/hooks/ipc-events/app-lifetime-ipc-bridge.ts
  • src/renderer/src/i18n/locales/en.json
  • src/renderer/src/popout.tsx
  • src/renderer/src/store/slices/terminals.ts
  • src/renderer/src/store/slices/worktrees-removal-state-cleanup.test.ts
  • src/renderer/src/store/slices/worktrees-slice-test-harness.ts
  • src/renderer/src/store/slices/worktrees/teardown/remove-worktree-map-identity.test.ts
  • src/renderer/src/store/slices/worktrees/teardown/remove-worktree-store-cleanup.ts
  • src/renderer/src/store/slices/worktrees/teardown/removed-worktree-renderer-teardown.ts
  • src/renderer/src/store/slices/worktrees/teardown/worktree-purge-state.ts
  • src/renderer/src/store/terminals/terminal-actions.ts
  • src/renderer/src/store/terminals/terminal-state.ts
  • src/renderer/src/store/terminals/terminal-tab-close.ts
Files skipped from review as they are similar to previous changes: 1
  • src/renderer/src/i18n/locales/en.json

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.

Comment thread src/renderer/src/popout.tsx Resolved
kimyk0120 and others added 3 commits October 29, 2026 09:00
…tab-window

# Conflicts:
#	src/renderer/src/components/terminal-pane/TerminalPaneOverlayLayer.tsx
#	src/renderer/src/popout.tsx
#	src/renderer/src/store/slices/worktrees/teardown/worktree-purge-state.ts

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01QCGg3xzzG6zeVE2aanNY4S
For a detached tab the action focuses its companion window rather than
moving the tab, so name it as the placeholder does.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01QCGg3xzzG6zeVE2aanNY4S
The companion used the preview's 24-row snapshot and 1,000-row buffer, so
older output was gone. It now requests and keeps the user's terminal
scrollback (5,000 rows by default); only the PTY's own companion may ask
for more than a preview's 1,000 rows.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01QCGg3xzzG6zeVE2aanNY4S
@greptile-apps

greptile-apps Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 1/5

[Medium impact] Adds detached terminal window feature to the application.

Fix the companion's cross-terminal access, clipboard rejection, and Windows input behavior before merging.

Findings

  1. P1 Security Companion can stop other terminals ▶
  2. P1 Copy and paste fail ▶
  3. P1 Windows word navigation breaks ▶
  4. P2 Every tab scans all terminals ▶

Summary

Adds companion OS windows for single-pane local terminals while keeping terminal ownership in the main window.

  • A terminal tab can show its same live session in a companion window.
  • The tab stays in place while its terminal view opens in another window.
  • Closing a tab or removing its worktree also closes its companion window.

Diagram

sequenceDiagram
  participant M as Main renderer
  participant H as Main process
  participant C as Companion window
  participant P as Live PTY
  M->>H: Open companion for tab and PTY
  H->>C: Load terminal view
  M->>M: Hide pane and show placeholder
  C->>H: Connect preview and claim grid
  H->>P: Subscribe and forward input
  P-->>C: Snapshot and live output
  C->>H: Close or return to main
  H-->>M: Companion closed
  M->>M: Restore pane
Loading

Reviews (1) · Last reviewed commit: "fix(terminal): keep the pane's scrollbac..." · Reviewed by Greptile

Comment on lines +80 to +84
webPreferences: {
preload: join(__dirname, '../preload/index.js'),
sandbox: true,
partition: 'orca-detached-terminal',
webviewTag: false

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 security Companion can stop other terminals

The companion receives the full preload, so its own-PTY restriction can be bypassed through window.api.pty.management. Calling killAll() reaches a handler that checks no sender and stops every daemon session. Give the companion a narrow preload, or reject its requests on unrelated privileged channels.

How this was verified: The companion loads preload/index.js, which exposes pty.management.killAll, and that handler shuts down all listed sessions without checking the caller.

Knowledge Base Used: Desktop application platform

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not changed in this PR. The companion uses the same preload/index.js as the main window, the dashboard popout (dashboard-popout-window.ts) and the workspace-space window, and it is modelled on the popout's window policy. So this is not specific to the companion. The pty:management:* handlers check no sender for any app window today, and neither do pty:spawn and pty:kill. So rejecting only killAll for the companion would not close the gap.

The companion loads only the bundled popout.html, under the privileged navigation policy, sandboxed, on its own partition, with no webview and all permissions denied. The own-PTY check in terminalPreview scopes which PTY the companion streams and claims the grid for. It is not a preload privilege boundary, and the PR text says it covers terminalPreview only.

A narrowed preload, or sender gating on the privileged channels, would apply to every auxiliary window, so I would rather leave that to a separate change the maintainers scope. I am happy to follow up if you want it.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That’s a fair distinction. The own-PTY restriction only scopes terminalPreview; it doesn’t make the shared preload a security boundary. And because pty:spawn, pty:kill, and the management handlers are broadly callable today, blocking just killAll for this renderer would be an incomplete fix.

I agree this is a shared auxiliary-window privilege issue, not something to solve with a one-off exception in this PR. I’ll withdraw the finding here; a follow-up covering the preload/IPC boundary across auxiliary windows is the right scope.

Tip: You can customize Greptile's behavior for this repo with .greptile/rules.md and .greptile/config.json.

Comment on lines +52 to +56
<AgentTerminalPreview
ptyId={ptyId}
scrollbackRows={scrollbackRows}
className="h-full min-h-0 flex-1"
/>

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Copy and paste fail

AgentTerminalPreview uses readClipboardText() and writeTerminalClipboardText(), but their handlers admit only the main renderer or the dashboard popout. The new companion matches neither, so paste is rejected and copying a selection silently fails. Admit registered detached companions to the text-only clipboard channels without granting file or image access.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in c07f68a. A registered companion window now passes the text-clipboard sender check, with the same text-only authority as the dashboard popout. Selection, image, file and remote clipboard channels still refuse it. Covered by clipboard-detached-terminal-access.test.ts.

Comment on lines +52 to +56
<AgentTerminalPreview
ptyId={ptyId}
scrollbackRows={scrollbackRows}
className="h-full min-h-0 flex-1"
/>

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Windows word navigation breaks

The companion omits terminalInput, so local Windows terminals lose their ConPTY input rules. Without that prop, resolvePreviewShortcutAction() treats localWindowsConpty as false. Ctrl+Left/Right then sends ESC b/ESC f instead of leaving the Windows key encoding intact, producing stray characters in PSReadLine. Pass the terminal's input profile into the companion, as the dashboard preview does.

Knowledge Base Used: Terminal runtime and interaction

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in b6f7300. The main renderer resolves the pane's input facts with resolveDashboardCardTerminalInput, as the dashboard does for a card, and sends them to main whenever they change. Main validates the facts with the dashboard's isDashboardTerminalInput and keeps the latest set for that companion. The companion reads the set and follows later pushes. It mounts AgentTerminalPreview only once the set is known, because xterm reads the ConPTY and kitty options at mount. A local Windows ConPTY pane therefore keeps Ctrl+Left/Right as Windows key events in the companion.

Comment on lines +14 to +16
const target = useAppStore(
useShallow((state) => resolveTerminalDetachTarget(state, props.tab.id))
)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Every tab scans all terminals

Every mounted terminal tab now runs resolveTerminalDetachTarget() on store updates. That function flattens all worktrees' terminal tabs before finding one tab. With many visible tabs, each update repeats the full scan and allocation for every tab, even when nothing is detached. Select the tab and layout directly, or memoize this work by the relevant map identities. useShallow avoids the resulting render, not the scan.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 6045154. TerminalSortableTab now selects only its own layout and derives the target from the tab it already receives (resolveTabDetachTarget). No tab row flattens the worktrees' tab lists any more. resolveTerminalDetachTarget still looks the tab up for the detach action itself, which runs once per click.

kimyk0120 and others added 3 commits October 30, 2026 09:24
The text clipboard channels admitted only the main renderer and the
dashboard popout, so paste in a detached terminal was rejected and
copying a selection failed silently. Registered companion windows now
get the same text-only authority as the popout; selection, image, file
and remote clipboard channels still refuse them.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01QCGg3xzzG6zeVE2aanNY4S
The companion mounted its preview without the pane's host-input facts,
so a local Windows ConPTY pane lost its key rules there: Ctrl+Left and
Ctrl+Right sent ESC b / ESC f. Only the main renderer can resolve those
facts. It now resolves them as the dashboard does for a card, and sends
them whenever they change. Main keeps the latest set per companion.
The companion mounts its preview once the set is known, because xterm
reads its ConPTY and kitty options at mount, and then follows later
changes.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01QCGg3xzzG6zeVE2aanNY4S
Each terminal tab ran resolveTerminalDetachTarget on every store update,
flattening every worktree's tabs to find its own. A tab row now reads
only its layout and derives the target from the tab it already has.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01QCGg3xzzG6zeVE2aanNY4S
@kimyk0120

Copy link
Copy Markdown
Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1


Review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: b4366de6-0d70-42ca-abc2-73d52b4fc134
Commits

Reviewing files that changed from the base of the PR and between d6f7033 and 6045154.

Files selected for processing: 35
  • src/main/ipc/dashboard-payload-validation.ts
  • src/main/ipc/detached-terminal.test.ts
  • src/main/ipc/detached-terminal.ts
  • src/main/ipc/terminal-preview.test.ts
  • src/main/ipc/terminal-preview.ts
  • src/main/window/clipboard-detached-terminal-access.test.ts
  • src/main/window/clipboard-ipc-handlers.ts
  • src/main/window/createMainWindow.ts
  • src/main/window/detached-terminal-window.test.ts
  • src/main/window/detached-terminal-window.ts
  • src/preload/api-types.ts
  • src/preload/api/detached-terminal-api.ts
  • src/preload/api/detached-terminal-bridge.ts
  • src/preload/index.ts
  • src/renderer/src/components/dashboard-popout/AgentTerminalPreview.tsx
  • src/renderer/src/components/detached-terminal/DetachedTerminalWindow.test.tsx
  • src/renderer/src/components/detached-terminal/DetachedTerminalWindow.tsx
  • src/renderer/src/components/settings/keybinding-title-copy.ts
  • src/renderer/src/components/tab-bar/SortableTab.tsx
  • src/renderer/src/components/tab-bar/SortableTabContextMenu.test.tsx
  • src/renderer/src/components/tab-bar/SortableTabContextMenu.tsx
  • src/renderer/src/components/tab-bar/TerminalSortableTab.tsx
  • src/renderer/src/components/terminal-pane/TerminalPaneOverlayLayer.tsx
  • src/renderer/src/components/terminal-workspace-keydown.test.ts
  • src/renderer/src/components/terminal-workspace-keydown.ts
  • src/renderer/src/hooks/ipc-events/detached-terminal-ipc-bridge.test.ts
  • src/renderer/src/hooks/ipc-events/detached-terminal-ipc-bridge.ts
  • src/renderer/src/i18n/locales/en.json
  • src/renderer/src/popout.tsx
  • src/renderer/src/store/slices/worktrees-removal-state-cleanup.test.ts
  • src/renderer/src/store/slices/worktrees-slice-test-harness.ts
  • src/renderer/src/store/slices/worktrees/teardown/worktree-purge-state.ts
  • src/renderer/src/store/terminals/detached-terminal-input.test.ts
  • src/renderer/src/store/terminals/detached-terminal-input.ts
  • src/renderer/src/store/terminals/terminal-detachment.ts
Files skipped from review as they are similar to previous changes: 1
  • src/renderer/src/i18n/locales/en.json

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.

…tab-window

Main moved tab right-click menus to ContextMenu, dropped the
remove-worktree-map-identity suite, and grew SortableTab.tsx and
clipboard-ipc-handlers.ts to their line caps. The move action now sits in
the ContextMenu items, the hover card's program name and the
terminal-preview sender check moved into small modules so both files stay
under the cap, and the detached placeholder follows main's no-dim rule
over a theme image.

# Conflicts:
#	src/renderer/src/components/dashboard-popout/AgentTerminalPreview.tsx
#	src/renderer/src/components/tab-bar/SortableTab.tsx
#	src/renderer/src/components/tab-bar/SortableTabContextMenu.tsx
#	src/renderer/src/components/terminal-pane/TerminalPaneOverlayLayer.tsx
#	src/renderer/src/components/terminal-workspace-keydown.ts
#	src/renderer/src/i18n/locales/en.json
#	src/renderer/src/store/slices/worktrees/teardown/remove-worktree-map-identity.test.ts

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01QCGg3xzzG6zeVE2aanNY4S
kimyk0120 and others added 3 commits November 2, 2026 10:13
Main's changed-code gate now refuses type assertions. The terminal input
check is a type guard, so main admits the companion's facts without a
cast. The resolver takes only the slices it reads, so its test builds a
typed state, and the bridge and window tests type their holders.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01QCGg3xzzG6zeVE2aanNY4S
The hidden pane stays mounted after a tab moves to its own window, so a
reattach or agent restart can bind a new PTY there. The window kept
streaming the PTY it opened with, and the new one stayed hidden until the
user re-docked. The main renderer now closes the window and re-docks the
tab once the tab resolves to another PTY or splits.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01QCGg3xzzG6zeVE2aanNY4S
@kimyk0120

Copy link
Copy Markdown
Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor
Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

…tab-window

# Conflicts:
#	src/renderer/src/store/slices/worktrees-removal-state-cleanup.test.ts
…tab-window

# Conflicts:
#	src/renderer/src/components/tab-bar/SortableTab.tsx
#	src/renderer/src/store/slices/terminals.ts
@kimyk0120

Copy link
Copy Markdown
Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor
Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to GitHub limitations.

⚠️ Outside diff range comments (1)

Minor · Close a companion bound to another PTY before replacing its… · detached-terminal-window.ts:60-115

src/main/window/detached-terminal-window.ts:60-115
Minor · Functional Correctness · Quick win

Close a companion bound to another PTY before replacing its entry.

createOrFocusDetachedTerminalWindow reuses any live companion for the tab. It does not check the companion's PTY. If a second detach request for the same tab overlaps an open that is still pending, and the tab rebinds in between, the renderer can record the new PTY as detached while the companion still shows the old PTY. The mismatch persists until the user closes the companion or moves the tab back.

Replacing the entry alone is not safe. The old companion stays open, untracked, and bound to the old PTY. Close the mismatched companion and remove its entry before creating the replacement. The replaced window's closed handler then returns early and does not re-dock the new state.

Suggested fix
   const existing = entriesByTabId.get(args.tabId)
-  if (existing && !existing.window.isDestroyed()) {
+  if (existing && existing.ptyId === args.ptyId && !existing.window.isDestroyed()) {
     if (existing.window.isMinimized()) {
       existing.window.restore()
     }
     if (!isBackgroundLaunch()) {
       existing.window.focus()
     }
     return existing.window
   }
+  if (existing) {
+    // Why: a companion bound to another PTY must close before its entry is replaced.
+    entriesByTabId.delete(args.tabId)
+    if (!existing.window.isDestroyed()) {
+      existing.window.close()
+    }
+  }
Review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: c752b395-e911-4875-bece-82ee55b78835
Commits

Reviewing files that changed from the base of the PR and between 63862ef and 2a43d74.

Files selected for processing: 19
  • src/main/ipc/dashboard-payload-validation.ts
  • src/main/ipc/terminal-preview.ts
  • src/main/window/createMainWindow.test.ts
  • src/main/window/main-window-focus-lifecycle.ts
  • src/renderer/src/components/detached-terminal/DetachedTerminalWindow.tsx
  • src/renderer/src/components/settings/shortcuts/keybinding-title-copy.ts
  • src/renderer/src/components/tab-bar/SortableTab.tsx
  • src/renderer/src/components/tab-bar/TerminalSortableTab.tsx
  • src/renderer/src/components/tab-bar/terminal-tab-program-name.ts
  • src/renderer/src/components/terminal-pane/TerminalPaneOverlayLayer.tsx
  • src/renderer/src/hooks/ipc-events/detached-terminal-ipc-bridge.test.ts
  • src/renderer/src/i18n/locales/en.json
  • src/renderer/src/store/slices/terminals.ts
  • src/renderer/src/store/slices/worktrees-removal-state-cleanup.test.ts
  • src/renderer/src/store/terminals/detached-terminal-input.test.ts
  • src/renderer/src/store/terminals/detached-terminal-input.ts
  • src/renderer/src/store/terminals/terminal-actions.ts
  • src/renderer/src/store/terminals/terminal-detachment.ts
  • src/renderer/src/store/terminals/terminal-state.ts
Files with no reviewable changes: 1
  • src/renderer/src/components/tab-bar/SortableTab.tsx
Files skipped from review as they are similar to previous changes: 1
  • src/renderer/src/i18n/locales/en.json

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review.

A second open request for the same tab focused the existing companion
even when it showed another PTY, so the renderer could record the new
PTY as detached while the window still showed the old one. Close the
mismatched companion and drop its entry first; its closed handler then
returns early and does not re-dock the replacement.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Cx1ytb2dGbTo2FeZeqZAuh
@kimyk0120

Copy link
Copy Markdown
Author

Re the outside-diff finding on detached-terminal-window.ts:60-115 (close a companion bound to another PTY before replacing its entry): fixed in ca2a53f. createOrFocusDetachedTerminalWindow now reuses a live companion only when its PTY matches. Otherwise it drops the entry and closes the old window, so the old window's closed handler returns early and does not re-dock the replacement. Added a test for the mismatched-PTY case.

@kimyk0120

Copy link
Copy Markdown
Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor
Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

…tab-window

Main deleted SortableTabContextMenu.test.tsx; the move-to-new-window cases
this PR had added there now live in SortableTabContextMenu.detached-window.test.tsx.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Cx1ytb2dGbTo2FeZeqZAuh
@kimyk0120

Copy link
Copy Markdown
Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor
Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: Move a terminal tab to its own window

1 participant