What this thread does
As of November 2026, do not add useSmartEdit; the current configuration reference does not list it. Do first: request a fresh read and a small replacement; after adding a failure rule to GEMINI.md, use /memory reload to load it into the current session.
The problem
The replace (edit) tool in Gemini CLI often fails with messages such as "Failed to edit, could not find the string to replace", "0 occurrences found for old_string" or "No changes detected", and the agent then loops. The tracking issue (opened 2025-06-13 by sijieamoy, with a summary added by a Gemini CLI collaborator) describes these failures. GitHub shows it as closed on 2025-12-03 with the reason "duplicate"; a commenter complained that the older, better-documented issue was closed in favour of a newer one. Reports continued into 2026 (the last comments are from January to March).
What the maintainers said
In September 2025 a collaborator wrote that the team was testing a new "smart edit" tool and asked users to add "useSmartEdit": true to settings.json, saying it had significantly improved the edit error rate in their testing. The later repository history and current reference describe a different situation:
- A pull request titled "Enable smart edit by default on main" was merged on 2025-09-03.
- The current Gemini CLI configuration reference does not list
useSmartEdit, and the tools folder holds a singleedit.ts. The history in the repository: PR 7679 (merged 2025-09-03) enabled smart edit by default on main, PR 11051 (merged 2025-10-13) changed theuseSmartEditschema default to true, and PR 15832 (merged 2026-01-02) removed the setting because smart edit is now the only registered edit tool. So on current versionsuseSmartEditno longer exists and you should not rely on it. - The same reference documents
tools.disableLLMCorrection(default true): when enabled, edit tools fail immediately if exact matches are not found instead of trying to self-correct. Leave this as the default unless you have a reason; this setting is not presented in the thread as a fix.
What commenters reported
- One commenter said smart edit on CLI v0.4.0 dropped the error rate significantly but not to zero. Another enabled it and still saw repeated failures.
- Rules in GEMINI.md were suggested by commenters. A commenter described a rule to grep for the target text whenever replace fails (reported as helping avoid most infinite loops). Another suggested telling the model to prefer small targeted replacements and to read the file again right before each replacement, reporting fewer failures. These are individual user reports, rather than a maintainer guarantee.
- After changing
GEMINI.md, run/memory reloadto reload context, and/memory showto inspect it. The context guide documents both commands, so a restart is not required solely to reload those instructions. - Others had the agent use
sed, or asked it to print the diff so they could apply it by hand.
Takeaway
The thread was closed as a duplicate on 2025-12-03; it does not identify a confirmed fix. Keep edits small, make the agent read the file again before replacing, keep a GEMINI.md rule for the failure case, and expect some failures after long sessions (commenters in 2026 said it grows worse over time).
Sources
- Gemini CLI #1028: edit failures and community workarounds.
- Configuration reference: current settings omit
useSmartEdit;tools.disableLLMCorrectiondefaults to true. - GEMINI.md guide:
/memory reloadand/memory show. - Repository history: PR 7679, PR 11051 and PR 15832.
- Gemini CLI tools directory.
Started from a post by @sijieamoy, packaged by the editor. Original post