You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
feat(terminal): move a terminal tab to its own window - #28963
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.
(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)
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.
Fixesstablyai#28955
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01QCGg3xzzG6zeVE2aanNY4S
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.
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: 5
Check name
Status
Explanation
Title check
The title clearly describes the main change: moving a terminal tab to its own window.
Description check
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
[#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
[#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
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.
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review.
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
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.
‼️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.
🚧 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.
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.
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.
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.
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.
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
The reason will be displayed to describe this comment to others. Learn more.
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.
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.
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.
The reason will be displayed to describe this comment to others. Learn more.
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.
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.
The reason will be displayed to describe this comment to others. Learn more.
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.
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.
The reason will be displayed to describe this comment to others. Learn more.
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.
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.
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
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.
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
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.
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.
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 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.
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.
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.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
tab.moveToNewWindowkeybinding action that is unassigned by default.Mechanism: the main window stays the only owner of app state, session persistence and PTY lifecycle; the companion is a view.
detached-terminal-window.tscreates one sandboxedBrowserWindowper tab on the existingpopout.htmlentry (modelled ondashboard-popout-window.ts; own partition, no webview, privileged navigation policy, permissions denied). Itsclosedhandler is the single place that forgets the window and notifies the main renderer.detached-terminal.tsregisters thedetachedTerminal:*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).terminalPreviewIPC andAgentTerminalPreview;terminal-preview.tsnow 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.terminal-detachment.ts, not part of the workspace session);TerminalPaneOverlayLayerkeeps 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
(Captured headlessly with the repo's Playwright
electron-headlesssetup against the seeded e2e repo.)Testing
New unit tests: companion window creation/dedupe/focus,
closednotifies exactly once even whenclose()is asynchronous,render-process-gonecloses the companion, main-window close/reload/crash closes companions, handlers registered once,terminalPreviewper-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:nodeoversrc/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 existingreact185update-depth guards and theuseIpcEventssuites).pnpm typecheckand everypnpm lintstep pass (the Bun-launchedverify:localization-catalogsstep 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:
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.BrowserWindowconstruction as the dashboard pop-out; no platform-specific code.Button, existing tokens and icons.Agent skill upstream boundary
Notes
Ensure no issues in: Security, Cross-platoform support (Linux, Windows, Mac), Remote SSH, Mobile, general backwards compatibility, performance
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)🤖 Generated with Claude Code
https://claude.ai/code/session_01QCGg3xzzG6zeVE2aanNY4S