Skip to content

Comments

fix: strip CLAUDECODE env var from spawned sessions to prevent crashes#683

Open
wisdommen wants to merge 1 commit intoslopus:mainfrom
wisdommen:fix/clean-claudecode-env-from-spawned-sessions
Open

fix: strip CLAUDECODE env var from spawned sessions to prevent crashes#683
wisdommen wants to merge 1 commit intoslopus:mainfrom
wisdommen:fix/clean-claudecode-env-from-spawned-sessions

Conversation

@wisdommen
Copy link

@wisdommen wisdommen commented Feb 21, 2026

Summary

  • Strip CLAUDECODE and CLAUDE_CODE_ENTRYPOINT environment variables from all session spawn paths (SDK query, daemon regular spawn, daemon tmux spawn) to prevent Claude Code nested-session detection from crashing remote sessions
  • Fix Error object serialization in the logger — JSON.stringify(new Error(...)) produces {}, now uses err.stack or err.message for meaningful log output

Problem

When happy daemon start is run from within a Claude Code session (e.g., VS Code terminal), the daemon inherits CLAUDECODE=1. This propagates to all spawned session processes. Claude Code detects this and refuses to start with "cannot be launched inside another Claude Code session", causing every mobile/remote session to immediately crash with "Process exited unexpectedly".

The error was nearly impossible to debug because JSON.stringify(new Error("...")) produces {} (Error objects have no enumerable properties), so logs only showed [remote]: launch error {}.

Changes

  1. packages/happy-cli/src/claude/sdk/utils.ts — Delete CLAUDECODE and CLAUDE_CODE_ENTRYPOINT in getCleanEnv(), which is used when spawning Claude Code via the SDK
  2. packages/happy-cli/src/daemon/run.ts — Delete these vars in both the regular process spawn path and the tmux spawn path
  3. packages/happy-cli/src/ui/logger.ts — Handle Error instances in logToFile() by using err.stack || err.message instead of JSON.stringify(err)

Test plan

  • Start daemon from within a Claude Code session (e.g., VS Code terminal) and verify remote sessions launch successfully from the mobile app
  • Start daemon from a clean shell and verify existing behavior is unchanged
  • Trigger a session spawn error and verify the log output now shows the actual error message/stack instead of {}

Fixes #682

🤖 Generated with Claude Code

When the daemon is started from within a Claude Code session, the
CLAUDECODE=1 environment variable leaks into all child processes.
Claude Code detects this and refuses to start ("cannot be launched
inside another Claude Code session"), causing every remote session
to immediately crash with "Process exited unexpectedly".

Strip CLAUDECODE and CLAUDE_CODE_ENTRYPOINT from the environment in
three places: getCleanEnv() (SDK query spawning), daemon regular
process spawning, and daemon tmux spawning.

Also fix Error object serialization in the logger — JSON.stringify()
on Error produces "{}" since Error has no enumerable properties.
Use err.stack or err.message instead for meaningful log output.

Fixes slopus#682

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.

Daemon inherits CLAUDECODE env var, causing all remote sessions to crash

1 participant