Skip to content

fix(pty): strip inherited Claude Code session env before spawning child CLI#106

Merged
itsdestin merged 1 commit into
masterfrom
fix/strip-cc-env-on-spawn
Jun 17, 2026
Merged

fix(pty): strip inherited Claude Code session env before spawning child CLI#106
itsdestin merged 1 commit into
masterfrom
fix/strip-cc-env-on-spawn

Conversation

@itsdestin

Copy link
Copy Markdown
Owner

Problem

When YouCoded is launched from inside a Claude Code session (e.g. bash scripts/run-dev.sh run 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:

CLAUDECODE=1
CLAUDE_CODE_CHILD_SESSION=1
CLAUDE_CODE_SESSION_ID=<parent>
CLAUDE_CODE_ENTRYPOINT / CLAUDE_CODE_EXECPATH

pty-worker.js spread ...process.env into every claude it 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 TranscriptWatcher is 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.js before pty.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_PIPE are still set fresh per-session (unchanged).

Verification

  • node -c parses cleanly.
  • Proven equivalent during diagnosis: relaunching dev with these vars unset (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

…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>
@itsdestin itsdestin merged commit 6ca21e6 into master Jun 17, 2026
2 checks passed
@itsdestin itsdestin deleted the fix/strip-cc-env-on-spawn branch June 17, 2026 21:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant