# Fix VS Code File Watcher ENOSPC Limit Exceeded on Linux
On Linux, VS Code shows this error notification:
Visual Studio Code is unable to watch for file changes in this large workspace.Or in the developer tools console:
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:
cat /proc/sys/fs/inotify/max_user_watches
# Default: 8192Check current usage:
find /proc/*/fd -lname anon_inode:inotify 2>/dev/null | wc -lFixing the Limit Temporarily
sudo sysctl fs.inotify.max_user_watches=524288This 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:
echo "fs.inotify.max_user_watches=524288" | sudo tee -a /etc/sysctl.conf
sudo sysctl -pOr create a dedicated file:
echo "fs.inotify.max_user_watches=524288" | sudo tee /etc/sysctl.d/99-vscode.conf
sudo sysctl --systemAlternative: Reduce Watcher Usage
If you cannot increase the system limit (e.g., shared server), reduce the number of files VS Code watches:
{
"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:
# Approximate memory usage
echo $((524288 * 1024 / 1024 / 1024))GB
# 0.5GB of kernel memory for watcher structuresOn a system with 8GB+ RAM, this is negligible. On very low-memory systems (1-2GB), you may want a lower limit:
echo "fs.inotify.max_user_watches=262144" | sudo tee /etc/sysctl.d/99-vscode.confDocker 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:
[boot]
command = sysctl -w fs.inotify.max_user_watches=524288Verifying the Fix
After increasing the limit, reload VS Code:
Developer: Reload WindowThe ENOSPC error should no longer appear. Confirm by checking the Output panel:
View > Output > Select "Log (Window)" from dropdownIf the error is gone, file watching is working correctly.