Repository navigation
cgc watch does not respect .cgcignore rules #716
Description
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
- Create a
.cgcignorefile in a project root with patterns like:**/bin/ **/obj/ - Run
cgc index— files inbin/andobj/are correctly excluded. - Run
cgc watchin the same directory. - Trigger a build (e.g.,
dotnet buildfor a .NET project, or any build tool that writes tobin//obj/). - 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:
- Events for ignored files trigger processing — e.g., a
.csfile generated inobj/triggers_handle_modification(). - The re-scan includes ignored files — the full repository refresh parses files that
cgc indexwould have skipped.
Expected Behavior
- The watcher should load
.cgcignore(same logic asbuild_graph_from_path_async) and:- Skip events for files matching ignore patterns in
on_created/on_modified/on_deleted/on_moved. - Apply the same
pathspecfiltering in_initial_scan()and_handle_modification()when collecting files viarglob.
- Skip events for files matching ignore patterns in
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:
- Add a
_should_ignore(self, path: str) -> boolmethod. - Check it in each event handler before debouncing.
- Apply the same filter in
_initial_scan()and_handle_modification()when building the file list.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
github-actions commentedon Mar 13, 2026
Hi! 👋 Join our CodeGraphContext Discord channel to collaborate: https://discord.gg/dR4QY32uYQ
hi0001234d commentedon Apr 3, 2026
assign it to me I am just starting working on it
fixes #716
Shashankss1205 commentedon Apr 30, 2026
Hey @antonsynd can you please test the latest version and tell if the issue still persists? Thanks for reporting and making CGC better.
fixes CodeGraphContext#716