Troubleshooting

Atlas edit error: Could not find oldString in the file

Updated 8 min read

Atlas fails with Could not find oldString in the file because edit.replace runs a cascade of nine replacers (simple, line-trimmed, block-anchor, whitespace-normalized, indentation-flexible, escape-normalized, trimmed-boundary, context-aware, and multi-occurrence) and throws that message only when every one of them fails to locate your text, so the fix is to re-read the file with the read tool and copy oldString straight out of the output rather than reconstructing it from memory. The error message itself names the requirement: it must match exactly, including whitespace, indentation, and line endings. Include enough surrounding context that the span is unique. If you meant to create a new file, pass an empty oldString instead, and if you meant a full rewrite, use write.

Why does Atlas say it could not find oldString in the file

Atlas throws Could not find oldString in the file only after edit.replace has run a cascade of 9 replacers and every one of them missed. The message states the requirement directly: oldString must match exactly, including whitespace, indentation, and line endings. Nothing partial matched anywhere in the file.

The nine replacers in the edit.replace cascade are simple, line-trimmed, block-anchor, whitespace-normalized, indentation-flexible, escape-normalized, trimmed-boundary, context-aware, and multi-occurrence. Several of those are deliberately forgiving: line-trimmed and whitespace-normalized tolerate spacing drift, and indentation-flexible tolerates a shifted indent level. So when the error appears, your oldString did not merely have a stray space. Something more substantial is wrong: the text is not in the file at all, it is in a different file, it was already changed by an earlier edit in the same session, or it was reconstructed from memory rather than copied. Diagnose the mismatch rather than nudging the whitespace.

How to fix Could not find oldString by re-reading the file

The reliable fix for Could not find oldString in the file is to call the Atlas read tool on the target, then copy oldString straight out of that output. Copying from the read output guarantees whitespace, indentation, and line endings match what the 9 replacers in edit.replace are searching, because they are the same bytes.

Reconstruction is the root cause in most of these failures. An oldString typed from memory, lifted from a code review, or pasted from a diff hunk carries subtle differences from what is on disk right now, and none of the nine replacers is designed to bridge an outright content mismatch. Reading first also catches the second most common case: the file already changed. If an earlier edit in the session touched the same region, the text you are targeting no longer exists in the form you remember. Read, copy, edit. Once the edit succeeds, Atlas computes a unified diff for the file edit and surfaces it for approval before writing, so you will see exactly what changed.

How line endings cause Atlas edit to miss oldString

Atlas normalizes line endings and converts to the file's detected ending during edit, so CRLF versus LF is handled for you across all 9 replacers. A mismatched paste can still miss, which is why the error text names line endings explicitly alongside whitespace and indentation as part of the exact-match requirement.

Do not spend long here, because line endings are rarely the whole story once the cascade has run. Atlas already detects the file's ending and converts, so a file that is uniformly CRLF and an oldString that arrives as LF is usually not the failure. What does bite people is a paste that mixed endings inside a single oldString, typically from copying across editors or terminals. Rather than trying to debug invisible characters by inspection, sidestep the class entirely: pull oldString from the read tool's output so that whatever the file actually contains is what you hand back to edit.

How much context should oldString include in Atlas edit

Include enough surrounding lines in oldString that the span is unique in the file. Atlas edit needs a match that is both findable and unambiguous, and the 9-replacer cascade in edit.replace is looking for your exact text, so a short fragment is harder to locate and likelier to collide elsewhere.

There is a real tension to manage. Too little context and the match is fragile, since a lone line like a closing brace or a common assignment appears in many places and gives the replacers nothing distinctive to anchor on. Too much and you make the edit brittle for other reasons. The practical target is the smallest span that appears exactly once, usually a function signature plus its body, or a statement plus the two lines that bracket it. Copy that span verbatim from the read tool. Uniqueness matters here for a second reason too: an oldString that appears more than once triggers a different Atlas failure entirely.

When to use empty oldString or the write tool instead of edit

Atlas gives you 2 escape hatches from edit. If you meant to create a new file, pass an empty oldString, which is how edit creates files. If you meant to replace an entire existing file, call the write tool. Neither case should produce Could not find oldString, because neither is a search.

Some occurrences of this error are really a wrong-tool problem wearing a search failure's clothes. An agent that wants to scaffold a brand new module and invents plausible-looking existing text to replace will hit the cascade and get nowhere, because the file has no such text. An empty oldString is the correct signal for file creation. Likewise, a full-file rewrite expressed as a giant oldString covering every line is fragile and slow to construct, and write does the job directly. Reach for edit when you are changing a bounded region of a file that already contains text you can quote verbatim.

How to verify the Atlas edit finally matched

Verify the fix by re-running edit after copying oldString from the read tool output. A successful match produces 1 unified diff for approval, because Atlas computes a unified diff for every file edit and surfaces it before writing. Another Could not find oldString error means the text still is not in the file.

A repeated failure after a clean copy from the read tool is a strong signal that you are looking at the wrong file or the wrong revision of it. Confirm the path, and confirm no earlier edit in the same session already rewrote the region you are targeting. Reading the diff Atlas presents is the other half of the verification: check that the hunk it is proposing touches the lines you meant, not a similar-looking span elsewhere in the file. Atlas also snapshots file changes as git patches, so if an approved edit lands somewhere unintended, it can be diffed and rolled back.

How to fix it

  1. 01Re-read the file with the read tool and copy oldString straight out of the output. Do not retype it and do not reconstruct it from memory.
  2. 02Check line endings. Atlas normalizes and converts to the file's detected ending, but a mismatched paste can still miss.
  3. 03Include enough surrounding context in oldString that the span is unique within the file.
  4. 04If you meant to create a new file, pass an empty oldString rather than guessing at existing text.
  5. 05If you meant a full rewrite of the file, use the write tool instead of edit.
  6. 06Re-run edit and confirm Atlas produces a unified diff for approval rather than throwing Could not find oldString in the file.

Frequently asked questions

how do I fix could not find oldString in the file in Atlas
Re-read the file with the Atlas read tool and copy oldString straight out of the output. The match must be exact, including whitespace, indentation, and line endings, and copying from the read output guarantees those bytes are identical.
why does Atlas edit fail even though the code is in the file
edit.replace runs nine replacers (simple, line-trimmed, block-anchor, whitespace-normalized, indentation-flexible, escape-normalized, trimmed-boundary, context-aware, multi-occurrence) and throws only when all of them miss. If it still fails, the text on disk differs from what you supplied, often because an earlier edit already changed it.
does Atlas edit handle CRLF and LF line endings
Yes. Atlas normalizes line endings and converts to the file's detected ending, so a uniform CRLF or LF file is handled. A paste with mixed endings inside one oldString can still miss, which is why copying from the read tool output is the safe path.
how much context should I include in oldString for Atlas edit
Include enough surrounding lines that the span appears exactly once in the file. A lone brace or a common assignment gives the replacer cascade nothing distinctive to anchor on, and a non-unique span causes a different edit failure.
how do I create a new file with the Atlas edit tool
Pass an empty oldString. An empty oldString is how Atlas edit creates a new file. Do not invent existing text to replace, because the replacer cascade will search for it, fail, and throw Could not find oldString in the file.
should I use edit or write to replace a whole file in Atlas
Use write. The Atlas edit tool is for changing a bounded region you can quote verbatim, and expressing a full-file rewrite as one enormous oldString is fragile. write replaces the file contents directly.
what are the replacers in the Atlas edit tool
edit.replace cascades through simple, line-trimmed, block-anchor, whitespace-normalized, indentation-flexible, escape-normalized, trimmed-boundary, context-aware, and multi-occurrence replacers. Several tolerate spacing and indentation drift, so a failure usually means a real content mismatch, not a stray space.

Try Atlas in your terminal

The terminal-native AI coding agent. Free core, single binary.

Install Atlas

Related guides

Atlas with GPT-5.4: The Balanced 2026 Default

GPT-5.4 brings a 1,050,000 token window to Atlas at $2.50 / $15 per Mtok, half the input cost of GPT-5.6. The balanced day-to-day default for 2026 sessions.

Atlas with GPT-5.3 Codex: Code-Specialized Reasoning in 2026

GPT-5.3 Codex is OpenAI's February 2026 code-specialized reasoning model, $1.75 / $14 per Mtok on a 400K window. Built for the long agentic loops Atlas runs.

Rename a Symbol Across the Repo with Atlas in 2026

How to rename a symbol across a repo with Atlas in 2026: findReferences gets the true reference set, grep catches strings and docs, and edit refuses ambiguous matches.

Atlas with GPT-5.6: OpenAI's 2026 Flagship in the Terminal

GPT-5.6 gives Atlas a 1,050,000 token context at $5 / $30 per Mtok. Atlas routes OpenAI through the Responses API so reasoning persists across tool calls in 2026.

Atlas with Grok 4.20 (Non-Reasoning) in 2026: Fast, Predictable Edit Passes

Grok 4.20 (Non-Reasoning) bills no thinking tokens, so cost per turn is fully predictable at $1.25 / $2.5 per Mtok, with the same 1,000,000 token context as the reasoning variant.

Atlas with Qwen3.6 Max Preview: The Top 3.6 Tier, Reviewed in 2026

Qwen3.6 Max Preview is Alibaba's top Qwen3.6 tier at $1.30 per Mtok input and $7.80 per Mtok output, with 256K tokens (262,144) of context. What it is worth inside Atlas.

Atlas with MiniMax-M2.1 in 2026: A Free Upgrade Over M2

MiniMax-M2.1 runs Atlas at $0.30 per Mtok input and $1.20 per Mtok output with a 204,800 token context and 131,072 max output. Setup, tradeoffs, and when to move on.

Atlas with Qwen Flash: A Cheap Tier That Still Writes Real Diffs in 2026

Run Atlas on Qwen Flash in 2026. Alibaba's fast tier pairs 1M tokens (1,000,000) of context with a 32,768 token output at $0.05 per Mtok in, $0.40 per Mtok out.

Browse this resource hub