fix: strip CLAUDECODE env var from spawned sessions to prevent crashes#683
Open
wisdommen wants to merge 1 commit intoslopus:mainfrom
Open
fix: strip CLAUDECODE env var from spawned sessions to prevent crashes#683wisdommen wants to merge 1 commit intoslopus:mainfrom
wisdommen wants to merge 1 commit intoslopus:mainfrom
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
CLAUDECODEandCLAUDE_CODE_ENTRYPOINTenvironment variables from all session spawn paths (SDK query, daemon regular spawn, daemon tmux spawn) to prevent Claude Code nested-session detection from crashing remote sessionsErrorobject serialization in the logger —JSON.stringify(new Error(...))produces{}, now useserr.stackorerr.messagefor meaningful log outputProblem
When
happy daemon startis run from within a Claude Code session (e.g., VS Code terminal), the daemon inheritsCLAUDECODE=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
packages/happy-cli/src/claude/sdk/utils.ts— DeleteCLAUDECODEandCLAUDE_CODE_ENTRYPOINTingetCleanEnv(), which is used when spawning Claude Code via the SDKpackages/happy-cli/src/daemon/run.ts— Delete these vars in both the regular process spawn path and the tmux spawn pathpackages/happy-cli/src/ui/logger.ts— HandleErrorinstances inlogToFile()by usingerr.stack || err.messageinstead ofJSON.stringify(err)Test plan
{}Fixes #682
🤖 Generated with Claude Code