Skip to content

fix(bridge): strip inherited CLAUDECODE env vars before spawning claude#2

Open
CommsConnectgmbh wants to merge 1 commit into
mainfrom
fix/strip-claude-code-env-on-spawn
Open

fix(bridge): strip inherited CLAUDECODE env vars before spawning claude#2
CommsConnectgmbh wants to merge 1 commit into
mainfrom
fix/strip-claude-code-env-on-spawn

Conversation

@CommsConnectgmbh

Copy link
Copy Markdown
Owner

Summary

Fixes the showstopper from #1: when the bridge is started from inside a Claude Code session, the spawned claude process inherits CLAUDECODE / CLAUDE_CODE_* env vars and refuses to launch with:

Cannot be launched inside another Claude Code session

This makes the bridge effectively unstartable / undebuggable from a Claude Code session.

Changes

  • New cleanClaudeEnv(extra) helper in bridge/src/server.mjs that returns process.env with the inherited Claude-Code vars stripped (CLAUDECODE, CLAUDE_CODE_ENTRYPOINT, CLAUDE_CODE_SESSION_ID, CLAUDE_AGENT_SDK_VERSION, CLAUDE_CODE_ENABLE_SDK_FILE_CHECKPOINTING, CLAUDE_CODE_ENABLE_TASKS).
  • Applied to both spawn sites:
    • stream-json child (spawn(CLAUDE_BIN, ...))
    • interactive PTY (pty.spawn(CLAUDE_BIN, ...))
  • Behavior unchanged when bridge is started outside a Claude Code session — the vars simply don't exist to strip.

Test plan

  • Start bridge from a plain shell → claude spawns as before.
  • Start bridge from inside a Claude Code session → claude now spawns cleanly instead of erroring.
  • Interactive PTY session works (no inherited session ID confusing --resume).

Closes #1 (partially — node-pty bump tracked separately).

If the bridge is started from inside a Claude Code session, the spawned
`claude` CLI inherits CLAUDECODE / CLAUDE_CODE_* env vars and refuses to
launch with "Cannot be launched inside another Claude Code session".

Apply the strip to both spawn sites (stream-json child + interactive PTY)
via a shared cleanClaudeEnv() helper.

Refs #1
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.

Feedback: Windows-Setup + nested Claude Code session detection (Showstopper)

1 participant