You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Could not find oldString in the file. It must match exactly, including whitespace, indentation, and line endings.
This contract is false. Matching actually runs a fuzzy replacer chain that normalizes whitespace/indentation before concluding "not found". The error message and the real behavior contradict each other. This is independent of any opinion about whether fuzzy matching is desirable — the message simply misstates what the tool does.
Reproduction
File:
alpha
beta_line
gamma
oldString = " beta_line" (4 spaces, file has 3) → edit succeeds (whitespace normalized), so the "must match exactly" contract is already violated here.
oldString = "nonexistent_text_xyz" → rejected with the error text above, which claims exactness including whitespace — the same whitespace that was just normalized in case 1.
Minimal evidence: leading indentation (4sp vs 3sp), internal spacing (foo bar vs foo bar), and tab↔spaces all match via non-exact replacers (LineTrimmedReplacer / WhitespaceNormalizedReplacer in packages/opencode/src/tool/edit.ts).
Why it's a problem
Callers (models and automation) rely on the error text to decide how to correct oldString. Telling them matching is exact-when-it-isn't sends them down the wrong path (e.g. re-checking whitespace that the tool would have tolerated anyway), and misleads spec-driven tooling about when matching will fail.
Proposed fix
Rewrite the message to reflect reality:
thrownewError("Could not find oldString in the file. Exact match and all fuzzy fallbacks "+"(whitespace/indentation/escape-tolerant) were attempted. Re-read the file and "+"copy the exact text (whitespace included) into oldString.")
Related
Companion feature request: surface which match strategy (exact vs fuzzy) was used on success.
This issue might be a duplicate of existing issues. Please check:
edit tool: failed oldString match returns no context — models abandon the edit instead of retrying #42908: Also targets the same "must match exactly" error message and proposes improving it — that issue focuses on adding context (closest matching region) to help models retry, while this one focuses on the message being factually incorrect about whitespace matching. They overlap on the same error text and may be best resolved together.
Activity
github-actions commentedon Aug 25, 2026
This issue might be a duplicate of existing issues. Please check:
edittool: failed oldString match returns no context — models abandon the edit instead of retrying #42908: Also targets the same "must match exactly" error message and proposes improving it — that issue focuses on adding context (closest matching region) to help models retry, while this one focuses on the message being factually incorrect about whitespace matching. They overlap on the same error text and may be best resolved together.thdxr commentedon Oct 11, 2026
Thanks for the report! OpenCode 2.0 is now out and development is focused on V2, so we're closing issues filed against OpenCode 1. Please upgrade (
opencode upgrade --major, details: https://anoma.ly/notes/opencode-2-0), and if this is still relevant on 2.0, reopen this issue or open a new one with your 2.0 version.— from 𝕺𝖕𝖊𝖓𝕮𝖔𝖉𝖊
adrien-pain-eurodecision commentedon Oct 28, 2026
@thdxr I can confirm that this issue still arises in opencode 2.2.0