Skip to content

Conversation

@fberlakovich
Copy link

@fberlakovich fberlakovich commented Jan 13, 2026

Cleans up remote process when switching back to local mode, avoiding two processes competing for the input/output. Fixes slopus/happy#430

@fberlakovich fberlakovich changed the title fix: forward signals to child process in binary launcher #124 fix: forward signals to child process in binary launcher Jan 13, 2026
@materemias
Copy link

I think the same fix needs to be applied to claudeLocal.ts process#168

@fberlakovich
Copy link
Author

I think the same fix needs to be applied to claudeLocal.ts process#168

You are right, that probably explains why a claude instance kept running in the background and doing weird things even after I exited happy-cli.

@sferich888
Copy link

I have applied this patch/fix in my environment and can confirm that it improve / resolves the bugs that I was seeing.

michelhelsdingen added a commit to michelhelsdingen/happy-cli that referenced this pull request Feb 6, 2026
…us#11)

## THE FIX
Forward SIGTERM, SIGINT, SIGHUP to child Claude CLI process.
This ensures child processes are killed when parent is terminated.

## ROOT CAUSE
When switching between local/remote modes, the parent process was killed
but child Claude CLI processes remained alive ("orphaned"). These orphaned
processes continued to hold stdin, causing:
- Duplicate/garbled characters when typing
- "Competing processes" fighting for terminal input

## SOLUTION (from GitHub slopus/happy#430)
```javascript
const forwardSignal = (signal) => {
    if (child.pid && !child.killed) {
        child.kill(signal);
    }
};
process.on('SIGTERM', () => forwardSignal('SIGTERM'));
process.on('SIGINT', () => forwardSignal('SIGINT'));
process.on('SIGHUP', () => forwardSignal('SIGHUP'));
```

## FILES CHANGED
- scripts/claude_version_utils.cjs - binary launcher signal forwarding
- src/claude/claudeLocal.ts - TypeScript launcher signal forwarding

## TESTED
✅ Fresh local mode - typing works
✅ Switch to remote mode - typing works
✅ Switch back to local mode - typing works (was broken)
✅ Multiple mode switches - stable

## IMPORTANT
This is the ONLY fix needed. No stdin cleanup, no removeAllListeners(),
no setRawMode changes required. Signal forwarding alone solves it.

Closes slopus#11
References: slopus/happy#430, PR slopus#127

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.

Competing processes when switching to local mode

3 participants