Project open writes a newline into empty __init__.py files (files.insertFinalNewline is false)

Where does the bug appear (feature/product)?

Cursor IDE

Describe the Bug

About two seconds after the window starts, each previously opened empty init.py is saved as 1 byte (0a). Other empty init.py files in the same repo stay 0 bytes.

Steps to Reproduce

Use a Git repo that contains empty init.py files (0 bytes), already committed.
Open a few of them in Cursor once, in any earlier session.
User settings:

“files.insertFinalNewline”: false,
“files.trimFinalNewlines”: true
Close every editor tab.
Restore the files from another terminal:

git restore – path/to/init.py
Quit Cursor and open the same project again.

Expected Behavior

A 0-byte file stays 0 bytes. Should stop a newline from being added.

Screenshots / Screen Recordings

Operating System

MacOS

Version Information

Cursor version: 3.25.6 (Universal)

Additional Information

Still happening on 3.25.6, after the fix staff described for 2.3 in Cursor adds newline to files with existing newlines

No tabs were open. files.insertFinalNewline is false. files.trimFinalNewlines is true. files.hotExit off did not stop it. PyCharm “Ensure every saved file ends with a line break” is unchecked.

After git restore, the files were 0 bytes. The window started at 12:03:29. At 12:03:32, 6 of the empty init.py files were each 1 byte, 0a. Cursor did not ask to save. The other 348 empty init.py files in the same repo stayed 0 bytes. The 6 had been opened in an earlier session.

Same write on earlier restarts at 11:26:49 and 11:38:22.

The added newline makes the file fail pycodestyle W391 (blank line at end of file). PyCharm treats that as an error and blocks the commit. These files are package markers and are stored in Git as 0 bytes, which does not trigger W391.

Does this stop you from using Cursor

No - Cursor works, but with this issue

Hey @Stepan_Gharslyan, thanks for the report and the timestamps, that makes this much easier to pin down.

What you’re seeing comes from Cursor restoring leftover Agent edits on startup. If an Agent touched a file in an earlier session and that change was never accepted or rejected, Cursor keeps that review state and re-applies it when the window opens, then writes the file. That write skips your save settings, which is why files.insertFinalNewline and files.trimFinalNewlines have no effect. It also explains why only those 6 files are affected and not the other 348. I’ve flagged this to the team.

To stop it for those files, you can clear the leftover review state:

  1. Open Cursor on the project (the 6 files will get the newline again, that’s fine).
  2. Open one of the 6 init.py files.
  3. If you see Keep / Undo controls in the editor (or the file is listed in the Agent’s review panel), click Keep for that file.
  4. Repeat for the other 5 files.
  5. Run git restore on the 6 files from your terminal.
  6. Quit Cursor fully and open the project again.

Could you let me know:

  • Whether the 6 files stay at 0 bytes after step 6
  • Whether you saw Keep / Undo controls (or a review list entry) on those files in step 3
  • Whether an Agent created or edited those files at some point, or if you only opened them yourself

Undo and Save cleared the 6 files. I did not see Keep / Undo. I opened each one, pressed Cmd+Z, closed the tab, and chose Save. After a restart they stayed at 0 bytes.

I am not sure it will stay that way. The newline came back on earlier restarts, and colleagues on this repo see the same thing on empty init.py files. A per-file undo is hard to ask of everyone. If the startup write can ignore files.insertFinalNewline, a real fix would help us a lot.