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

Open
opened 2026-02-16 18:08:55 -05:00 by yindo · 1 comment
Owner

Originally created by @schneiderlin on GitHub (Jan 29, 2026).

Originally assigned to: @thdxr on GitHub.

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
Originally created by @schneiderlin on GitHub (Jan 29, 2026). Originally assigned to: @thdxr on GitHub. 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
Author
Owner

@github-actions[bot] commented on GitHub (Jan 29, 2026):

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

  • #5840: [Tracking] Edit tool reliability: "modified since last read" errors - This is a broader tracking issue for the same FileTime validation error that occurs when files are modified externally (including by plugins)

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

@github-actions[bot] commented on GitHub (Jan 29, 2026): This issue might be a duplicate of existing issues. Please check: - #5840: [Tracking] Edit tool reliability: "modified since last read" errors - This is a broader tracking issue for the same FileTime validation error that occurs when files are modified externally (including by plugins) Feel free to ignore if this doesn't fully address your specific case.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#8012