FileWatcher: Dynamic Discovery of Skills and Photons
Overview
The FileWatcher enables automatic discovery and indexing of skills and photons without requiring NCP to restart. When you add, modify, or delete skill/photon files, NCP immediately detects and makes them available.
This replaces the old workflow where you had to restart NCP to use newly added skills and photons.
How It Works
File Monitoring: FileWatcher continuously monitors:
~/.ncp/skills/directory for skill changes~/.ncp/photons/directory for photon changes (if Photon runtime is enabled)
Event Detection: When files are added, modified, or deleted:
- Event is debounced to prevent duplicate processing
- Temporary/system files are automatically filtered out
- Orchestrator is notified via callbacks
Index Update: Skills/photons are:
- Loaded and parsed
- Added to discovery index
- Made available to Claude immediately
- Execution time tracked and logged
Configuration
Environment Variables
NCP_ENABLE_SKILLS (default: true)
Enables skill discovery. Set to false to disable skills:
export NCP_ENABLE_SKILLS=falseNCP_ENABLE_PHOTON_RUNTIME (default: true)
Enables photon runtime. Set to false if you need to temporarily disable photons:
export NCP_ENABLE_PHOTON_RUNTIME=false- CLI / npm installs: Update
~/.ncp/settings.json(enablePhotonRuntime) to make the change stick across shells. - DXT / client bundles: These builds ignore
~/.ncp/settings.json, so specify the env var in your client config ("NCP_ENABLE_PHOTON_RUNTIME": "true").
Note: FileWatcher only starts if at least one of these is enabled.
NCP_FILE_WATCHER_DEBOUNCE_MS (default: 300)
Debounce interval in milliseconds. Prevents rapid file changes from triggering multiple updates:
export NCP_FILE_WATCHER_DEBOUNCE_MS=500 # 500ms debounce- Lower values (100-200ms): More responsive, but higher CPU usage
- Higher values (500-1000ms): Less responsive, but more stable with slow editors
- Default (300ms): Good balance for most use cases
Usage Examples
Adding a New Skill
- Create skill directory and file:
mkdir -p ~/.ncp/skills/my-skill
echo "# My Skill" > ~/.ncp/skills/my-skill/SKILL.md- NCP automatically detects it:
⭐ Skill added (auto-detected): my-skill
✅ Skill indexed: my-skill (125ms)- Skill is immediately available to Claude without restart
Modifying an Existing Skill
- Edit the SKILL.md file:
nano ~/.ncp/skills/my-skill/SKILL.md- NCP automatically detects the change:
🔄 Skill modified (auto-detected): my-skill
✅ Skill updated: my-skill (142ms)- Updated version available immediately
Removing a Skill
- Delete the skill directory:
rm -rf ~/.ncp/skills/my-skill- NCP automatically detects removal:
🗑️ Skill removed (auto-detected): my-skill
✅ Skill unindexed: my-skill- Skill no longer available to Claude
File Filtering
FileWatcher automatically ignores:
- Editor backups:
~,.swp,.swo,.bak - Temp files:
.tmp,.orig - macOS:
._*,.DS_Store - Windows:
Thumbs.db - Office:
~123(Word/Excel backups)
These are silently ignored and don't trigger updates.
Logging
Log Levels
Enable detailed logging to debug FileWatcher:
export NCP_DEBUG=trueLog Messages
Different emoji indicators show operation type:
- ⭐: File added (new detection)
- 🔄: File modified (update detection)
- 🗑️: File deleted (removal detection)
- ✅: Operation succeeded
- ❌: Operation failed
- 📁: FileWatcher startup/shutdown
Example Log Output
📁 File watcher started for skills and photons directories (debounce: 300ms)
⭐ Skill added (auto-detected): my-skill
✅ Skill indexed: my-skill (125ms)
🔄 Skill modified (auto-detected): my-skill
✅ Skill updated: my-skill (142ms)
🗑️ Skill removed (auto-detected): my-skill
✅ Skill unindexed: my-skillTroubleshooting
FileWatcher Not Detecting Changes
Symptom: Files added but not appearing in NCP
Causes & Solutions:
Skills are disabled:
bash# Check if enabled (should be 'true') echo $NCP_ENABLE_SKILLS # Enable if disabled export NCP_ENABLE_SKILLS=truePhoton runtime disabled (for photons):
bash# Enable photon runtime export NCP_ENABLE_PHOTON_RUNTIME=trueFile in wrong location:
- Skills must be in
~/.ncp/skills/ - Photons must be in
~/.ncp/photons/ - Use full paths:
~expands to your home directory
- Skills must be in
File not matching expected format:
- Skills: Directory with
SKILL.mdfile - Photons: Files ending in
.photon.tsor.photon.js
- Skills: Directory with
Editor hasn't saved file:
- FileWatcher only detects saved changes
- Ensure file is fully saved before checking logs
Updates Taking Too Long
Symptom: Skill/photon updates are slow (>1-2 seconds)
Possible Causes:
Debounce interval too high:
bash# Reduce debounce (but watch for duplicates) export NCP_FILE_WATCHER_DEBOUNCE_MS=200Slow filesystem:
- Updates are slower on network shares or cloud storage
- Consider using local filesystem for
.ncp/directory
Large skill/photon files:
- Parsing large files takes time
- Consider splitting into smaller files
FileWatcher Not Starting
Symptom: No "File watcher started" message in logs
Possible Causes:
Both features disabled:
bash# At least one must be enabled export NCP_ENABLE_SKILLS=trueNCP not initialized yet:
- FileWatcher starts during background initialization
- Wait for "MCP server ready" message
File system permissions:
bash# Check directory is readable ls -la ~/.ncp/skills/ ls -la ~/.ncp/photons/
Duplicate Updates
Symptom: Same skill updated multiple times for single change
Cause: Debounce interval too low, editor creates multiple save events
Solution:
# Increase debounce to reduce duplicates
export NCP_FILE_WATCHER_DEBOUNCE_MS=500Performance Considerations
Memory Usage
FileWatcher uses minimal memory:
- Per-file debounce timers: ~1KB each
- Watcher instances: ~2MB total
- No significant impact on NCP's memory footprint
CPU Usage
FileWatcher has minimal CPU impact:
- Idle state: <0.1% CPU
- Processing updates: <1% CPU per update
- Debounce prevents rapid processing
Filesystem Impact
FileWatcher uses OS-level file monitoring:
- macOS: Uses
FSEvents(efficient) - Linux: Uses
inotify(efficient) - Windows: Uses file system watcher API (efficient)
No polling or scanning required.
Best Practices
1. Use Local Filesystem
Avoid:
- Network shares (NFS, SMB)
- Cloud-synced folders (Dropbox, OneDrive, iCloud)
- Virtual filesystems
These can have delayed file change detection.
2. One SKILL.md Per Directory
✅ Good:
~/.ncp/skills/
└─ my-skill/
└─ SKILL.md❌ Bad:
~/.ncp/skills/
└─ SKILL.md (ambiguous - what's the skill name?)3. Use Consistent File Extensions
✅ Good:
my-photon.photon.ts
my-photon.photon.js❌ Bad:
my-photon.ts (missing .photon marker)4. Let Editor Fully Save
Always ensure files are fully saved:
- VSCode: Wait for white dot to disappear from tab
- Vim: Confirm
:wcommand completes - Don't force-save in middle of write
5. Check Logs When Adding Skills
Always verify the skill was detected:
# Look for success message
tail -50 ~/.ncp/logs/ncp.log | grep -i "skill.*indexed"Advanced Configuration
Custom Debounce Per Skill
Currently not supported, but can be achieved by:
- Temporarily increase debounce for bulk operations
- Return to normal debounce for regular use
# Bulk add multiple skills
export NCP_FILE_WATCHER_DEBOUNCE_MS=1000
# ...copy/add many skill files...
# Then reduce back for normal use
export NCP_FILE_WATCHER_DEBOUNCE_MS=300Monitoring FileWatcher Events
To track all file changes:
export NCP_DEBUG=true
tail -f ~/.ncp/logs/ncp.log | grep -E "⭐|🔄|🗑️|❌"FAQ
Q: Does FileWatcher require a restart? A: No! That's the whole point - NCP keeps running and detects changes automatically.
Q: Can I disable FileWatcher but keep skills enabled? A: Currently no - if skills are enabled, FileWatcher will start. This is by design to ensure consistency.
Q: What if I'm editing a skill and someone else is too? A: The last save wins. FileWatcher detects the final modification and indexes that version. Consider using version control for collaboration.
Q: How long does a skill update take? A: Typically 100-300ms, depending on:
- File size
- Filesystem speed
- System load
- Debounce interval
Q: Can I use network shares for ~/.ncp/? A: Not recommended. Network latency causes delayed change detection. Use local filesystem for best results.
Q: What happens if a skill has syntax errors? A: The update fails with an error message. Previous version remains in index. Fix the error and re-save to update.
Q: Do deleted skills clean up immediately? A: Yes. Deletion removes the skill from discovery index immediately (within debounce window).