find shell wrapper doesn't skip hidden/gitignored paths like grep/rg do — traverses Claude's own .claude/worktrees/

Status Open
Maintainer reply None cached
Activity 0 comments · opened Aug 20, 2026

Summary

The shell wrappers Claude Code installs for grep/rg respect .gitignore and skip hidden directories by default. The find wrapper (which shells out as bfs) does not. In a repo where Claude Code itself creates a large gitignored directory — .claude/worktrees/ — this means find silently traverses back into Claude Code's own worktree stash, inflating Bash tool output and token usage on any task that runs a bare find from the repo root.

Repro

In a repo with several worktrees under .claude/worktrees/ (excluded via .gitignore and .git/info/exclude):

$ find . -name "*.py" | wc -l
91170
$ find . -name "*.py" | grep -c "^./.claude/worktrees"
65411   # 72% of all results come from inside .claude/worktrees/

For comparison, grep/rg from the same root correctly exclude it:

$ grep -rl "class " . | grep -c "^./.claude/worktrees"
0

find does have a -nohidden flag, but it isn't applied by default, so it has to be passed explicitly (or the caller has to remember to -not -path "./.claude/worktrees/*") on every invocation.

Impact

.claude/worktrees/ is created by Claude Code itself (for --worktree, EnterWorktree, subagent/background-session isolation), and per the worktrees docs, the auto-cleanup sweep intentionally skips any worktree that still has uncommitted changes or unpushed commits — so in an active dev environment, this directory can persist for a long time and grow large. Any agent task that runs Bash find from the repo root during that window pulls in a large amount of irrelevant data, which can materially inflate token usage for tasks whose actual scope is narrow.

Suggested fix

Make the find wrapper consistent with the grep/rg wrappers: skip hidden directories and honor .gitignore/.git/info/exclude by default (equivalent to always applying -nohidden, or specifically always excluding .claude/worktrees/), with an explicit opt-in flag for callers that need to search hidden/ignored paths intentionally.

Environment

  • Claude Code CLI, shell integration (grep/rg/find wrapped as ugrep/rg/bfs via the Claude binary)
  • Reproduced in a large git monorepo with multiple worktrees under .claude/worktrees/

View original on GitHub ↗