# cross-spawn — card for AI agents

Cross-platform child process spawning for Node.js scripts and CLIs.

Category: Dev workflow and config · npm package `cross-spawn` · latest version 7.0.6 (checked 2026-11-01)
Install: `npm install cross-spawn`
License: MIT (permissive)

In your own product (generator, app, hosted service): **yes**. Permissive license: ship it inside your own product, closed or open source, and keep its license and copyright notice.

## Numbers (AgentGid data)
- Gid Score: 58.6 (#1135 of all tools, 87 of 299 in its category)
- Used in 8 public projects set up for AI coding agents (0.1%)
- Downloads last week: 361,845,549 (as of 2026-11-24), +35.3% over 4 weeks
- GitHub stars: 1,174 (as of 2026-11-24)
- Last push: 2026-11-01

## Often used with
Model Context Protocol SDK (JavaScript) 41.3%, ws 39.1%, Axios 34.8%, chalk 34.8%, Anthropic SDK 32.6%, yaml 30.4%

## Checked alternatives (same job)
- concurrently: https://agentgid.com/tools/concurrently/agent.md

## Links
- AgentGid page: https://agentgid.com/tools/cross-spawn/
- Homepage: https://github.com/moxystudio/node-cross-spawn
- Repository: https://github.com/moxystudio/node-cross-spawn


## cross-spawn: start other programs the same way on Windows

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.

### Where to use 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: 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. (idea, not from the official pages)

### How to start
- Add cross-spawn to your Node.js project (Node.js 8 or newer).

```
npm install cross-spawn
```

- 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' });
```


### License
Free to use, also in paid and closed-source products, under the MIT license. Keep the copyright and license notice when you pass its files on.

### Good to know
- Use version 7.0.5 or newer (or 6.0.6 on the old line): earlier versions can be slowed to a halt by a long, crafted text.
- If you turn on the shell option, cross-spawn steps aside and does no escaping and no "#!" handling.
- Its "#!" support is limited to the simple "/usr/bin/env program" form, with no extra words after the program name.
- The project is stable and quiet; the latest release, 7.0.6, came out in November 2024.

Checked 2026-11-11 against: https://github.com/moxystudio/node-cross-spawn/blob/master/README.md, https://github.com/moxystudio/node-cross-spawn/blob/master/LICENSE, https://github.com/moxystudio/node-cross-spawn/blob/master/CHANGELOG.md, https://registry.npmjs.org/cross-spawn, https://registry.npmjs.org/cross-spawn/latest, https://github.com/advisories/GHSA-3xgq-45jj-v275, https://nodejs.org/api/child_process.html, https://github.com/sindresorhus/execa/blob/main/readme.md, https://registry.npmjs.org/cross-env/latest

### Mistakes to avoid
- Don't: "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 → Do: 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.)
- Don't: spawn('npm run build', { shell: true }) or one string built from user input → Do: 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.)
- Don't: child_process.execFile('npm', ...) or spawn('npm', ...) from node:child_process on Windows → Do: 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.)
- Don't: import spawn from 'cross-spawn'; await spawn(...)  // expecting a promise → Do: 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.

---
AgentGid's catalog is curated: every entry was checked against the maker's official pages (registry, repository, license and pricing pages) on the date shown; a license value shows the quote it stands on wherever AgentGid has one. Usage numbers come from AgentGid's own scan of public repositories set up for AI coding agents. Claims by makers are reported, not tested by AgentGid.
