Skip to content

[BUG]: write.txt and edit.txt claim read-before-edit enforcement that does not exist in code #30771

Closed

Description

Description

The tool description files packages/opencode/src/tool/write.txt (line 5) and packages/opencode/src/tool/edit.txt (line 4) claim that the tools will fail/error if the AI attempts to write/edit a file without reading it first, but neither tool has any enforcement of this requirement.

write.txt line 5

If this is an existing file, you MUST use the Read tool first to read the file's contents. This tool will fail if you did not read the file first.

edit.txt line 4

You must use your Read tool at least once in the conversation before editing. This tool will error if you attempt an edit without reading the file.

Neither packages/opencode/src/tool/write.ts nor packages/opencode/src/tool/edit.ts implements any runtime check that the target file was previously read via the Read tool. The AI can call write or edit on any file without ever calling Read, and the tools will execute successfully.

Additionally, packages/core/src/fs-util.ts lines 100-118 implements writeWithDirs, which auto-creates parent directories on write. If the AI mistypes a path (e.g., src/utls/helper.ts instead of src/utils/helper.ts), a wrong directory tree is silently created with no warning to the AI. Combined with the lack of read-before-write enforcement, this means an AI can accidentally write a new file to a wrong path without ever reading the intended target.

Consolidated finding (merged from closed #30780):

AGENTS.md files loaded via instruction.ts:210 inject content into system-reminder tags with no sanitization. The system prompt (default.txt:78, anthropic.txt:75) tells AI that system-reminder tags are authoritative. If AGENTS.md contains instructions contradicting tool descriptions (e.g., "edit without reading"), there is no precedence mechanism to resolve the conflict. This extends the false-claim problem: even if tool descriptions said the right thing, AGENTS.md could override them.

Plugins

N/A (source code analysis)

OpenCode version

main

Steps to reproduce

  1. Read source code at packages/opencode/src/tool/write.txt and packages/opencode/src/tool/edit.txt
  2. Note the false enforcement claims
  3. Read write.ts and edit.ts — no runtime check exists
  4. Also note writeWithDirs in fs-util.ts creates parent dirs silently

Screenshot and/or share link

N/A (we read the source code)

Operating System

N/A (code analysis, not environment-specific)

Terminal

N/A

Activity

  1. github-actions commented on Jun 4, 2026

    @github-actions
    Contributor

    This issue might be a duplicate of existing issues. Please check:

    The core finding here (misleading enforcement text in write.txt/edit.txt) appears to be already documented in #30376. You may want to add any new details there rather than tracking separately.

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