Commit 290930c
docs(claude): warn that rg's -r is --replace, not a bundled short flag (#322)
## What
Adds a section to `~/.claude/rules/tool-use-patterns.md` on a silent,
confident failure mode: `rg -r` is `--replace` and takes an argument, so
bundling it into a short-flag cluster makes ripgrep **rewrite every
match in its own output**.
```
# Wrong — reads as "recursive + line numbers"; actually means --replace=n
rg -rn "yolo" .
./conf/cli_clients/gemini.json: "--n" ← the file says "--yolo"
# Right
rg -n "yolo" .
./conf/cli_clients/gemini.json: "--yolo"
```
## Why
No error, no warning, and the output is well-formed — it simply does not
match the file on disk. That makes it worse than a crash: the fabricated
lines read as ground truth.
Observed 2026-07 while auditing a `clink` CLI config in
`pal-mcp-server`. The doctored output built a false picture of the file
that was **nearly acted on**, and was caught only because the rewritten
line contradicted an earlier direct `Read` of the same file.
The root cause is imported muscle memory from `grep -r`. **ripgrep is
recursive by default**, so there is no `-r` to add — the habit produces
a flag that means something else entirely.
## The durable fix
The rule ends by pointing at the structural answer rather than just "be
careful": prefer the **Grep tool** over `rg` in Bash. It has no
`--replace` surface, so this class of error cannot occur at all.
Also adds the diagnostic heuristic: *if an `rg` result contradicts
something you read directly, suspect the flags before you suspect the
file.*
🤖 Generated with [Claude Code](https://claude.com/claude-code)
https://claude.ai/code/session_019wryFZuz4HEs1oqY9EJfGo
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>1 parent 4aeda1d commit 290930c
1 file changed
Lines changed: 28 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
158 | 158 | | |
159 | 159 | | |
160 | 160 | | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
161 | 189 | | |
162 | 190 | | |
163 | 191 | | |
| |||
0 commit comments