Skip to content

[BUG] npx keeps an idle npm process alive for the whole lifetime of the command it runs #10165

Open

Description

@Finomosec

Is there an existing issue for this?

  • I have searched the existing issues

This issue exists in the latest npm version

  • I am using the latest npm

This is not just a request to bump a dependency for a CVE

  • This is not solely a request to bump a dependency for a CVE

Current Behavior

npx <pkg> (and npm exec -- <pkg>) starts the package's bin as a child process and then stays alive for as long as that child runs.
While the command runs, the process tree looks like this:

npm exec <pkg>        <- full Node.js process with npm loaded, only waiting
└─ sh -c '<pkg>'      <- shell, only waiting
   └─ <pkg>           <- the actual program

The npm exec process does no work after the child has started, but it keeps a complete Node.js runtime with npm loaded in memory.
For short commands this does not matter.
It does matter for long-running commands, which is how npx is now used most of the time: MCP servers, language servers, dev servers and watchers are typically configured as npx -y <pkg>.
Each of them is started once per editor window or AI agent session, so a single machine easily ends up with dozens of these idle npm processes at once.
Together they hold a lot of memory that does nothing, and the amount grows with every additional session.

Expected Behavior

Once npm has resolved and installed the package, it should get out of the way instead of waiting as a parent process.
On POSIX systems npm could replace itself with the command via process.execve(), which is available in every Node.js version npm supports.
The program would then keep npm's PID, and no idle npm process would stay behind.

Steps To Reproduce

  1. Run any long-running package bin through npx, for example a stdio MCP server: npx -y <package>.
  2. In a second terminal, inspect the process tree: ps -eo pid,ppid,rss,args --forest.
  3. An npm exec <package> Node.js process stays resident as the grandparent of the program for as long as the program runs.
  4. Start several of them and add up the memory of the npm exec processes.

Environment

  • npm: 12.2.1
  • Node.js: 22.23.4, 24.22.1, 26.12.0
  • OS Name: Linux
  • System Model Name: x86_64 desktop
  • npm config:
; defaults

Activity

  1. added
    cmd:exec
    DCR
    on Nov 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    DCRPriority 3cmd:exec

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions