Skip to content

fix(terminal): strip inherited CLAUDECODE, CLAUDE_CODE_EXECPATH and CLAUDE_CODE_ENTRYPOINT from spawned PTY env - #10188

Merged
nwparker merged 1 commit into
stablyai:mainfrom
Baek-Seunghyun:fix/claude-session-marker-env-leak
Oct 26, 2026
Merged

nwparker merged 1 commit into
stablyai:mainfrom
Baek-Seunghyun:fix/claude-session-marker-env-leak

Conversation

@Baek-Seunghyun

@Baek-Seunghyun Baek-Seunghyun commented Jul 23, 2026 •

Copy link
Copy Markdown
Contributor

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_ID and CLAUDE_CODE_BRIDGE_SESSION_ID stamps. CLAUDECODE, CLAUDE_CODE_EXECPATH and CLAUDE_CODE_ENTRYPOINT still 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 to CLAUDE_CHILD_SESSION_STAMP_ENV_KEYS. This list already goes through getInheritedAgentSessionStampEnvKeysToDelete -> assemblePtySpawnEnvDeletions and is sent as envToDelete to every provider. A key that the pane's own env sets explicitly is still kept (the existing env[key] === undefined filter).
  • src/main/ipc/pty/pty-spawn-env-terminal-basics.test.ts: added the three keys to the existing regression test.

Why

  • CLAUDECODE turns 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.
  • An inherited CLAUDE_CODE_ENTRYPOINT (for example sdk-ts or claude-desktop) stops Claude from detecting its own entrypoint, so the pane's Claude reports the wrong identity.
  • CLAUDE_CODE_EXECPATH is a stale path to the executable of the session that launched Orca.

Claude Code's own fresh-session env scrub also drops CLAUDECODE and CLAUDE_CODE_EXECPATH. The original PR added a separate claude-session-env helper and called it at 3 spawn sites. This version reuses the single envToDelete seam 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:

  • On main: strips inherited Claude child-session stamps from a local spawn env fails with AssertionError: expected '1' to be undefined on env.CLAUDECODE.
  • With this change: it passes.

Testing

  • Reproduced on main with the extended regression test, which fails as shown above. Two extra probes also failed on main: a local spawn that must remove the inherited values and keep an explicit pane CLAUDE_CODE_ENTRYPOINT, and a daemon-lane spawn whose envToDelete must include the new keys.

  • With the fix: pty-spawn-env-terminal-basics, pty-daemon-spawn-agent-home-env, pty-daemon-spawn-wsl-runtime and structured-agent-launch-parity all pass (139/139). pty-spawn-env-terminal-basics plus src/main/ipc/pty/host-env pass (149/149).

  • Agent Teams teammate commands set env CLAUDECODE=1 inline in the command, so stripping it from the base env does not affect them.

  • Mixed-version remote: older daemons and relays apply envToDelete generically, 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

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

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, TRACEPARENT and others on its children. The structured-chat path (claude-child-process-environment.ts) also keeps its own 3-key list.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

@coderabbitai

coderabbitai Bot commented Jul 23, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

Added stripInheritedClaudeSessionEnv to remove inherited Claude session marker variables without mutating the source environment. Applied the helper to daemon PTY subprocesses, local PTY provider spawns, and relay PTY spawns before merging explicit environment values. Added tests verifying inherited markers are removed, explicitly supplied values are preserved, unrelated variables remain available, and inputs are not mutated.

Pre-merge checks: Passed 5
Check name Status Explanation
Docstring Coverage Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Title check Passed The title clearly identifies the primary change: removing inherited Claude Code environment markers from spawned PTY environments.
Description check Passed The description covers the required change, rationale, linked issue, testing, visual proof, platform considerations, and checklist. The missing Review heading and unchecked build item are non-critical…
Full details: Description check

Explanation

The description covers the required change, rationale, linked issue, testing, visual proof, platform considerations, and checklist. The missing Review heading and unchecked build item are non-critical because the description remains complete and states that the build was not run locally.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.ts
  • src/main/daemon/pty-subprocess.ts
  • src/main/providers/local-pty-provider.test.ts
  • src/main/providers/local-pty-provider.ts
  • src/main/pty/claude-session-env.test.ts
  • src/main/pty/claude-session-env.ts
  • src/relay/pty-handler.test.ts
  • src/relay/pty-handler.ts

Comment thread src/relay/pty-handler.ts Resolved
…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]>
@nwparker
nwparker force-pushed the fix/claude-session-marker-env-leak branch from 8821313 to 5f010a8 Compare October 26, 2026 18:11
@nwparker nwparker changed the title fix(terminal): strip inherited Claude Code session markers from spawned PTY env fix(terminal): strip inherited CLAUDECODE, CLAUDE_CODE_EXECPATH and CLAUDE_CODE_ENTRYPOINT from spawned PTY env Oct 26, 2026
@nwparker
nwparker merged commit f05da69 into stablyai:main Oct 26, 2026
33 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: CLAUDE_CODE_CHILD_SESSION stamp variants still leak into transcripts (residual after #9961)

3 participants