← ClaudeAtlas

bash-cwd-drift-false-clean-greplisted

Catch the false all-clear produced when the Bash tool's persistent working directory drifts and a verification grep silently searches the wrong tree. Use when: (1) a `grep -rn` over known-present strings returns nothing and you are about to conclude the repo is clean, (2) an earlier `cd subdir/` in the session was followed by a repo-root-relative command, (3) a "no matches" result is being used as evidence rather than as an absence of evidence, (4) a stale-claim sweep or a pre-commit consistency check returns empty, (5) `ls`/`cat` on a root file reports No such file or directory. The Bash tool persists cwd across calls, so a grep with relative paths reports zero matches instead of erroring, and zero matches reads exactly like a passing check. Includes the guard that turns a silent miss into a loud one.
MrBinnacle/skills · ★ 0 · AI & Automation · score 68
Install: claude install-skill MrBinnacle/skills
# Bash cwd drift turns a verification grep into a false all-clear ## Problem The Bash tool's working directory **persists between calls**. A `cd subdir/` earlier in the session is still in effect many calls later. When a verification command uses paths relative to the repo root, it searches a tree that does not contain them. For most commands this is loud — `cat`, `ls`, `git add` error out. **For `grep` it is silent in the worst possible direction**: multi-path `grep` reports "no matches" for files it could not open, and no matches is exactly what a clean repository looks like. The result is a verification step that returns *pass* without having examined anything. ## Context / Trigger conditions - A `grep -rn` for strings you know are present returns nothing. - Earlier in the session a command ran `cd <subdir>` — often to run a test suite or a build. - You are running a stale-claim sweep, a pre-commit consistency check, or a "did I miss this string anywhere else" pass, and it comes back empty. - A subsequent `ls` or `cat` on a repo-root file says `No such file or directory`. - The empty result is about to be reported to a user as "verified: nothing else to fix." ## Root cause Two behaviours compose: 1. **cwd persists across Bash tool calls.** Shell variables and functions do not; the directory does. 2. **`grep` with several path arguments treats an unopenable path as a non-match** in the aggregate exit status when other paths matched — and when *none* opened,