Skip to content

Implement selective file watching to reduce watchers when --skip-projects or nested .claude exist#37

Open
konard wants to merge 3 commits intomainfrom
issue-32-3e7ff8a2
Open

Implement selective file watching to reduce watchers when --skip-projects or nested .claude exist#37
konard wants to merge 3 commits intomainfrom
issue-32-3e7ff8a2

Conversation

@konard
Copy link
Contributor

@konard konard commented Sep 10, 2025

Summary

Implements selective file watching in watch mode to reduce the number of filesystem watchers when --skip-projects is enabled or nested .claude directories exist, addressing issue #32.

Problem

Previously, watch mode would monitor ALL files and subdirectories recursively in the ~/.claude directory, including:

  • Projects folder (even when --skip-projects was used)
  • Nested .claude directories (which cause recursive monitoring issues)

This resulted in unnecessary filesystem watchers being created for files that were excluded from backups.

Solution

  • Selective Directory Watching: When --skip-projects is enabled or selective filtering is needed, create individual watchers for each subdirectory instead of using recursive watching on the parent
  • Projects Folder Exclusion: Skip creating watchers for the projects folder when --skip-projects is enabled
  • Nested .claude Directory Filtering: Skip watching nested .claude directories to avoid recursive monitoring issues
  • Runtime Filtering: Added shouldIgnoreFileChange() function to filter file change events using the same logic as the archiving process
  • Consistent Logic: Uses the same filtering logic already implemented in the archiving process (from PR Fix watch mode issues and recursive .claude directory bug #19)

Key Changes

  1. New setupSelectiveWatchers() function: Creates individual watchers for each subdirectory in ~/.claude with selective filtering
  2. New shouldIgnoreFileChange() function: Filters file change events at runtime using path analysis
  3. Enhanced watch setup logic: Detects when selective watching is needed and switches to selective mode
  4. Comprehensive test suite: Added multiple test files to validate the functionality

Testing

  • Unit Tests: examples/test-watch-filtering.js - validates file filtering logic
  • Integration Tests: examples/test-watcher-setup.js - tests selective watcher setup
  • Manual Testing: examples/test-watch-selective-monitoring.sh - helper for manual testing

Benefits

  • Reduced Resource Usage: Fewer filesystem watchers when --skip-projects is used
  • Better Performance: Eliminates unnecessary monitoring of excluded directories
  • Consistency: Watch mode now respects the same filtering rules as backup creation
  • Robust: Handles nested .claude directory edge cases

Impact

  • Backwards Compatible: No changes to existing CLI interface or behavior
  • Transparent: Users will see improved performance without changing their workflow
  • Debug Friendly: Verbose mode shows which directories are being watched vs skipped

Fixes #32

🤖 Generated with Claude Code

Adding CLAUDE.md with task information for AI processing.
This file will be removed when the task is complete.

Issue: #32
@konard konard self-assigned this Sep 10, 2025
konard and others added 2 commits September 10, 2025 20:45
…ects or nested .claude directories exist

- Add setupSelectiveWatchers() function to create individual watchers for .claude subdirectories
- Skip watching projects folder when --skip-projects option is enabled
- Skip watching nested .claude directories to avoid recursive watching issues
- Add shouldIgnoreFileChange() function for runtime filtering of file change events
- Maintain same filtering logic as used in archiving process for consistency
- Add comprehensive test suite for validation:
  * test-watch-filtering.js - Tests file change filtering logic
  * test-watcher-setup.js - Tests selective watcher setup
  * test-watch-selective-monitoring.sh - Manual testing helper

This significantly reduces the number of filesystem watchers when:
1. --skip-projects is used (excludes entire projects directory)
2. Nested .claude directories exist (prevents recursive monitoring)

Fixes issue where watch mode would monitor all files including those excluded from backups.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@konard konard changed the title [WIP] --skip-projects and recursive .claude skip should both reduce number of watched files Implement selective file watching to reduce watchers when --skip-projects or nested .claude exist Sep 10, 2025
@konard konard marked this pull request as ready for review September 10, 2025 17:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

--skip-projects and recursive .claude skip should both reduce number of watched files

1 participant