Skip to content
This repository was archived by the owner on Feb 14, 2026. It is now read-only.

Comments

fix(sdk): strip CLAUDECODE env var when spawning Claude Code#169

Open
cruzanstx wants to merge 1 commit intoslopus:mainfrom
cruzanstx:fix/strip-claudecode-env
Open

fix(sdk): strip CLAUDECODE env var when spawning Claude Code#169
cruzanstx wants to merge 1 commit intoslopus:mainfrom
cruzanstx:fix/strip-claudecode-env

Conversation

@cruzanstx
Copy link

Summary

  • Claude Code 2.1+ sets a CLAUDECODE environment variable and blocks launch if it's already present (nested-session detection)
  • happy-cli passes process.env unchanged to the child Claude Code process, causing it to immediately exit with code 1
  • Every remote session crashes on first message and retries 3 times before giving up
  • Fix: strip CLAUDECODE from the child process environment before spawning

Root Cause

Claude Code 2.1.41 introduced nested-session detection that checks for the CLAUDECODE env var. Since happy-cli is itself launched by Claude Code (or inherits the env), the spawned child process sees this variable and refuses to start:

Error: Claude Code cannot be launched inside another Claude Code session.
Nested sessions share runtime resources and will crash all active sessions.
To bypass this check, unset the CLAUDECODE environment variable.

The getCleanEnv() path (used for command-only mode) already strips problematic env vars, but the normal spawn path passes process.env directly.

Changes

src/claude/sdk/query.ts: Always delete CLAUDECODE from the child process environment, regardless of spawn mode.

Test plan

  • Start daemon, send message from mobile app — session should start without crashing
  • Verify claude --version still works (command-only mode uses getCleanEnv())
  • Verify interactive mode still works

🤖 Generated with Claude Code

Claude Code 2.1+ sets a CLAUDECODE environment variable and refuses to
launch if it detects it already present, treating it as a nested session.
Since happy-cli legitimately spawns Claude Code as a child process (not a
nested session), the env var must be stripped before spawning.

Without this fix, every remote session immediately crashes with
"Claude Code process exited with code 1" and retries 3 times before
giving up.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant