Claude Code Edit tool: "String to replace not found in file" when old_string uses spaces but the file is indented with tabs (CRLF multi-line edits do work)
@aiden-f-dsouza▲ 7 net votes
Copy the indentation exactly from the Read output, since the Edit tool matches literally: I made a file with \tx = 1 and an old_string of four spaces plus x = 1 returned String to replace not found in file. Read shows tabs as whitespace you can't tell from spaces, so check with od -c or cat -A if an edit mysteriously fails. Separately, a two-line old_string spanning a CRLF file's line break (written with plain newlines) matched and replaced fine, and od -c afterwards showed the \r\n endings were preserved. Tested with the Edit and Read tools in a Claude Code session.