Background shells + auto-close for the create_shell MCP tool - #140
Draft
big-guy wants to merge 4 commits into
Draft
Background shells + auto-close for the create_shell MCP tool#140big-guy wants to merge 4 commits into
big-guy wants to merge 4 commits into
Conversation
big-guy
marked this pull request as ready for review
June 1, 2026 05:37
Adds two optional args to the create_shell MCP tool:
- `background: true` — the tab is created without switching the UI to it,
and its title renders italic until the tab is selected (selecting it
drops the flag via selectTab). Background shells also spawn their PTY
while hidden so the command actually runs even though the tab is never
displayed.
- `close_delay` (seconds, >= 0, default 30) — after the command exits
successfully the tab auto-closes once the delay elapses, unless it is
its leaf's active tab at fire time. A non-zero (failed) exit never
auto-closes. A corner banner ("Keep open" / "Close when done") lets the
user cancel; "Keep open" clears closeDelay, which the monitor re-reads
at fire time.
Implementation:
- terminals slice: new `background` + `closeDelay` tab fields and a
terminals/tabCloseDelayChanged event/reducer.
- PanesFSM.addTab gains an { activate } option; selectTab clears the
background flag; new setShellCloseDelay method (persists).
- PtyManager.addExitListener exposes exit codes; new
ShellAutoCloseMonitor drives the close timer off it.
- XTerminal: spawn-while-hidden for background shells + the auto-close
prompt banner; TerminalPanel italicizes background tab titles.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
The "Keep open" / "Close when done" banner is only useful while the command is still running. Wire the terminal-exit listener for shell tabs (previously agent-only) and hide the banner once exited. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
- Replace hardcoded `italic` tab styling with a semantic `tab-unviewed` Tailwind utility (styles.css) so the intent — an unviewed tab — is named. - Reword the auto-close prompt buttons: "Keep open" -> "Do not close", "Close when done" -> "Close if successful" (and matching comments). - Tighten the create_shell MCP `background` and `close_delay` arg descriptions in mcp-bridge.js. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
- panes-fsm selectTab: replace the destructure + `void _bg` + `as TerminalTab`
cast ceremony with a plain `{ ...tab, background: undefined }` patch.
- shell-autoclose-monitor locate(): collapse findLeafByTabId + redundant
leaf.tabs.find re-search into one optional-chained lookup.
No behavior change. Typecheck, build, and 71 reducer/FSM tests pass.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
big-guy
force-pushed
the
background-shells
branch
from
June 4, 2026 21:49
385dedf to
eaf70fb
Compare
big-guy
marked this pull request as draft
June 5, 2026 01:04
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Expands the
create_shellMCP tool with two optional arguments so agents can run commands without commandeering the user's view, and clean up after themselves.What's new
background: true— the shell tab is created without switching the UI to it. Its title renders italic (tab-unviewed) until the user selects it, at which point it's promoted to a normal tab.close_delay(seconds, integer ≥ 0, default 30) — after a successful exit (code 0), the tab auto-closes once the delay elapses.0closes immediately on success.Rules
Implementation notes
background/closeDelaylive on theTerminalTabslice (shared world state); the prompt-dismissed flag is renderer-local.terminals/removedevent, so the newShellAutoCloseMonitorhooksPtyManager.addExitListenerdirectly and re-reads state at fire time (so "Do not close" / active-tab transitions during the countdown are honored).XTerminalspawns their PTY immediately at a fallback grid instead of deferring until visible.Verification
npm run typecheck,npx electron-vite build, andnpx vitest runall pass (71 reducer/FSM tests, including new coverage for thetabCloseDelayChangedreducer,addTabbackground activation, andselectTabflag-clearing).🤖 Generated with Claude Code