Repository navigation
Description
Summary
rtk diff FILE1 FILE2 prints [ok] Files are identical and exits 0 for files that
differ, whenever the changed line pairs share at least one word. Zero-overlap line
changes render correctly; any word overlap between the old and new line silently
suppresses the change — apparently classified as a "modified" pair and then dropped
entirely from both the summary counts and the rendered output.
This is dangerous for the tool's primary audience (AI agents): an agent that runs
rtk diff to verify a deploy or compare configs gets a confident wrong answer with a
clean exit code. We hit it comparing two agent-definition files whose only difference
was one frontmatter line — rtk diff said identical; /usr/bin/diff showed the change.
Reproduction (rtk 0.42.4, macOS arm64, Homebrew bottle)
printf 'alpha beta\n' > /tmp/v1.txt
printf 'alpha zzzz\n' > /tmp/v2.txt
rtk diff /tmp/v1.txt /tmp/v2.txt
# [ok] Files are identical <- WRONG
# exit 0
diff /tmp/v1.txt /tmp/v2.txt
# 1c1
# < alpha beta
# > alpha zzzz
# exit 1Boundary matrix (all verified)
| old line | new line | shared words | rtk diff result |
|---|---|---|---|
alpha beta |
alpha zzzz |
1 of 2 | "identical" (WRONG) |
alpha beta gamma delta |
alpha beta XXXXX delta |
3 of 4 | "identical" (WRONG) |
alpha beta gamma delta |
alpha beta gamma |
3 (suffix trim) | "identical" (WRONG) |
alpha beta gamma delta |
XXXXX beta gamma delta |
3 of 4 | "identical" (WRONG) |
alpha beta |
gggg zzzz |
0 | correct +/- output |
aaaa |
zzzz |
0 | correct +/- output |
old3 |
new3 |
0 | correct +/- output |
Multi-line context doesn't matter: a 36-line file with one word-overlapping changed
line is also reported identical. -v/-vv add the "Comparing:" banner but still say
identical.
Suspected mechanism: the word-similarity pairing classifies overlapping line pairs as
"modified" (the summary header prints ~0 modified in the working cases, suggesting a
modified bucket exists), but modified pairs are then omitted from output AND counted as
zero — when a diff consists only of such pairs, the tool concludes "identical".
Also: exit code
Even when rtk diff renders changes correctly, it exits 0 (real diff exits 1 on
difference). Scripts using rtk diff a b && echo same misbehave. Notably rtk diff -q
DOES exit 1 correctly — only the full-output path is wrong.
Workarounds
rtk diff -q— correct differ/identical verdict + exit code (but no hunk output)rtk proxy diff …— bypasses filtering, real diff semantics
Environment
- rtk 0.42.4 (Homebrew bottle,
homebrew/core, arm64, macOS 26 / Darwin 25.3.0) - Found via Claude Code hook usage (
diffauto-rewritten tortk diff), where the
false "identical" briefly masked a real config divergence.
Activity
pszymkowiak commentedon Jul 4, 2026
🔍 Automated Triage
bughighSummary
rtk diff falsely reports 'Files are identical' (and exits 0) whenever changed line pairs share any word, due to word-similarity pairing misclassifying them as 'modified' and dropping them from both counts and output — fix the modified-pair handling in the diff renderer/summary and the full-output exit code.
Triaged automatically by wshm · This is an automated analysis, not a human review.
AllanCardosobr commentedon Jul 10, 2026
Confirmed on rtk 0.36.0 (macOS, Darwin 25.3.0), so this predates the 0.42.x reports — long-standing behavior rather than a recent regression.
Consistent with the word-overlap hypothesis:
x = 1→x = 2(shared words) is swallowed as "identical", whileAAAA→BBBB(zero overlap) renders correctly — though still with exit 0, as covered in #2446.Impact matches the OP: hit via an AI agent (Claude Code with the rewrite hook) using
diffas an equality check and acting on the false "identical".qx54 commentedon Jul 17, 2026
Different results on rtk 0.43.0 (macOS): the false
[ok] Files are identicalno longer reproduces, and the exit code is now correct (1).However, the output format looks wrong: instead of a standard diff, it prints both files in their entirety, separated by
---, with no</>markers or hunk headers.This has been open for more than one month now, see #2446
KuSh commentedon Aug 30, 2026
Closing — this is fixed on current
develop. Verified with the exact reproduction from the report, on 0.46.0:The cause was the identical-files guard testing
added == 0 && removed == 0, which ignored themodifiedcounter — so a line pair classified as a modification (similarity > 0.5, i.e. any meaningful word overlap) was counted, then reported as no change at all.render_file_diffnow branches ondiff.changes.is_empty(), which covers modified-only diffs by construction.Two related defects from your report are still open, so this isn't the end of the story for
rtk diff:never_worsepicks it because it is fewer tokens than the rendered form. Tracked in diff output rewritten to a success verdict, exit code masked (rtk 0.42.1) #3267.Thanks for the boundary matrix in the original report — that's what made the classification bug obvious rather than just the symptom.