# chokidar — card for AI agents

Minimal, efficient cross-platform file watching library for build tools and dev servers.

Category: Dev workflow and config · npm package `chokidar` · latest version 6.0.0 (checked 2026-11-01)
Install: `npm install chokidar`
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: 74.4 (#221 of all tools, 17 of 299 in its category)
- Used in 107 public projects set up for AI coding agents (1.7%)
- Downloads last week: 292,666,295 (as of 2026-11-24), +33.9% over 4 weeks
- GitHub stars: 12,275 (as of 2026-11-24)
- Last push: 2026-11-06

## Often used with
tsx 60.7%, Zod 72.0%, Model Context Protocol SDK (JavaScript) 49.5%, chalk 49.5%, ws 49.5%, yaml 47.7%

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

## Links
- AgentGid page: https://agentgid.com/tools/chokidar/
- Homepage: https://github.com/paulmillr/chokidar
- Repository: https://github.com/paulmillr/chokidar


## chokidar: react when files change in Node.js

chokidar is a free library for Node.js programs that watches files and folders. It tells your program when a file is added, changed or removed, so a build can rerun or a page can reload the moment you save. It behaves the same on Windows, Mac and Linux.

### Where to use it
- Rebuild when source files change: Your build or dev script reruns as soon as you save a file in src, and skips hidden files and other files you do not care about.
- Process files dropped into a folder: Customers or a scanner drop files into an inbox folder; your app picks each one up only after it has finished copying.
- Watch a network or shared drive: Files live on a network share or an unusual drive where normal change alerts are unreliable; chokidar can check them on a timer instead.
- Survive editors that save in two steps: Some editors save by writing a temporary file and renaming it. chokidar reports this as one change instead of a delete and a new file.
- Keep an AI agent's file index fresh: Your coding agent keeps a search index of a project; when a file changes, only that file is read and indexed again. (idea, not from the official pages)
- Reload a docs preview on save: A small preview server for Markdown docs refreshes the browser page whenever a writer saves a page. (idea, not from the official pages)

### How to start
- Add chokidar to your Node.js project (version 6 needs Node.js 22.22 or newer).

```
npm install chokidar
```

- Watch a folder and print every event.

```
import chokidar from 'chokidar';
// or: import { watch } from 'chokidar';
// or: const chokidar = require('chokidar');

chokidar.watch('src').on('all', (event, path) => console.log(event, path));
```

- Close the watcher when you are done; to watch again, create a new one.

```
await watcher.close(); // async and terminal: create a new watcher to resume
```


### 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
- Version 6 needs Node.js 22.22 or newer, and since version 5 it ships only as an ES module.
- Patterns like "**/*.js" no longer work since version 4; you filter with a function or a regular expression instead.
- It watches everything under the folders you give it, so keep them narrow and leave out big folders like node_modules.
- On Linux a big project can hit the system limit on watched files; the README shows how to raise it or watch less.
- Version 6, released in October 2026, is a complete rewrite with a new watching method on Mac and Windows.

Checked 2026-11-11 against: https://github.com/paulmillr/chokidar/blob/main/README.md, https://github.com/paulmillr/chokidar/blob/main/LICENSE, https://registry.npmjs.org/chokidar, https://registry.npmjs.org/chokidar/latest

### Mistakes to avoid
- Don't: chokidar.watch('**/*.js') → Do: chokidar.watch('.', { ignored: (path, stats) => stats?.isFile() && !path.endsWith('.js') }) (Globs were removed in version 4; a pattern string is now treated as a plain path.)
- Don't: ignored: 'node_modules/**' → Do: ignored: /\/node_modules\// (A string in ignored is an exact path, not a pattern; regular expressions test the whole path.)
- Don't: chokidar.watch(dir, { usePolling: true, interval: 500 }) → Do: chokidar.watch(dir, { backend: 'polling', pollingInterval: 500 }) (The old option names are deprecated aliases in version 6.)
- Don't: await watcher.close(); watcher.add('src') → Do: Create a new watcher with chokidar.watch('src') after closing (close() is final; once closing has started, add() throws.)
- Don't: Installing chokidar 6 in a project that runs on Node.js 20 → Do: Upgrade to Node.js 22.22+, or pin chokidar@5 for Node.js 20 (Each major version raised the minimum Node.js version.)

### Questions
- Can I watch "src/**/*.ts" like in old examples? Not since version 4. Watch the folder and filter with a function, or expand the pattern yourself and pass the file list.
- Why do I get events for files that already exist when I start? The first scan reports every existing file as added. Set ignoreInitial to true to skip those events.
- My process never exits while watching. Is that a bug? No. A watcher keeps the process alive by default; set persistent to false or call close().
- Can I reuse a watcher after closing it? No. Closing is final; create a new watcher to start again.

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