Skip to content

Plugin cannot update FileTime after modifying files, causing "file modified since last read" errors #11249

Closed

Description

@schneiderlin

Problem
When a plugin uses the tool.execute.after hook to modify files (e.g., running a formatter), subsequent write/edit operations on the same file fail with:

Error: File xxxxx has been modified since it was last read.
Last modification: 2026-01-30T03:53:46.637Z
Last read: 2026-01-30T03:53:35.616Z
Please read the file again before modifying it.

This happens even when the plugin has already read the file via the SDK client.

Root Cause

  1. The plugin receives ctx.client which is an SDK client instance
  2. The plugin can call ctx.client.read() to fetch file content after modifying it
  3. However, calling ctx.client.read() does NOT update the FileTime tracking for the session
  4. FileTime state is managed internally and only updated by the Read/Write/Edit tools themselves
  5. Without a way for plugins to update FileTime, any external file modifications invalidate the timestamp tracking

Reproduction Steps

  1. Create a plugin that modifies files in tool.execute.after:
  2. Configure opencode to load this plugin
  3. Open opencode and run: "Write a dummy file"
  4. Plugin modifies the file after write completes
  5. Error: "File has been modified since it was last read"

Current Workaround
Plugins can use the environment variable to disable FileTime checks:
export OPENCODE_DISABLE_FILETIME_CHECK=1
opencode
However, this:

  • Disables ALL file modification safety checks
  • Not plugin-specific (affects entire session)
  • Reduces safety for concurrent edits

Activity

  1. github-actions commented on Jan 30, 2026

    @github-actions
    Contributor

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

    Feel free to ignore if this doesn't fully address your specific case.

  2. github-actions commented on Apr 1, 2026

    @github-actions
    Contributor

    To stay organized issues are automatically closed after 90 days of no activity. If the issue is still relevant please open a new one.

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