Skip to content

feat(core): steer model to prefer replace over write_file for existing files #24713

@genneth

Description

@genneth

What happened?

The model frequently uses write_file to rewrite entire files when a targeted replace call would be more appropriate. This leads to unnecessary full-file rewrites that are:

The root cause appears to be in the tool descriptions rather than the tool implementations. The write_file tool description contains no guidance about when it should or shouldn't be used. Meanwhile, the replace tool description is ~300 words of strict requirements (3+ lines of context, exact literal matching, mandatory instruction parameter), which may discourage the model from choosing it.

What did you expect to happen?

The model should strongly prefer replace for modifying existing files and only use write_file for creating new files or complete rewrites where the majority of the file content is changing.

Suggested fix

Add steering text to the write_file tool description, something like:

"Prefer the replace tool for modifying existing files. Only use write_file to create new files or for complete rewrites where most of the content is changing."

This is a low-risk, prompt-only change that doesn't require any code modifications to tool implementations. It could also be reinforced in the system prompt snippets (snippets.ts).

Additionally, consider simplifying the replace tool description to reduce friction — the current description's strict tone may push the model toward the "safer" write_file path.

Related issues

Environment

N/A — this is a prompt/tool description change, not environment-specific.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/agentIssues related to Core Agent, Tools, Memory, Sub-Agents, Hooks, Agent Qualitystatus/need-triageIssues that need to be triaged by the triage automation.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions