fix(pty): strip inherited Claude Code session env before spawning child CLI#106
Merged
Conversation
…ld CLI When YouCoded is launched from inside a Claude Code session (e.g. running `bash scripts/run-dev.sh` from the Bash tool, or any terminal that is itself a CC session), the Electron process inherits CLAUDECODE=1, CLAUDE_CODE_CHILD_SESSION=1, CLAUDE_CODE_SESSION_ID=<parent>, etc. pty-worker spread `...process.env` into the spawned `claude`, so the child believed it was a NESTED/child session. Nested interactive Claude Code does NOT write a top-level transcript to ~/.claude/projects/<slug>/<id>.jsonl. Since the TranscriptWatcher is the sole source of chat-view state, the chat view stayed permanently empty — even though the terminal/PTY showed output normally and hooks still fired. The built app was unaffected only because it's normally launched from a clean Windows env. Strip the CC session-identity markers from the child env so every session we spawn is a clean top-level session regardless of how YouCoded itself was launched. Verified equivalent: relaunching dev with these vars unset (`env -u ...`) restored chat-view transcript capture. Co-Authored-By: Claude Opus 4.8 (1M context) <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.
Problem
When YouCoded is launched from inside a Claude Code session (e.g.
bash scripts/run-dev.shrun from the Bash tool, or any terminal that is itself a CC session), the Electron process inherits Claude Code's own session-identity env vars:pty-worker.jsspread...process.envinto everyclaudeit spawns, so the child CLI believed it was a nested/child session. Nested interactive Claude Code does not write a top-level transcript to~/.claude/projects/<slug>/<id>.jsonl.Because the
TranscriptWatcheris the sole source of chat-view state, the chat view stayed permanently empty — messages reached Claude and responses appeared in terminal view, but never in chat view. Hooks still fired (auto-title, session-start) and the PTY worked, which made it look like only chat rendering was broken.The built app was unaffected only because it's normally launched from a clean Windows environment (no CC vars).
Fix
Strip the CC session-identity markers from the child env in
pty-worker.jsbeforepty.spawn, so every session YouCoded spawns is a clean top-level session regardless of how YouCoded itself was launched.CLAUDE_DESKTOP_SESSION_ID/CLAUDE_DESKTOP_PIPEare still set fresh per-session (unchanged).Verification
node -cparses cleanly.env -u CLAUDECODE -u CLAUDE_CODE_CHILD_SESSION ...) immediately restored chat-view transcript capture. This patch performs the identical strip at the spawn chokepoint.🤖 Generated with Claude Code