Repository navigation
fix(terminal): strip inherited CLAUDECODE, CLAUDE_CODE_EXECPATH and CLAUDE_CODE_ENTRYPOINT from spawned PTY env - #10188
Conversation
Walkthrough
Pre-merge checks:
|
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: e9b10787-076b-4b01-8f75-93459f18827c
📥 Commits
Reviewing files that changed from the base of the PR and between 8f40ddf and fdd9d7b484fc874a9b18d7380dfcc033bb505e67.
📒 Files selected for processing (8)
src/main/daemon/pty-subprocess.test.tssrc/main/daemon/pty-subprocess.tssrc/main/providers/local-pty-provider.test.tssrc/main/providers/local-pty-provider.tssrc/main/pty/claude-session-env.test.tssrc/main/pty/claude-session-env.tssrc/relay/pty-handler.test.tssrc/relay/pty-handler.ts
a5fbfc1 to
8821313
Compare
…arkers from PTY env An Orca launched from inside a Claude Code session inherits CLAUDECODE, CLAUDE_CODE_EXECPATH, and CLAUDE_CODE_ENTRYPOINT alongside the child-session stamps stablyai#9961 already strips. Every pane then looks nested to Claude Code and to agent-aware tools, and the inherited entrypoint overrides Claude's own detection. Add them to the existing inherited-stamp deletion list so every local, daemon, and relay spawn drops them while explicit pane values win. Closes stablyai#9155 Co-authored-by: 백승현 <[email protected]>
8821313 to
5f010a8
Compare
ELI5
If you start Orca from inside a Claude Code session, Orca was passing some of Claude's "you are already inside Claude" markers down to every new terminal. A Claude started in one of those terminals then thought it was nested inside another Claude and behaved differently. This change removes those leftover markers when a terminal opens, so each terminal starts clean. A value a terminal sets for itself on purpose is still kept.
What Changed
Before: #9961 already stripped the inherited
CLAUDE_CODE_CHILD_SESSION,CLAUDE_CODE_SESSION_IDandCLAUDE_CODE_BRIDGE_SESSION_IDstamps.CLAUDECODE,CLAUDE_CODE_EXECPATHandCLAUDE_CODE_ENTRYPOINTstill leaked into every pane when Orca, or its terminal daemon, was started from inside a Claude Code session.After: those three keys are stripped too, on the local, daemon and SSH relay spawn paths.
Mechanism:
src/main/ipc/pty/host-env/spawn-env-keys.ts: added the three keys toCLAUDE_CHILD_SESSION_STAMP_ENV_KEYS. This list already goes throughgetInheritedAgentSessionStampEnvKeysToDelete->assemblePtySpawnEnvDeletionsand is sent asenvToDeleteto every provider. A key that the pane's own env sets explicitly is still kept (the existingenv[key] === undefinedfilter).src/main/ipc/pty/pty-spawn-env-terminal-basics.test.ts: added the three keys to the existing regression test.Why
CLAUDECODEturns on Claude's "running under Claude Code" mode: some tools are disabled, the subscription-type override is ignored, and the diagnostics file is turned off. Agent-detecting tools also treat the user's own shell as an agent.CLAUDE_CODE_ENTRYPOINT(for examplesdk-tsorclaude-desktop) stops Claude from detecting its own entrypoint, so the pane's Claude reports the wrong identity.CLAUDE_CODE_EXECPATHis a stale path to the executable of the session that launched Orca.Claude Code's own fresh-session env scrub also drops
CLAUDECODEandCLAUDE_CODE_EXECPATH. The original PR added a separateclaude-session-envhelper and called it at 3 spawn sites. This version reuses the singleenvToDeleteseam that main added in #9961 instead. That avoids a parallel stripping path, keeps the explicit-value-wins behavior, and also covers persistent daemons and relays.Linked Issue
Fixes #9155
Visual Proof
N/A. This changes only the environment passed to spawned terminals, so there is nothing new on screen. The before/after evidence is the regression test:
main:strips inherited Claude child-session stamps from a local spawn envfails withAssertionError: expected '1' to be undefinedonenv.CLAUDECODE.Testing
Reproduced on
mainwith the extended regression test, which fails as shown above. Two extra probes also failed onmain: a local spawn that must remove the inherited values and keep an explicit paneCLAUDE_CODE_ENTRYPOINT, and a daemon-lane spawn whoseenvToDeletemust include the new keys.With the fix:
pty-spawn-env-terminal-basics,pty-daemon-spawn-agent-home-env,pty-daemon-spawn-wsl-runtimeandstructured-agent-launch-parityall pass (139/139).pty-spawn-env-terminal-basicsplussrc/main/ipc/pty/host-envpass (149/149).Agent Teams teammate commands set
env CLAUDECODE=1inline in the command, so stripping it from the base env does not affect them.Mixed-version remote: older daemons and relays apply
envToDeletegenerically, so they drop the new keys with no protocol change.Platform: macOS. The change is platform-neutral (env key list only). Windows key matching goes through the existing case-insensitive deletion path.
oxlint, oxfmt, the anti-slop, code-quality and ast-grep gates, and the changed-code quality gate are all clean on the touched files.
I manually tested these changes locally
Automated tests added/updated, or explained why not below
Agent skill upstream boundary
Notes
Original fix by @Baek-Seunghyun in #10188 (credited via
Co-authored-by). Original report in #9155.Out of scope follow-ups: Claude also stamps
CLAUDE_CODE_SESSION_ATTENDED,CLAUDE_PID,AI_AGENT,TRACEPARENTand others on its children. The structured-chat path (claude-child-process-environment.ts) also keeps its own 3-key list.Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)