Skip to content

Comments

fix: sanitize CLAUDECODE env var in daemon-spawned sessions#736

Open
pemagic wants to merge 1 commit intoslopus:mainfrom
pemagic:fix/sanitize-claudecode-env
Open

fix: sanitize CLAUDECODE env var in daemon-spawned sessions#736
pemagic wants to merge 1 commit intoslopus:mainfrom
pemagic:fix/sanitize-claudecode-env

Conversation

@pemagic
Copy link

@pemagic pemagic commented Feb 23, 2026

Summary

  • Remove inherited CLAUDECODE=1 env var before spawning Claude CLI in all spawn paths, preventing "Process exited unexpectedly" when daemon is started from a Claude Code terminal
  • Fix error logging that serialized Error objects as {} (non-enumerable properties), making debugging impossible

Root Cause

When the Happy daemon is started from within a Claude Code terminal, it inherits CLAUDECODE=1. Claude CLI detects this and refuses to start, thinking it's a nested session. The daemon didn't sanitize this variable before spawning child processes.

The error was invisible in logs because JSON.stringify(new Error("msg")) returns {}.

Changes

CLAUDECODE removal (5 locations):

  • scripts/claude_remote_launcher.cjs
  • scripts/claude_local_launcher.cjs
  • src/claude/sdk/query.ts
  • src/claude/claudeLocal.ts
  • src/daemon/run.ts

Error logging fix (2 locations):

  • src/claude/claudeRemoteLauncher.ts — extract e.message + e.stack
  • src/claude/sdk/metadataExtractor.ts — extract error.message

Test plan

  • Start Happy daemon from within a Claude Code terminal session
  • Create a new conversation from mobile app
  • Verify session starts successfully instead of "Process exited unexpectedly"

Fixes #735

🤖 Generated with Claude Code

When the daemon is started from within a Claude Code terminal, it inherits
the CLAUDECODE=1 environment variable. This causes all daemon-spawned
child sessions to fail because Claude CLI detects it and refuses to start,
thinking it's a nested session.

Remove CLAUDECODE from the environment in all spawn paths:
- scripts/claude_remote_launcher.cjs
- scripts/claude_local_launcher.cjs
- src/claude/sdk/query.ts (SDK spawn)
- src/claude/claudeLocal.ts (local mode spawn)
- src/daemon/run.ts (daemon child spawn)

Also fix error logging in claudeRemoteLauncher.ts and metadataExtractor.ts
where Error objects were logged as {} due to JSON.stringify not serializing
non-enumerable Error properties.

Fixes slopus#735

Generated with [Claude Code](https://claude.ai/code)
via [Happy](https://happy.engineering)

Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Happy <yesreply@happy.engineering>
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.

Bug: Daemon-spawned sessions fail when daemon started from Claude Code terminal

1 participant