# Fix VS Code File Watcher ENOSPC Limit Exceeded on Linux

On Linux, VS Code shows this error notification:

bash
Visual Studio Code is unable to watch for file changes in this large workspace.

Or in the developer tools console:

bash
Error: ENOSPC: System limit for number of file watchers reached, watch '/home/user/project/node_modules'

This means the Linux kernel's inotify file watcher limit is too low for your project size.

Understanding the inotify Limit

Linux uses inotify to monitor file system changes. VS Code relies on inotify to detect file changes and trigger auto-reload, auto-save, and IntelliSense updates. The default limit is typically 8192 watchers, which is insufficient for projects with node_modules (which can contain 100,000+ files).

Check the current limit:

bash
cat /proc/sys/fs/inotify/max_user_watches
# Default: 8192

Check current usage:

bash
find /proc/*/fd -lname anon_inode:inotify 2>/dev/null | wc -l

Fixing the Limit Temporarily

bash
sudo sysctl fs.inotify.max_user_watches=524288

This takes effect immediately without restarting VS Code. The value 524288 (512K) is sufficient for most development workflows.

Making the Fix Permanent

Add the setting to /etc/sysctl.conf:

bash
echo "fs.inotify.max_user_watches=524288" | sudo tee -a /etc/sysctl.conf
sudo sysctl -p

Or create a dedicated file:

bash
echo "fs.inotify.max_user_watches=524288" | sudo tee /etc/sysctl.d/99-vscode.conf
sudo sysctl --system

Alternative: Reduce Watcher Usage

If you cannot increase the system limit (e.g., shared server), reduce the number of files VS Code watches:

json
{
    "files.watcherExclude": {
        "**/.git/objects/**": true,
        "**/.git/subtree-cache/**": true,
        "**/node_modules/**": true,
        "**/dist/**": true,
        "**/build/**": true,
        "**/.next/**": true,
        "**/__pycache__/**": true
    },
    "files.exclude": {
        "**/.git": true,
        "**/node_modules": true,
        "**/__pycache__": true
    }
}

Excluding node_modules from watching is the single most effective change. A typical node_modules directory contains 50,000-200,000 files, consuming the majority of watchers.

Impact of Excluding node_modules

When node_modules is excluded from watching: - New packages installed via npm install will not trigger VS Code to notice the change - You may need to reload the window after installing new packages - IntelliSense for newly installed packages may require a manual refresh

This is a minor inconvenience compared to the ENOSPC error. Most developers accept this trade-off.

Checking Memory Usage of Watchers

Each inotify watcher consumes approximately 1KB of kernel memory. With 524288 watchers:

bash
# Approximate memory usage
echo $((524288 * 1024 / 1024 / 1024))GB
# 0.5GB of kernel memory for watcher structures

On a system with 8GB+ RAM, this is negligible. On very low-memory systems (1-2GB), you may want a lower limit:

bash
echo "fs.inotify.max_user_watches=262144" | sudo tee /etc/sysctl.d/99-vscode.conf

Docker and WSL2 Considerations

Docker

When running VS Code inside a Docker container, the inotify limit is set by the host system. The container inherits the host's max_user_watches value. Increase it on the host, not the container.

WSL2

On Windows Subsystem for Linux (WSL2), the inotify limit may be different from the Windows host:

```bash # Check WSL2 limit cat /proc/sys/fs/inotify/max_user_watches

# Increase in WSL2 sudo sysctl fs.inotify.max_user_watches=524288 ```

To make it persistent across WSL2 restarts, add to /etc/wsl.conf:

bash
[boot]
command = sysctl -w fs.inotify.max_user_watches=524288

Verifying the Fix

After increasing the limit, reload VS Code:

bash
Developer: Reload Window

The ENOSPC error should no longer appear. Confirm by checking the Output panel:

bash
View > Output > Select "Log (Window)" from dropdown

If the error is gone, file watching is working correctly.