You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[FEATURE]: Optional read-before-write precondition for edit/write tools #33089
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:
Track which files have been read in the current session
Before allowing edit/write on a file, check if it was read first
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:
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.
Activity
github-actions commentedon Jun 20, 2026
This issue might be a duplicate of existing issues. Please check:
tools.edit.require_prior_read) — nearly identical in scope and proposed implementation.isReadOnly/isDestructiveflags to the tool interface, which is part of the broader safety classification problem this issue addresses.Please review those issues to see if your request is already covered before this proceeds.
Necmttn commentedon Jun 21, 2026
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.
rekram1-node commentedon Jun 22, 2026
STOP SPAMMING ISSUES.