Skip to content

Competing processes when switching to local mode #124

@fberlakovich

Description

@fberlakovich

When switching from local mode to remote mode (or vice versa), the terminal flickers between two states and. Keystrokes are sometimes captured by one mode, sometimes by the other, making the session unusable.

Environment

  • happy-coder: 0.13.0
  • Claude Code: 2.1.1 (installed via homebrew)
  • Node.js: v24.12.0
  • macOS: 15.1 (Darwin 25.1.0)
  • Terminal: iTerm2

I am not sure whether maybe I am just holding it wrong.
It seems that two processes are competing for the input/output.
Either way, the following local fix seems to solve the issue

  diff --git a/scripts/claude_version_utils.cjs b/scripts/claude_version_utils.cjs
  index 2184917..1a6b638 100644
  --- a/scripts/claude_version_utils.cjs
  +++ b/scripts/claude_version_utils.cjs
  @@ -497,6 +497,18 @@ function runClaudeCli(cliPath) {
               stdio: 'inherit',
               env: process.env
           });
  +
  +        // Forward signals to child process so it gets killed when parent is killed
  +        // This prevents orphaned Claude processes when switching between local/remote modes
  +        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'));
  +
           child.on('exit', (code) => {
               process.exit(code || 0);
           });

In case it is not just a me-problem I am happy to create a PR.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions