Fix agent resume, command injection and GitHub CLI probing in terminals - #388
Open
0x92 wants to merge 2 commits into
Open
Fix agent resume, command injection and GitHub CLI probing in terminals#3880x92 wants to merge 2 commits into
0x92 wants to merge 2 commits into
Conversation
Two independent fixes to agent terminals, both about noise and silent failure rather than features. Resume: every spawned terminal inherited the launching process's environment wholesale. When Pane itself is started from inside a Claude Code session — a terminal, a script, a dev run — that includes CLAUDE_CODE_CHILD_SESSION, and Claude Code responds by switching transcript persistence off. Nothing is written, so the next `claude --resume <id>` fails with "No conversation found" and the pane comes back empty after a restart, with nothing on screen explaining why. Those markers are now stripped at spawn: every terminal Pane starts is a new top-level session, so the launching agent's identity is always wrong to pass on. GitHub CLI: PR enrichment ran `gh pr list` on every git status refresh. On a machine without `gh` that is two console errors per session per refresh for something that was never going to work. Availability is now probed once per execution context (keyed by WSL distribution, since the host and a distro have separate PATHs) and the lookup itself is silent — a repository with no GitHub remote, or an unauthenticated `gh`, is a normal state. Tests: environment stripping (5); the PR enrichment tests now count lookups rather than every command, since the probe adds one.
A terminal that has just printed its prompt can lose the first character it is given. ConPTY switches input modes around the prompt, and a resize arriving in the same moment makes it likelier. The symptom is a command that runs with its first letter missing — `laude --resume <id>`, which fails as "command not found" and reads as if Pane sent nonsense. It shows up on restart, exactly when a session is trying to resume its agent. The command is now preceded by a byte that costs nothing either way: Ctrl-U, which clears the input line and at a fresh prompt has nothing to clear. Whatever the shell swallows, it is not part of the command. The command follows 60ms later, once that window has passed. Kept in its own module so it can be unit-tested without dragging in the database singleton that terminalPanelManager depends on.
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.
Description
Three independent fixes to agent terminals. None of them is a feature; all three are about a failure that looks like the agent misbehaving.
1. Resumed sessions came back empty. Every spawned terminal inherited the launching process's environment wholesale. When Pane itself is started from inside a Claude Code session — a terminal, a script, a dev run — that includes
CLAUDE_CODE_CHILD_SESSION, and Claude Code responds by switching transcript persistence off ("Transcript saving is off — inherited CLAUDE_CODE_CHILD_SESSION marker"). Nothing is written, so the nextclaude --resume <id>fails with "No conversation found with session ID" and the pane comes back blank after a restart, with nothing on screen explaining why. Those markers are now stripped at spawn: every terminal Pane starts is a new top-level session, so the launching agent's identity is always wrong to pass on.2. The resume command sometimes ran as
laude. A terminal that has just printed its prompt can lose the first character it is given — ConPTY switches input modes around the prompt, and a resize arriving in the same moment makes it likelier. The command then fails as "command not found" and reads as if Pane sent nonsense. It shows up on restart, exactly when a session is trying to resume its agent. The command is now preceded by a byte that costs nothing either way: Ctrl-U clears the input line, and at a fresh prompt there is nothing to clear. Whatever the shell swallows is not part of the command; the command follows 60 ms later.3. Two red console lines per session, per refresh, on machines without
gh. PR enrichment rangh pr liston every git status refresh regardless of whether the GitHub CLI exists. Availability is now probed once per execution context — keyed by WSL distribution, since the host and a distro have separate PATHs — and the lookup itself is silent. A repository with no GitHub remote, or an unauthenticatedgh, is a normal state for a local project, not something to shout about.Notes
Both new modules (
agentSessionEnv,terminalInjection) sit next toterminalPanelManagerrather than inside it, so they can be unit-tested without pulling in the database singleton it depends on.Type of Change
Checklist
pnpm typecheckandpnpm lintlocallypnpm electron-devCritical Areas Modified
Additional Notes
Tests: 5 for environment stripping, 4 for the injection sequence, and the existing PR-enrichment tests now count
gh pr listlookups rather than every command, since the availability probe adds one.Verified in the running app: a session whose agent had been resumed after a restart, on a host where Pane itself was launched from inside a Claude Code session.