Skip to content

write.ts: no pre-read check before writing, silently overwrites existing files #30864

Closed

Description

Description

File: packages/core/src/tool/write.ts:67

return yield* files.writeTextPreservingBom({ plan, content: parameters.content })

No pre-existence check. After compaction/pruning (long sessions), AI loses memory of file contents and may write to an existing file, silently overwriting user code.

V1 had a create tool with flag: "wx" that rejected existing files, and a separate write tool. V2 merged them into one write tool that overwrites unconditionally.

Fix: Add a pre-read guard that fails the tool when the file already exists, forcing the AI to use edit instead.

OpenCode version

v1.16.0 (commit 3cf1cef)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions