Claude Code doesn't detect when `npm run start:dev` finishes and hangs indefinitely
Bug Description
When running npm run start:dev in Claude Code, the CLI doesn't detect that the process has finished executing and hangs indefinitely. This prevents Claude Code from proceeding with subsequent commands or providing feedback to the user that the script has completed.
Expected Behavior
Claude Code should detect when npm scripts complete execution and return control to the user, allowing for subsequent commands to be run.
Actual Behavior
After running npm run start:dev, Claude Code appears to hang indefinitely, not recognizing that the npm script has finished. The user has to manually interrupt (Ctrl+C) to regain control.
Possible Causes
- Process detection issue: Claude Code may not be properly detecting when child processes spawned by npm scripts terminate
- Output stream handling: The script might be keeping stdout/stderr streams open even after completion
- Signal handling: The process completion signal might not be properly propagated to Claude Code
Suggested Solutions
- Implement proper process exit detection for npm scripts, including checking for:
- Process exit codes
- Closed stdout/stderr streams
- Child process termination signals
- Add a timeout mechanism specifically for development server scripts that typically run indefinitely (like
start:dev)
- Provide clear visual feedback when a long-running process is detected, with options to:
- Continue running in background
- Terminate the process
- Detach from the process
Workaround
Currently, users must manually interrupt the hanging process with Ctrl+C to regain control of Claude Code.
Related Issues
This appears to be a new issue not covered by existing hanging/freeze issues (#3723, #3775, #3790, etc.) which seem to focus on general command execution problems rather than npm script completion detection.
This issue has 5 comments on GitHub. Read the full discussion on GitHub ↗