An agent is asked to find all the test files in a 5,000-file codebase to update an import statement. The agent currently runs Bash("find . -name '*.test.tsx'"). The result includes some directories that should have been ignored (like node_modules), and the agent now has to filter them out.
What's the cleaner approach?
Why did you pick that answer? Two or three sentences. The act of articulating it is what builds the judgment — not the click that follows.
Glob is the dedicated tool for path-pattern matching — it respects ignore rules, is faster than shell find, and doesn't require you to remember find's flag syntax. The general principle: Glob for paths, Grep for content, Read/Write/Edit for file contents, Bash only when no dedicated tool fits. Reaching for Bash first is a common anti-pattern that costs reliability.
You can do path matching with find, just as you can write web pages in assembly — but the dedicated tool exists because it's better at this specific job. Defaulting to Bash for problems with cleaner solutions adds friction every time.
This is the cleverest of the wrong answers — git ls-files does respect gitignore, and switching to it solves the immediate problem. But you've still picked Bash for path discovery, just with a more sophisticated shell command. The dedicated tool that handles this case directly is sitting unused. Don't reach for cleverness in the wrong layer.
Parsing .gitignore to build exclusion logic for find is rebuilding, in your agent code, the exact behavior Glob provides for free. This is the most expensive way to get to the right answer — and the next developer to read your code will rightly ask why you didn't just use Glob.