fix(grep): skip .claude/worktrees by default#2149
Conversation
|
I have read the CLA Document and I hereby sign the CLA |
|
Hey @nanookclaw Thanks for addressing this, Blocker: explicit-path searches into .claude/worktrees now silently return nothingThe exclusion glob is applied unconditionally, including when the user's own path argument points at the worktrees. mkdir -p repro/.claude/worktrees/wt1 && cd repro && git init -q
echo 'fn NEEDLE() {}' > .claude/worktrees/wt1/app.rs
echo '.claude/worktrees/' > .gitignorertk grep NEEDLE .claude/worktrees This is the exact failure mode build_rg_command's own --no-ignore-vcs comment exists to prevent ("false negatives that make AI agents draw wrong conclusions"). An agent deliberately inspecting a worktree gets an empty result with no indication the path was excluded. Scope (tested, for context): only explicit directory paths regress — normal scans (rtk grep X .), explicit file paths, --type, and running from inside a worktree are all unaffected. Secondary regression (grep fallback only)--exclude-dir=worktrees is base-name-only, so when rg is absent, any directory named worktrees is dropped — a legit src/worktrees/ silently disappears: |
rtk grep passes --no-ignore-vcs so ripgrep descends into Claude Code's gitignored .claude/worktrees checkouts, surfacing out-of-scope matches (worse with --hidden). Add a default rg exclusion glob (!**/.claude/worktrees/**) matching the directory at any depth, with an --exclude-dir mirror on the grep fallback. The exclusion is inserted before user args so a later user --glob can re-include the directory. Closes rtk-ai#2147 Signed-off-by: Nanook Claw <nanook@agentmail.to>
173894c to
b0e2b59
Compare
|
Addressed in Changes made:
Validation run locally:
|
Summary
rtk grepno longer descends into Claude Code's.claude/worktreescheckouts. Becausertk grepruns ripgrep with--no-ignore-vcs(and a user may add--hidden), the gitignored worktree copies were being searched, surfacing duplicate, out-of-scope matches. Closes rtk grep should ignore .claude/worktrees #2147.!**/.claude/worktrees/**(matches the directory at the repo root and any nested depth) plus an--exclude-dir=worktreesmirror on thegrepfallback path.--globstill wins (ripgrep honors the last matching glob) and can re-include the directory if explicitly wanted.--no-ignore-vcssemantics,--typehandling, the-r/--recursivestrip, and BRE→PCRE pattern translation are all preserved.Test plan
cargo fmt --all && cargo clippy --all-targets && cargo test— clippy clean, full suite 1954 passed / 0 failed.grep_cmd.rs: arg-construction (glob present/shape/any-depth, exclusion precedes user args on both backends, user args +--typepreserved) and one end-to-end test that runs realrgagainst a fixture with root + nested.claude/worktreesunder--hidden..claude/worktrees+ a normal file):rg --no-ignore-vcs --hidden): 3 matches, incl. both worktree files.rtk grep SENTINEL . --hidden): only the non-worktree file matches; worktrees skipped at root and nested depth.rtk grep SENTINEL . --hidden --glob '**/.claude/worktrees/**': re-includes the worktree files (override works).rgabsent, thegrepfallback (--exclude-dir=worktrees) also skips the directory.Fallback note: GNU grep's
--exclude-diris base-name only, so the fallback skips any directory namedworktrees. It only runs when ripgrep is unavailable, so the slight over-exclusion is an acceptable trade-off; this is documented in code.AI-assisted: implemented with Claude Code, reviewed with a second independent model pass before submitting.