Skip to content

[FEATURE]: Optional read-before-write precondition for edit/write tools #33089

Closed as not planned

Description

  • I have verified this feature I'm about to request hasn't been suggested before.

Describe the enhancement you want to request

Currently, the model can call edit/write/bash on a file without ever having read that file first. This allows the AI to act on partial context (e.g., a grep summary) and make incorrect edits.

I propose adding an optional read-before-write precondition to the tool runtime. The system would:

  1. Track which files have been read in the current session
  2. Before allowing edit/write on a file, check if it was read first
  3. If not read, require the model to read it first or get explicit user permission

This could be implemented in the existing tool.execute.before plugin hook (session/tools.ts), which already exists but is unused for safety checks. The hook would:

  • Check if the target file was read in this session
  • If not, either block the edit or append a warning to the tool output

An opt-in configuration in opencode.json would let users enable this:

{
  safety: {
    requireReadBeforeEdit: true
  }
}

About the duplicate flag: This is different from:

Activity

  1. github-actions commented on Jun 20, 2026

    @github-actions
    Contributor

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

    Please review those issues to see if your request is already covered before this proceeds.

  2. Necmttn commented on Jun 21, 2026

    @Necmttn

    Read-before-write works best as a receipt, not only a boolean. Track file read receipts by resolved path, inode/mtime or content hash, read offset/range, session id, and turn id; invalidate the receipt when the file changes externally.

    Then a write guard can say "blocked: no current read receipt for this file" or "warning: read is stale." That avoids a model satisfying the rule with an old grep summary or a read from a different path alias.


    Generated with ax.

  3. rekram1-node commented on Jun 22, 2026

    @rekram1-node
    Contributor

    STOP SPAMMING ISSUES.

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