Stop restored shell tabs from re-running their command - #292
Merged
Conversation
A shell tab created by an agent persists the command it was launched with, and XTerminal treated that field as an instruction: any mount without a live PTY spawned `zsh -ilc <command>`. Reopening Ness (or touching a tab whose command had already exited) therefore re-ran it unprompted. The command is only ever meant to run once, in createShell's eager spawn, so the renderer now always opens a plain interactive shell and the persisted command stays as a record of origin. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Scrollback was already being written to userData/terminal-history/<id>, but getHistory() only read the in-memory map, and that map is seeded from disk inside create(). On a cold start the renderer asks for history before it spawns, so it got '' and skipped the replay — create() then loaded the file into a buffer nobody ever displayed, which is why a renderer reload showed scrollback but relaunching the app did not. Both entry points now go through ensureHistoryBuffer, so the file is read on first touch (at most once per id) whichever call arrives first. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Shells created via create_shell run their command exactly once, at creation. Remounting such a tab after a restart handed back an interactive prompt, which is not how these shells ever behave — once the command's shell exits mid-session the tab is just a transcript. Drop the renderer's pty:create for a command shell that has no live PTY. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
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.
Summary
create_shellpersists the command it was launched with.XTerminaltreated that field as an instruction: any mount without a live PTY spawnedzsh -ilc <command>. After a restart there's never a live PTY, so opening a previously-created shell tab silently re-ran whatever the agent had launched (npm run dev, a build, anything). Same thing mid-session once the command's shell had exited and the tab remounted.createShell(src/main/index.ts) at creation time.commandstays as a record of origin: still reported bylist_shells, still the tab's default label. Comments onTerminalTab.command/PersistedTab.commandupdated to say so, since the field name reads like an instruction.Test plan
npm run typechecknpx electron-vite buildcreate_shellwith a command → command runs immediately in the new tab (unchanged)+→ Shell) behave as before🤖 Generated with Claude Code