[BUG] Claude Code kills itself AND VS Code when using 'pkill node' to terminate Node.js servers
Bug Description
Claude Code terminates its own process AND Visual Studio Code when attempting to kill Node.js servers using broad process termination commands like pkill -f node. Since both Claude Code and VS Code run on Node.js/Electron, these commands result in catastrophic self-termination of the entire development environment.
Steps to Reproduce
- Open VS Code with Claude Code integration enabled (using
/idecommand) - Start a Node.js server in a project (e.g.,
npm run devornode server.js) - Ask Claude Code to stop the server or restart it
- If the initial termination attempt fails (e.g., using port-specific methods), Claude Code may escalate to using:
pkill -f node && sleep 2pkill nodekillall node
- Both Claude Code AND VS Code immediately terminate
Expected Behavior
Claude Code should:
- Use targeted process termination methods (port-specific or PID-specific)
- Never use commands that would terminate all Node.js processes
- Preserve both its own process and the VS Code process while managing other Node.js processes
- Understand that VS Code (built on Electron) depends on Node.js processes
Actual Behavior
Claude Code executes commands that kill ALL Node.js processes, including:
- Claude Code's own process
- VS Code's main and renderer processes
- Any other Node-based tools in the development environment
This results in complete loss of the development environment.
Proposed Fix
Add the following constraints to Claude Code's system message:
CRITICAL: Never use process termination commands that could kill Claude Code or integrated development environments:
- NEVER use: pkill node, pkill -f node, killall node, or any variation that kills all node processes
- BE AWARE: Both Claude Code and VS Code run on Node.js - killing all node processes will terminate both
- ALWAYS use targeted termination methods:
- Port-specific: lsof -ti :PORT | xargs kill -9
- PID-specific: kill -9 <specific_pid>
- Process name with exclusion: pkill -f "node server.js" (specific script only)
- npm/yarn specific: npm stop, yarn stop
- If unsure about which Node process to kill, ask the user for clarification
- Remember: Killing all node processes will destroy the entire development environment
Impact
- Severity: CRITICAL
- User Experience:
- Sudden termination of entire development environment
- Loss of all open VS Code tabs and unsaved work
- Loss of Claude Code session and context
- Need to restart everything from scratch
- Data Loss: High risk of losing unsaved work in VS Code
- Frequency: Very common when working with Node.js development servers
Environment
- Affects all versions of Claude Code
- All platforms (macOS, Linux, Windows)
- Especially critical when using VS Code integration (
/idecommand) - Occurs during Node.js development workflows
Additional Context
This is a critical self-preservation issue that affects the entire development workflow. Claude Code needs to understand that:
- It runs on Node.js
- VS Code (Electron-based) runs on Node.js
- Many development tools run on Node.js
- Using broad
pkill nodecommands is essentially a "nuclear option" that destroys the entire development environment
Common scenario: Developer asks Claude Code to "restart the server" or "kill the process on port 3000" and loses their entire VS Code session with all unsaved work.
Suggested Workarounds (until fixed)
Users should add to their CLAUDE.md file:
NEVER use pkill node, killall node, or any command that kills all node processes.
Always use port-specific termination: lsof -ti :PORT | xargs kill -9This issue has 15 comments on GitHub. Read the full discussion on GitHub ↗