Skip to content

Keep the Claude session Switchboard was started from out of new sessions - #111

Open
vivi7 wants to merge 1 commit into
doctly:mainfrom
vivi7:fix/pty-env-parent-session
Open

vivi7 wants to merge 1 commit into
doctly:mainfrom
vivi7:fix/pty-env-parent-session

Conversation

@vivi7

@vivi7 vivi7 commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

Summary

When Switchboard itself is started from inside a Claude Code session (from a terminal in a session, or by a session that restarts the app), every new Claude session it starts afterwards gets no title, never shows up as a real row (it stays "New session"), keeps ignoring a rename and cannot be resumed. This fixes it.

Why

Claude Code exports variables describing its own session to every child process: CLAUDECODE, CLAUDE_CODE_SESSION_ID, CLAUDE_CODE_CHILD_SESSION, CLAUDE_CODE_ENTRYPOINT, CLAUDE_PID, the bridge and messaging ones, CLAUDE_CODE_SSE_PORT… An Electron app launched from there inherits them, and buildPtyEnv passed them on to every PTY. Plain terminals already drop CLAUDECODE, but Claude sessions got everything.

A claude started with CLAUDE_CODE_CHILD_SESSION=1 and another session's CLAUDE_CODE_SESSION_ID takes itself for a child of that session: it writes no transcript of its own. Seen here with Claude Code 2.1.317: a session started with --session-id <id> ran for over an hour and ~/.claude/projects/**/<id>.jsonl never appeared (only session-env/<id> and file-history/<id>), while sessions started from a Switchboard launched from the Dock wrote theirs as usual. With no transcript there is no ai-title, nothing for the index to pick up, and nothing for --resume.

What it does

pty-env.js only: buildPtyEnv leaves out the variables that describe the session Switchboard was started from. Settings a user puts in env (CLAUDE_CODE_MAX_OUTPUT_TOKENS, CLAUDE_CONFIG_DIR, …) are kept. CLAUDE_CODE_SSE_PORT is dropped too, since it points at that session's IDE server; Switchboard still sets its own for --ide right after.

Testing

  • New test in test/pty-env.test.js: the inherited session variables are dropped and user settings are kept.
  • Manual check on macOS: an app instance started from a shell inside a Claude session (electron . with an isolated SWITCHBOARD_DATA_DIR), then a terminal opened in it echoing $CLAUDECODE|$CLAUDE_CODE_SESSION_ID|$CLAUDE_CODE_CHILD_SESSION: before, the parent session's id and 1; after, all empty, with CLAUDE_CODE_MAX_OUTPUT_TOKENS still there.
  • npm test: the only failures are fileDiff reads tracked and untracked changes… and projectGitInfo and projectGitDiff expose read-only data…, which fail the same way on current main on my machine (they trip over a global color.ui = always).

When Switchboard is started from inside a Claude Code session (a terminal in a session, or a session restarting the app), it inherits CLAUDECODE, CLAUDE_CODE_SESSION_ID, CLAUDE_CODE_CHILD_SESSION and the other variables Claude gives its children, and passed them to every session it started. A CLI started with them takes itself for a child of that old session and writes no transcript of its own, so a new session never got its title, never got a row from the index and could not be resumed. They are now left out of every PTY's environment; the settings a user puts in env stay.
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