claude-code icon indicating copy to clipboard operation
claude-code copied to clipboard

[BUG] Auto mode instructs Bash reads (cat/sed -n) while Edit requires a Read-tool read, so every auto-mode edit fails once by design

Open GridWork-dev opened this issue 3 months ago • 1 comments

Summary

In auto mode the harness's own system instruction tells the model to read files with cat/head/sed -n instead of the Read tool. The Edit tool's read-before-edit guard only counts the Read tool. Obeying the first rule guarantees the second one rejects the edit, so every auto-mode edit of a file the model has not Read-tooled costs two extra round-trips (the error, then a Read, then the retry).

This is distinct from #53525 (files written by Bash) and #76361 (read-state resets): here the two rules contradict each other by design, so the failure is not a state bug but an instruction conflict.

Reproduction

  1. Start a session in auto mode (the mode whose system text says: "Do your work through the Bash tool wherever it can accomplish the job: read files with cat, head, or sed -n ... rather than using the dedicated Read, Edit, or Write tools").
  2. Ask for a one-line change in any existing file. The model reads it with cat (as instructed).
  3. The model calls Edit on that file.
  4. Edit returns File has not been read yet. Read it first before writing to it.
  5. The model calls Read, then Edit again; the edit succeeds.

Measured

Corpus grep over every Claude Code transcript on one Linux box (retained window about 60 days): the string File has not been read yet appears 363 times across 80 transcripts. Every occurrence in a sample of 64 deep-read sessions followed a Bash read that the auto-mode instruction asked for.

Expected

Either of these removes the contradiction:

  • A Bash read of a path (cat, head, sed -n, tail) marks that path as read for the Edit guard, or
  • the auto-mode instruction stops asking the model to bypass the Read tool for files it is about to edit.

Environment

Claude Code 2.1.259, Linux (Arch), CLI in tmux. No plugins touch the Edit or Read tools.

GridWork-dev avatar Sep 04 '26 01:09 GridWork-dev

Measured on Claude Code 2.1.296, macOS. Each action ran in a fresh claude -p session. An InstructionsLoaded hook was the ground truth, and every transcript was checked for exactly one tool call.

What loads path rules and nested CLAUDE.md now:

  • Loads: Read, Write (including a new file), and a plain single-file cat/head/tail/nl/bat/sed -n, or grep/rg with a match. These also count inside a ; or && list.
  • Loads nothing: pipes, ||, redirects (2>/dev/null), extra flags (cat -A), cd dir && cat file, grep -r, a grep with no match, and every Bash write (sed -i, >, >>, heredoc, python -c, cp).

A fix that keeps Bash: a root CLAUDE.md brief that explains the gap and asks for one plain read per folder before working there. Tested on Opus in auto mode with bashFirst:true confirmed in every session: 5 edit tasks × 3 runs per arm.

No brief Strict "Edit/Write only" brief Read-first brief (below)
Rule loaded 5/15 15/15 15/15
Bash writes 12/15 2/15 2/15 (after a Read)
Avg tool calls 2.4 2.5 2.3

Context loading (known Claude Code gap). Path rules and nested CLAUDE.md load only on a Read/Write/Edit, or a plain single-file Bash read (cat, head, tail, sed -n, grep/rg with a match), with no pipes and no cd &&. Bash writes, pipes and multi-file commands load nothing. Before working in a folder, do one plain read of a file there; after that, use whatever is most efficient, Bash included. Repeat for each new folder, and again after /compact.

Small sample, and it's a workaround, not a fix, but it's been holding up for us.

yishait-tailor avatar Oct 13 '26 18:10 yishait-tailor