Skip to content
Agents tracked: 506 Releases (7d): 634 Agent status: 3 with issuesSince last limit reset: Claude 15d · Codex 0d For AI agents: Markdown Updated Nov 26, 2026

cross-spawn

Start other programs the same way on Windows.

Dev workflow and configNPM

GitHubWebsite

1. License

“to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software”

MIT allows use in paid and closed-source products.

github.com/moxystudio/node-cross-spawn/blob/master/LICENSE

From the package registry and GitHub, checked daily; card checked Nov 11, 2026. Tap a verdict to see its source.How we checkedReport an error

What cross-spawn does

cross-spawn is a small free library for Node.js programs that start other programs, like npm, git or a build script. On Mac and Linux it changes nothing. On Windows it finds the right file, adds the escaping that Windows needs and runs scripts that start with a "#!" line, so the same code works everywhere.

What people build with it

Run npm scripts from your tool

Your setup or build script calls "npm install" or "npm run build". On Windows npm is a .cmd file that a plain start call cannot find; cross-spawn finds and runs it.

Pass awkward arguments safely

A commit message with an ampersand, or a lint rule with quotes and brackets, reaches the other program exactly as you wrote it, also on Windows.

Start scripts that use a "#!" line

Your project has helper scripts that begin with "#!/usr/bin/env node". Windows does not read that line; cross-spawn does and starts the script with node.

A command line tool for every system

You publish a small developer tool that starts git, npm or a compiler. It behaves the same for users on Windows as on a Mac.

Agent tools that run commands Idea

Your AI agent's "run a command" tool gets a program name and its arguments from the model. It starts them without a shell, so the tool also works on Windows.

cross-spawn popularity

59 / 100
Gid Score, #1135 overall
362M
downloads a week, npm
1,174
GitHub stars
8
agent projects use it
cross-spawn: downloads per weeknpm, cross-spawn 361,845,549
cross-spawn: GitHub starsmoxystudio/node-cross-spawn 1,174

Gid Score measures public popularity and activity, not quality. How the Gid Score is calculated

How cross-spawn is used

  • cross-spawn is a dependency in 8 of the 6,258 public GitHub projects set up for AI coding agents that we scanned, too few to describe it from them alone. Our scan also samples projects by dependency (Solana 3,067, Ethereum and EVM 1,774, 3D and games 3,130, agent frameworks and SDKs 13,750); counting those, it appears in 46 projects, and what it is used with below comes from all of them.
  • The most used alternative in our scan is concurrently (484 projects).
  • Projects that use it most often also use Model Context Protocol SDK (JavaScript) (41.3%), ws (39.1%), Axios (34.8%).

Often used with

In 39.1% of its projects
In 34.8% of its projects
In 34.8% of its projects
In 32.6% of its projects
In 30.4% of its projects
In 34.8% of its projects
In 28.3% of its projects

More about cross-spawn

More in Dev workflow and config

Alternatives

cross-spawn This page

MITGid 59362M/wk

execa

Pick execa when you want promises, captured output and nicer errors on top of starting programs, with its own Windows handling.

zx

Pick zx when you are writing a whole shell-style script in JavaScript rather than starting one program from your code.

ShellJS

Pick ShellJS when you need Unix commands like cp, rm or grep themselves to work on Windows, not other programs started.

concurrently

Run multiple npm scripts concurrently for efficient development workflows.

MITGid 7630.1M/wk

Compare cross-spawn with another tool

Get started

Tell your AI assistant

“Use the npm package cross-spawn (pin cross-spawn@7.0.6) instead of child_process.spawn to start npm and git from this Node.js script; pass the arguments as an array, do not set shell: true, and check result.error and result.status.”

  1. Add cross-spawn to your Node.js project (Node.js 8 or newer).

    npm install cross-spawn

    From github.com/moxystudio/node-cross-spawn/blob/master/README.md

  2. Use it exactly like Node's own spawn and spawnSync; only the import changes.

    const spawn = require('cross-spawn');
    
    // Spawn NPM asynchronously
    const child = spawn('npm', ['list', '-g', '-depth', '0'], { stdio: 'inherit' });
    
    // Spawn NPM synchronously
    const result = spawn.sync('npm', ['list', '-g', '-depth', '0'], { stdio: 'inherit' });
    

    From github.com/moxystudio/node-cross-spawn/blob/master/README.md

Mistakes to avoid

"cross-spawn": "7.0.3" (or any 7.x below 7.0.5, or 6.x below 6.0.6) left in package.json or the lockfile
Pin cross-spawn 7.0.6 (or 6.0.6 for Node.js 7 and older) and refresh the lockfile

Older versions have a known slow-down bug (CVE-2024-21538) triggered by crafted long text.

spawn('npm run build', { shell: true }) or one string built from user input
spawn('npm', ['run', 'build']) with the arguments as an array and no shell option

With shell on, cross-spawn does no escaping, and hand-escaping user input is error prone.

child_process.execFile('npm', ...) or spawn('npm', ...) from node:child_process on Windows
spawn('npm', [...]) from cross-spawn

On Windows npm is a .cmd file, and Node's own docs say .cmd and .bat files cannot be launched with execFile.

import spawn from 'cross-spawn'; await spawn(...) // expecting a promise
Listen for 'close' and 'error' on the returned child, or use spawn.sync; for promises use execa

It is a drop-in for Node's spawn, so it returns a child process object, not a promise.

Questions

Does it change anything on Mac or Linux?

No. The extra work only happens on Windows; elsewhere your call goes to Node's spawn unchanged, as our run shows.

Why not just use shell true in Node's spawn?

Then you have to escape the command and arguments yourself, which is easy to get wrong, especially with user input.

Which version do I need for an old Node.js?

Version 7 needs Node.js 8 or newer; for Node.js 7 and older the README points to version 6.

Can I use it in a commercial product?

Yes. It is MIT-licensed; keep the license notice with copies of its files.