Repository navigation
Description
Summary
rtk find produces false negatives with exit 0 in three related ways:
- An existing file passed as the search root returns empty output —
rtk find <file> -type ffinds nothing where nativefindprints the file. - A bare file argument (
rtk find <file>, RTK syntax) is parsed as a glob pattern, so it can never match either. - Pattern searches silently drop hidden and gitignored matches, with no indication that pruning happened.
All three exit 0 and (as of 0.43.0) print nothing at all on zero matches. For an LLM agent consuming rtk output as ground truth, "no output, exit 0" reads as "the file does not exist". This bit us in production agent use: an agent ran rtk find <path-to-existing-file>.md -type f, got empty output, concluded the file was missing, and kicked off a large, expensive wrong-turn recovery. Same silent-data-loss class as #2944.
Environment
- rtk 0.43.0 (Homebrew bottle), macOS arm64 (Darwin 27)
- Also reproduced on 0.39.0 — there the empty-result cases at least printed
0 for '*'/0 for '<pattern>'; 0.43.0 prints nothing, which is harder to notice.
Minimal reproduction
mkdir -p /tmp/rtk-find-repro/sub && cd /tmp/rtk-find-repro
echo hello > journal.md && echo world > sub/note.md
git init -q . && echo "sub/" > .gitignore
mkdir -p .hidden && echo x > .hidden/secret.md
# 1) Explicit file path as search root
rtk find ./journal.md -type f # → (no output), exit 0 ❌
find ./journal.md -type f # → ./journal.md ✅
# 2) Bare file argument (RTK syntax)
rtk find ./journal.md # → (no output), exit 0 ❌
# 3) Hidden + gitignored matches silently dropped
rtk find . -iname '*.md' # → journal.md (1 file) ❌
find . -iname '*.md' # → 3 files ✅Root cause (as of 5d32d07, src/cmds/system/find_cmd.rs)
1. Root-entry drop in run(). Display paths are computed by stripping the search root:
let display_path = entry_path
.strip_prefix(path)
.unwrap_or(entry_path)
.to_string_lossy()
.to_string();
if !display_path.is_empty() {
files.push(display_path);
}When the root is the file (native-syntax parse puts args[0] into parsed.path), the walker yields the root entry, strip_prefix returns "", and the !display_path.is_empty() guard discards the only match. Sibling symptom of the same line: rtk find <dir> -type d omits the root directory itself, which native find prints.
2. Bare file argument parsed as pattern. Without native flags, parse_rtk_find_args takes args[0] as the glob pattern and searches .. A path like ./journal.md is then glob-matched against basenames and can never match. On 0.39.0 the output 0 for './journal.md' at least exposed the misparse; 0.43.0 prints nothing.
3. Hardcoded ignore-pruning. run() builds the walker with:
builder
.hidden(!search_hidden) // skip hidden unless pattern starts with '.'
.git_ignore(true)
.git_global(true)
.git_exclude(true);Deliberate as a default (per the #1101 comment), but under native-flag syntax — which the help text advertises as "accepts native find flags like -name, -type" — the consumer asked for find semantics and silently gets ripgrep semantics. Nothing in the output signals that matches were pruned.
4. Empty result prints nothing. The files.is_empty() branch tracks stats and returns without printing. Silence is indistinguishable from "no files exist", and is a regression from 0.39.0's explicit 0 for '<pattern>'.
Suggested fixes
In descending order of impact:
- Handle a file root. If
parsed.pathis an existing non-directory, short-circuit: apply the type/pattern checks to it directly and print it (or fixdisplay_pathfor root entries to fall back to the file name / given path instead of""). - Print an explicit zero-result line (
0 matches for '<pattern>' in <path>) instead of nothing — restores and improves the pre-0.43 behavior; costs a handful of tokens and prevents "empty = nonexistent" misreads. - Make pruning visible or scoped: when hidden/gitignore filtering drops entries under native-flag syntax, either emit a one-line notice (
note: hidden/gitignored entries skipped — use rtk proxy find for the full list) or disable gitignore handling when native find flags are present. - Treat an existing path in
args[0]as a path, not a pattern, inparse_rtk_find_args(or reject it with a clear error).
Workaround
For file-existence checks in agent instructions: use test -f <path> or rtk proxy find …. Pattern searches that must honor hidden/gitignored files: rtk proxy find.
Activity
pszymkowiak commentedon Jul 14, 2026
🔍 Automated Triage
bughighSummary
rtk find silently drops matches (file-as-root, bare-file-as-pattern misparse, hardcoded gitignore/hidden pruning) and prints nothing on zero results, making 'no output' indistinguishable from 'file does not exist' — fix in find_cmd.rs per included root-cause analysis with line refs.
📁 Relevant files
src/cmds/system/find_cmd.rsTriaged automatically by wshm · This is an automated analysis, not a human review.
ildunari commentedon Jul 19, 2026
Independently hit this class in production agent use today (agent swept a
.gitdirectory for conflict copies, got clean output, concluded there were none — there were six). While narrowing it I found what looks like a fourth silent-false-negative path not covered by this issue or #2996: bracket character classes in-namematch nothing.It is independent of the hidden/gitignore pruning in case 3 — this reproduces in a pristine directory with no git repo, no
.gitignore, no hidden files, and only plain visible regular files:So
*and?are handled but[...]is not — any bracket expression yields zero matches, exit 0, empty stderr. Same "no output reads as does not exist" failure mode described above. I have not built #2996 to check whether it happens to fix this too, but nothing in that PR's description touches pattern parsing, so I suspect it is a separate fix.Two smaller notes that may be useful:
-type fomits dotfiles, which I think is case 3 seen from another angle — worth including in the test matrix as a non-pattern path:A reproduction trap worth flagging for anyone verifying this, because it cost me three "passing" tests before I caught it: piping changes the result.
rtk rewriteexits 1 for piped invocations, so the hook leaves them alone and nativefindruns:Any test that pipes to
wc -l/grep -cto count results silently exercises the wrong code path and reports the bug as fixed. Worth an explicit note in the test plan.Environment: rtk 0.43.0 (Homebrew bottle), macOS arm64 (Darwin 25 and Darwin 27, reproduced on both).
dispather commentedon Aug 7, 2026
Still present on 0.44.2 (macOS arm64, Homebrew) — item 3 reproduces unchanged. Two things to add that I don't think are in the thread yet, both arguing for your suggested fix #3.
1. The pruning is inconsistent between rtk's own commands, not just against native
findSame tree, same
.gitignore, one ignored directory:rtk ls reportk ls repo/graphify-outlistsdata.txt 12Brtk tree reportk du -sh repo/graphify-outrtk rg --filesrgdoes the same, so this one is a faithful proxyrtk find repo -name graphify-out -type dAt file level too:
So within a single session
rtk lswill show you a directory thatrtk findreports does not exist. The existing argument in this issue is "native-flag syntax promises find semantics and delivers ripgrep semantics" — this is a second, independent one: whatever the intended default, the tool disagrees with itself, and a caller has no way to know which answer to trust.rtk rgis the useful contrast — it filters, but only becausergdoes, so it stays honest as a proxy.2. The obvious cross-check fails the same way
rtk findomits the trailing newline on its last record, so a one-record result counts as zero:This matters here specifically because counting is what a careful caller does to detect this bug. "Don't trust the listing, pipe it through
wc -l" is the natural defensive habit, and it returns 0 for a result that exists — confirming the same false negative by a second route. Terminating the final record with\nis independent of the ignore-pruning decision and would fix this on its own. (#3303 reports the same shape forgit status --porcelain, so this may be one underlying behaviour rather than two.)Confirmations
rtk proxy findreturns the ignored entry wherertk findreturns nothing..gitignore, in case they save someone else time: a result-count cap (a flat tree of 8 matching directories returned all 8) and symlink handling (controls with and without a symlink both returned everything).Bounding the exposure
For anyone who wants to know what this hid from them rather than just fixing it forward — the affected set is enumerable outside the session:
git -C "$REPO" ls-files --others --ignored --exclude-standard --directoryThat's an upper bound on paths
rtk findwould have reported absent. On two of our repos it was 2,535 and 14 entries. The bias is what makes this sting:.gitignorelists caches and build outputs, which is exactly what people usefindto check the existence of — so "is this cache still there?" is the question most likely to be answered wrongly, and the wrong answer is always "no". In our case an agent nearly rebuilt an intact 26 MB artifact on that basis.kadirmobil-sudo commentedon Sep 8, 2026
A sharper case of point 3 (silently dropped gitignored matches): the pruning also drops paths that are tracked in git.
Git does not ignore a file that is already in the index, so
git check-ignorereports it as visible whilertk findstill omits it. Anyone verifying "is this ignored?" the obvious way gets the opposite answer from what rtk does.This is how it surfaced in practice: auditing a vault directory,
rtk find output -maxdepth 1 -type dreturned 15 of 28 directories. Twelve of the thirteen missing ones matched.gitignorepatterns; four of those twelve were tracked files that git itself does not ignore. There was no truncation notice and the exit status was 0, so the shorter list looked like the complete answer.Two smaller things visible in the same output:
1F 1D:for a-type dquery, where every result is a directory. The F/D split appears to be miscounted for directory-only searches.-maxdepth 1is honored, so this is not the pattern-search path specifically — the pruning applies to plain directory listings too.Environment: rtk 0.40.0, macOS 26.5.2 arm64 (Darwin 25.5.0). Not verified against 0.48.0.
BeeKnown commentedon Sep 26, 2026
Following up here from #4244, which was closed as a duplicate of this issue.
One detail from #4244 that isn't covered above: when
rtk findprunes a match inside a gitignored directory, the recall log doesn't help you recover it. The output ends with a(N filtered)line pointing at~/Library/Application Support/rtk/tee/<timestamp>_find-hidden.log, but that log lists only the ignored directory name (e.g.data/), not the file that matched. So even a user who notices the filtered count and opens the log has no way to see that a real match was dropped, or which one. The only way to get it back is to rerun withrtk proxy find.Minimal repro (rtk 0.50.0, macOS, Homebrew bottle):
The tee log for the first command contains
data/and nothing else.For the force-tracked part of case 3 specifically, #4253 is an open fix: after the walk it adds tracked files that match the pattern from
git ls-files --cached --ignored --exclude-standard. It doesn't change the tee log, which it lists as out of scope, so the log problem above would still need its own change. A log entry naming the pruned paths that matched, rather than just the ignored directory, would be enough. I've retargeted #4253 to reference this issue.KuSh commentedon Nov 25, 2026
One more input that reaches the same misreading: a glob as the first starting point. From PowerShell or cmd, which pass globs through unexpanded,
rtk find s* -name '*.rs'(in a tree withsub/x.rs) is read as the pattern form, becomesfind -name 's*' -name '*.rs', and prints nothing with exit 0. Nativefindfrom bash printssub/x.rs. Measured on Windows 11 with develop e87da19 and with #4544's head;rtk find ./s* -name '*.rs'works on #4544 becauselooks_like_pathkeeps it out of the pattern form.KuSh commentedon Nov 28, 2026
Status on v1.2.1: a file given as the search root (
rtk find ./journal.md -type fandrtk find ./journal.md) and bracket classes like-name '*[0-9].txt'now return the same matches asfind. What remains is the pruning of hidden and gitignored paths (rtk find . -iname '*.md'shows(2 filtered)wherefindlists the files, the recall entry names only the directories, and a git-tracked file under an ignored directory is still dropped), plus the glob-as-first-starting-point form from the previous comment. Narrowing this issue to those.