# rimraf — card for AI agents

Cross-platform delete directories and files recursively like Unix rm -rf command.

Category: Dev workflow and config · npm package `rimraf` · latest version 6.1.3 (checked 2026-11-01)
Install: `npm install rimraf`
License: BlueOak-1.0.0 (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: 73.6 (#248 of all tools, 21 of 299 in its category)
- Used in 161 public projects set up for AI coding agents (2.6%)
- Downloads last week: 216,195,801 (as of 2026-11-24), +34.6% over 4 weeks
- GitHub stars: 5,859 (as of 2026-11-24)
- Last push: 2026-11-03

## Often used with
TypeScript 88.2%, ESLint 66.5%, Prettier 49.7%, Husky 32.9%, lint-staged 28.0%, Vitest 42.2%

## Links
- AgentGid page: https://agentgid.com/tools/rimraf/
- Homepage: https://github.com/isaacs/rimraf#readme
- Repository: https://github.com/isaacs/rimraf


## rimraf: delete folders the same way on every system

rimraf is a small free JavaScript package that deletes files and whole folders, like the rm -rf command, and works the same on Windows, Mac and Linux. Projects use it to wipe build output or caches before a fresh build. What it deletes is gone for good; it does not use the trash.

### Where to use it
- Wipe the build folder first: Before each build, old files in dist are removed so nothing stale gets shipped. One line in the scripts section of package.json does it. (idea, not from the official pages)
- Same delete command on every computer: Teammates on Windows and on Mac run the same clean script; rm -rf alone would fail on a plain Windows shell.
- Delete files by pattern: Remove every .log or .map file under a folder in one call instead of listing each one.
- Clear a cache but keep a marker file: Empty a cache folder while keeping the .gitkeep file that keeps the folder in git.
- Stop a huge delete on time: A cleanup job deletes a very large folder but must give up after a set time instead of blocking everything.
- Remove test leftovers: After a test run, delete the temporary folders the tests created so the next run starts clean. (idea, not from the official pages)

### How to start
- Add it to the project.

```
npm install rimraf
```

- Import the function by name and await it with a path or a list of paths.

```
import { rimraf, rimrafSync, native, nativeSync } from 'rimraf'
```

- Or call the command in a package.json script.

```
rimraf <path> [<path> ...]
```


### License
Free to use in paid and closed products under the Blue Oak Model License 1.0.0. Anyone who gets a copy of rimraf from you must also get the license text or a link to it.

### Good to know
- Never give it a path typed by a user or taken from a request. A wrong path can wipe important folders.
- Version 6 needs Node.js 20 or 22 and newer.
- Versions before 4 are marked unsupported, and some early 4.x versions had a symbolic link problem; use 6.x.
- Patterns like *.log only work when you turn glob on; by default the text is taken as a plain path.
- The project is maintained; version 6.1.4 came out on 3 November 2026.

Checked 2026-11-11 against: https://github.com/isaacs/rimraf/blob/main/README.md, https://github.com/isaacs/rimraf/blob/main/LICENSE.md, https://registry.npmjs.org/rimraf, https://registry.npmjs.org/rimraf/6.1.4

### Mistakes to avoid
- Don't: import rimraf from 'rimraf'  or  const rimraf = require('rimraf') → Do: import { rimraf } from 'rimraf'  or  const { rimraf } = require('rimraf') (Since version 5 there is no default export; code from old tutorials fails with 'not a function'.)
- Don't: rimraf('dist', (err) => { ... }) → Do: await rimraf('dist') (Since version 4 the function returns a Promise and takes no callback.)
- Don't: rimraf('dist/**/*.map')  expecting a pattern match → Do: rimraf('dist/**/*.map', { glob: true })  or  rimraf --glob 'dist/**/*.map' (Without the glob option the string is treated as one literal path.)
- Don't: await rimraf(req.body.folder) → Do: Build the path yourself from a fixed base folder and an id you checked; never pass raw user input (The README says reports that rely on untrusted input will be rejected; the risk is on you.)
- Don't: "rimraf": "^3.0.2" in package.json → Do: "rimraf": "^6.1.4" (Node 20 or 22+), or 5.x for older Node (npm marks every version before 4 as no longer supported.)

### Questions
- Does it put files in the trash? No. It deletes them for good; its purpose is permanent removal.
- Why does rimraf('*.log') not delete my log files? Patterns are off by default. Pass { glob: true } in code or --glob on the command line.
- What does it return? true when everything was removed; false only when a filter kept something. A missing path also gave true in our run.
- Is the sync version faster? Usually not. The README says the synchronous form is typically much slower than the async one.
- Can it delete the root folder by mistake? Not by default: removing / is refused unless you pass --no-preserve-root or preserveRoot: false.

---
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.
