Commit 8e14cfa
fix(mode-switch): signal forwarding prevents orphaned processes (slopus#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>1 parent e2da751 commit 8e14cfa
3 files changed
Lines changed: 37 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
497 | 497 | | |
498 | 498 | | |
499 | 499 | | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
500 | 513 | | |
501 | 514 | | |
502 | 515 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
232 | 232 | | |
233 | 233 | | |
234 | 234 | | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
235 | 258 | | |
236 | 259 | | |
237 | 260 | | |
| |||
0 commit comments