Gemini CLI: Surgical Code Edits via Smarter Tool Steering

Gemini CLI

Gemini CLI v0.43.0 updates the tool guidance for write_file and replace in the Gemini 3 model family, steering the model to prefer targeted replace operations over full-file rewrites for code modifications. The change reduces token consumption, shrinks diffs, and prevents accidental deletion of existing code that the user did not intend to remove. Developers working on large files will see fewer wholesale rewrites and more precise, reviewable edits.


Gemini CLI v0.43.0: Smarter Code Editing with Surgical Precision

One of the most frustrating patterns in AI-assisted coding is asking the model to change a single function and receiving back the entire file rewritten. Gemini CLI v0.43.0 tackles this directly by updating how it instructs the underlying model to choose between its editing tools.

The Problem: Whole-File Rewrites

Gemini CLI offers two primary file-modification tools: write_file, which writes an entire file to disk, and replace, which performs targeted string substitutions within an existing file. Until v0.43.0, the model did not have strong guidance on when to prefer one over the other. In practice, this led to a common failure mode: the model would use write_file for small edits, rewriting hundreds or thousands of lines to change a few of them. The consequences were real β€” larger diffs made code review harder, token usage increased, and critical sections of code could be accidentally omitted or altered during reconstruction.

The Fix: Explicit Tool Guidance

v0.43.0 adds targeted guidance to both tool descriptions in the Gemini 3 model configuration. The write_file tool now explicitly recommends using replace for modifications to existing files, rather than overwriting them wholesale. The replace tool's description now calls it the "preferred tool for surgical edits," highlighting three concrete benefits: minimized token usage, simplified code reviews, and prevention of accidental deletions.

In parallel, a typo in the system prompt guidelines was fixed β€” read_file had been incorrectly cited where replace was meant, which could have caused subtle model confusion when interpreting tool selection guidance.

What Changes for Users

Developers using Gemini CLI to edit code in large files should notice a meaningful shift in behavior. When asked to update a function, fix a bug, or refactor a method, the model will now default to making targeted replacements rather than rewriting the whole file. The practical effects:

  • Smaller diffs: Only the changed lines appear in version control, not the entire file.
  • Lower token costs: The model sends and receives less data per edit operation.
  • Reduced risk: Lines of code the user did not ask to change remain untouched.
  • Cleaner reviews: Pull requests generated from Gemini CLI sessions become easier to read and approve.

Scope of the Change

The update applies specifically to the Gemini 3 model family tool descriptions in packages/core/src/tools/definitions/model-family-sets/gemini-3.ts and to the shared snippet guidance in packages/core/src/prompts/snippets.ts. It is a prompting and tool-description change, not a change to the underlying replace tool mechanics. The replace tool itself has not changed β€” only the guidance the model receives when deciding whether to use it.

This type of change β€” steering model behavior through improved tool descriptions rather than model retraining β€” demonstrates how much of Gemini CLI's practical edit quality is determined by prompt engineering at the tool definition layer.