Skip to content

cgc watch does not respect .cgcignore rules #716

Closed

Description

@antonsynd

Description

cgc watch does not apply .cgcignore filtering, causing unnecessary graph updates when files in ignored directories change.

While build_graph_from_path_async() in graph_builder.py correctly searches for .cgcignore, parses it with pathspec, and filters files before indexing, the RepositoryEventHandler in core/watcher.py bypasses this entirely.

Steps to Reproduce

  1. Create a .cgcignore file in a project root with patterns like:
    **/bin/
    **/obj/
    
  2. Run cgc index — files in bin/ and obj/ are correctly excluded.
  3. Run cgc watch in the same directory.
  4. Trigger a build (e.g., dotnet build for a .NET project, or any build tool that writes to bin//obj/).
  5. Observe that the watcher receives events for files in ignored directories and triggers full repository refreshes.

Root Cause

In core/watcher.py, the RepositoryEventHandler event handlers (on_created, on_modified, on_deleted, on_moved) only check file extensions via self.graph_builder.parsers:

def on_modified(self, event):
    if not event.is_directory and Path(event.src_path).suffix in self.graph_builder.parsers:
        self._debounce(event.src_path, lambda: self._handle_modification(event.src_path))

There is no .cgcignore check here. Additionally, _handle_modification() and _initial_scan() both use a bare rglob("*") without .cgcignore filtering:

all_files = [f for f in self.repo_path.rglob("*") if f.is_file() and f.suffix in supported_extensions]

This means:

  1. Events for ignored files trigger processing — e.g., a .cs file generated in obj/ triggers _handle_modification().
  2. The re-scan includes ignored files — the full repository refresh parses files that cgc index would have skipped.

Expected Behavior

  • The watcher should load .cgcignore (same logic as build_graph_from_path_async) and:
    1. Skip events for files matching ignore patterns in on_created/on_modified/on_deleted/on_moved.
    2. Apply the same pathspec filtering in _initial_scan() and _handle_modification() when collecting files via rglob.

Impact

For projects with build artifacts in ignored directories (common in .NET, Java, Node.js, etc.), every build triggers a flood of watcher events and unnecessary full graph re-scans. In my testing with a .NET project, a single dotnet build generated tens of thousands of fsevents from bin/ and obj/ directories.

Suggested Fix

Pass the loaded pathspec.PathSpec into RepositoryEventHandler.__init__() and:

  1. Add a _should_ignore(self, path: str) -> bool method.
  2. Check it in each event handler before debouncing.
  3. Apply the same filter in _initial_scan() and _handle_modification() when building the file list.

Activity

  1. github-actions commented on Mar 13, 2026

    @github-actions
    Contributor

    Hi! 👋 Join our CodeGraphContext Discord channel to collaborate: https://discord.gg/dR4QY32uYQ

  2. hi0001234d commented on Apr 3, 2026

    @hi0001234d
    Collaborator

    assign it to me I am just starting working on it

  3. self-assigned this
    on Apr 7, 2026
  4. added a commit that references this issue on Apr 30, 2026
    b52785a
  5. Shashankss1205 commented on Apr 30, 2026

    @Shashankss1205
    Collaborator

    Hey @antonsynd can you please test the latest version and tell if the issue still persists? Thanks for reporting and making CGC better.

  6. moved this from Backlog tasks to Done in CGC Progress Boardon Apr 30, 2026
  7. added a commit that references this issue on Jun 21, 2026
    2daca40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions