beforeFileRead hook not invoked if file is open

Where does the bug appear (feature/product)?

Cursor IDE

Describe the Bug

The beforeReadFile hook doesn’t get invoked if the file being read is open in the UI.

Steps to Reproduce

  • Open any project file in the UI and ask the agent to summarise its contents
  • Close the file, start a new chat and ask the agent to summarise its contents
  • Look at the Hooks Execution Logs, you will see that the hook was only invoked when the file was closed

Expected Behavior

The beforeReadFile hook is invoked when the read file tool is used, regardless of whether or not the file is open in the UI.

Operating System

MacOS

Version Information

Version: 3.3.30
VSCode Version: 1.105.1
Commit: 3dc559280adc5f931ade8e25c7b85393842acf30
Date: 2026-05-09T18:28:42.332Z
Layout: editor
Build Type: Stable
Release Track: Default
Electron: 39.8.1
Chromium: 142.0.7444.265
Node.js: 22.22.1
V8: 14.2.231.22-electron.0
OS: Darwin arm64 25.3.0

Does this stop you from using Cursor

No - Cursor works, but with this issue

Hey, thanks for the report. I can reproduce it: when a file is open in the editor, the agent reads the content directly from the in-memory buffer and bypasses the layer where beforeReadFile is registered. When the file is closed, reads go through the exec-daemon and the hook fires correctly. So this isn’t a false negative in the logs, it’s a real bypass path in the renderer.

I’ve reported this internally to the team. I can’t share an ETA for a fix yet.

As a temporary workaround, if you need the hook for security scenarios like blocking .env, add sensitive patterns to .cursorignore. Then the agent won’t see the file at all, whether it’s open or not:

# .cursorignore
.env
.env.*

It’s not a replacement for the hook, but it will close the gap until there’s a fix.

Thanks Dean, appreciated.