Skip to content

Add config option to disable automatic git worktree discovery in grepai watch #211

@Jonathan-7

Description

@Jonathan-7

Problem

grepai watch automatically discovers and indexes all linked git worktrees via go-git. In projects that use tools which create many worktrees (e.g. Claude Code's EnterWorktree), this causes the watcher to become unstable:

  1. Each worktree triggers a full parallel initial scan (thousands of files each)
  2. Multiple concurrent scans overwhelm the Ollama embedding endpoint with requests, causing context canceled errors
  3. The filesystem event channel fills up (Event channel full, dropping event)
  4. The watcher exits, KeepAlive restarts it, and the cycle repeats — we observed 95,000+ restart cycles in a single day

The main project is a Django monolith with ~6,100 files. With 2-3 active worktrees, the watcher was trying to scan ~18,000+ files simultaneously, which Ollama (nomic-embed-text on Apple Silicon) couldn't sustain.

Workarounds attempted

Approach Result
parallelism: 1 Helped but didn't prevent crashes — worktree scans still run in parallel
.claude in ignore list Prevents indexing .claude/ files but doesn't prevent worktree discovery
Git CLI shim intercepting worktree list No effect — grepai uses go-git, not the CLI
Temporarily renaming .git/worktrees/ grepai retries discovery every ~12s; also breaks git in active worktrees
ThrottleInterval in launchd plist Mitigates restart storms but doesn't fix root cause

Proposed solution

Add a config option to disable worktree auto-discovery:

watch:
  discover_worktrees: false  # default: true (current behavior)

When false, grepai watch would only index the project at the working directory and skip linked worktree discovery entirely.

Alternative proposals

  • watch.max_worktrees: N — limit how many worktrees to watch (0 = none)
  • watch.worktree_ignore_patterns: [".claude/*"] — filter specific worktrees by path pattern
  • Sequential rather than parallel worktree scanning — index one worktree at a time

Environment

  • grepai: 0.35.0
  • OS: macOS 14.5 (Apple Silicon)
  • Embedder: Ollama with nomic-embed-text
  • Backend: gob
  • Project: ~6,100 files, 2-3 concurrent worktrees created by Claude Code

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions