Skip to content

fix(open_file): count a grown file, honor 'eventignorewin', and keep one terminal window - #396

Merged
ThomasK33 merged 4 commits into
mainfrom
fix/open-file-reload-edge-cases
Nov 1, 2026
Merged

ThomasK33 merged 4 commits into
mainfrom
fix/open-file-reload-edge-cases

Conversation

@ThomasK33

@ThomasK33 ThomasK33 commented Nov 1, 2026 •

Copy link
Copy Markdown
Member

Why

This PR is one of the small, reviewed fixes that close the open follow-up issues in claudecode.nvim (#393). It covers the four openFile items of #393 item 4, which came from #387.

  • A file that grew on disk while its buffer was loaded got -32602 startLine N is past the end of the file, although openFile loads the new text before it selects. Claude could not select a line it had just added.
  • With 'noautoread' and 'eventignorewin' (Neovim 0.11+) set to ignore FileChangedShell, openFile's :checktime made Neovim ask W11. The reply waited for the user's answer. The README said Neovim can still ask "in two cases", and this was a third.
  • An erroring user FileChangedShell or BufReadPost autocommand made openFile fail, and a BufReadPost error left the buffer half reloaded. The README did not say so.
  • With only a terminal, or a terminal and the preview window, preview = true left a second window on the terminal.

What changed

All code changes are in lua/claudecode/tools/open_file.lua.

  • startLine: for a loaded buffer without unsaved changes, openFile also counts the file on disk. When the buffer it then shows is shorter (the file shrank, or Neovim did not reload it), the selection is clamped to the last line, as before. A buffer with unsaved changes still counts only its own lines.
  • 'eventignorewin': openFile skips :checktime when 'eventignorewin' ignores FileChangedShell the way Neovim reads it (apply_autocmds_group()): the current window when it shows the buffer, else every window that shows it. While testing I found that the skip was too wide. With 'autoread', Neovim reloads a clean buffer without FileChangedShell, so 'eventignore' cannot make it ask. openFile now skips only with 'noautoread'. Before, 'eventignore' with 'autoread' left the old text.
  • Erroring user autocommands: documented, not changed. The error comes from the user's autocommand, and openFile reports it as :edit does. tools/README.md says what happens. openFile fails with that error, and the reload stops, unlike a :checktime the user types: the buffer keeps the old text. After a FileChangedShell error a later :w warns that the file changed. After a BufReadPost error two empty lines are added, Neovim takes the new file as read, and a later :w writes over it without a warning. Main does the same. Making openFile's reload finish like a typed :checktime is a follow-up.
  • Preview fallback: with preview and no editor window, openFile no longer splits the terminal. The preview window takes the file, and openFile makes one from the current window when the tab page has none.
  • lua/claudecode/tools/README.md describes the line count, the 'eventignorewin' rule, the autocommand errors, and the preview fallback. It now lists three cases where Neovim can still ask: FileChangedShell ignored for Neovim's own check when openFile shows the buffer in a new window, a user's autocommand that deletes openFile's, and W13 for a buffer opened before its file existed (W13 runs no FileChangedShell). The docs commit a0b4ee8 corrects statements an advisor pass found untrue.

Scope

  • When openFile shows the buffer in a window that did not show it, Neovim checks the file itself, and 'eventignore' or 'eventignorewin' can still make it ask. This is the documented first case, and main does the same.
  • W13 and the silent overwrite after an erroring BufReadPost are on main too. They are follow-ups.
  • With 'noautoread' and an ignored FileChangedShell, a buffer that a window already shows keeps the old text. openFile does not check it, so Neovim does not ask.

Blast Radius

openFile only. The line count changes only for a loaded buffer without unsaved changes, and only when startLine is past its last line. The :checktime skip changes only with 'eventignorewin' set, or 'eventignore' with 'autoread'. The fallback changes only with preview = true and no editor window.

Verification

  • Live with the verify-claudecode-nvim harness, Neovim 0.12.3, main against this PR:
    • 'noautoread' and setlocal eventignorewin=FileChangedShell, then Claude rewrites the shown file and calls openFile. On main the W11 dialog blocks the reply. Now the reply comes at once and nothing asks.
    • Claude adds lines 5 and 6, then calls openFile with startLine = 6. On main: -32602 startLine 6 is past the end of the file (4 lines). Now openFile answers Opened file and selected lines 6 to 6 and line 6 shows six from Claude.
  • Headless probe with 34 scenarios on Neovim 0.8.3, 0.9.5, 0.10.4 and 0.12.3, main against this PR. Fourteen scenarios differ, all as intended:
    • A grown file is shown, hidden, in the preview window, while the user types, and with 'noautoread': openFile now selects the new line.
    • 'eventignore' with 'autoread' now reloads.
    • A terminal with preview = true keeps one window, also with the preview window and with makeFrontmost = false.
    • With 'noautoread' and 'eventignorewin' set in the windows that show the buffer, main sets v:warningmsg to W11 (the question) in 4 scenarios on 0.12.3, and this PR in none.
    • The others match main: a buffer with unsaved changes still rejects the new line, and a shrunk file still clamps. The erroring FileChangedShell and BufReadPost autocommands give the same result as main and as vim.cmd("checktime") from Lua.
  • Earlier matrices on the same four versions, main against this PR: the fix(open_file): leave the user's window alone in the middle of a command #382 matrix matches in 1,856 of 1,856 runs. The fix(open_file,diff): never pick the preview window as the main editor window #384 window matrix matches in 416 of 416. The openFile probes from fix(open_file): keep the user's Visual mode, unsaved changes and focus #387 match in 60 of 60 scenarios, differing only in JSON key order.
  • An independent advisor pass found no code problem, but found README statements that were not true (which window's 'eventignorewin' Neovim reads, W13, and a typed :checktime). Commit a0b4ee8 corrects them.
  • Of the 11 new unit tests, 8 fail on their test commits and all pass with the fix. The other 3 pin rules that main already follows. mise run check, mise run test (963 passed, shuffled), and the integration suite on 0.8.3 and 0.12.3 (29 passed each) pass.

Before the fix, 'eventignorewin' makes openFile's check ask W11, and the reply waits:

Before: W11 dialog during openFile

After the fix, openFile selects line 6, which Claude just added:

After: line 6 selected

Part of #393


Generated with xum • Model: anthropic:claude-opus-5-5 • Thinking: xhigh

…lback gaps of #393

- A file that grew on disk while its buffer is loaded without unsaved
  changes gets -32602 for a startLine past the old end, although
  openFile loads the new text before it selects.
- With 'noautoread' and 'eventignorewin' set to ignore FileChangedShell
  in the windows that show the buffer, openFile's :checktime makes
  Neovim ask the user (W11).
- With only a terminal, or a terminal and the preview window,
  preview = true leaves a second window on the terminal.

The specs fail until the next commit. The preview mock now models
'eventignorewin' and reads the changed file, and the fallback mock
models the preview path.

_Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `xhigh`_
…nged file unread

With 'autoread', Neovim loads a changed file without FileChangedShell,
so 'eventignore' cannot make it ask. openFile still skips :checktime
then, and searches the old text. The new 'eventignorewin' case pins the
same rule. The preview mock now reads 'autoread' through getbufvar().

_Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `xhigh`_
…one terminal window

- startLine: for a loaded buffer without unsaved changes, openFile now
  also counts the file on disk, because it loads the file again when it
  changed. A startLine on a line Claude added is no longer -32602.
- openFile skips :checktime when 'eventignorewin' (Neovim 0.11+)
  ignores FileChangedShell, as Neovim reads it: the current window when
  it shows the buffer, else every window that shows it. With
  'noautoread', :checktime then asked the user (W11). With 'autoread',
  openFile now checks the file even when 'eventignore' or
  'eventignorewin' ignores the event, because Neovim then loads it
  without FileChangedShell and does not ask.
- With preview and no editor window, the fallback no longer splits the
  terminal: the preview window takes the file, so the second window on
  the terminal is gone.

tools/README.md now names the 'eventignorewin' rule, the grown-file
count, and what an erroring user FileChangedShell or BufReadPost
autocommand does during a reload (openFile fails, as :checktime does,
and the buffer keeps the old text).

_Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `xhigh`_
@ThomasK33

Copy link
Copy Markdown
Member Author

@codex review

@ThomasK33

Copy link
Copy Markdown
Member Author

@codex security review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 1, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-01T11:08:47.219995Z a0b4ee8 Manual request
🔒 Security Review ✅ Completed 2026-11-01T11:08:43.533306Z a0b4ee8 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review

Security review completed. No security issues were found in this pull request.

Reviewed commit: e4d37dc869

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep it up!

Reviewed commit: e4d37dc869

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

…d file

The advisor pass found statements in tools/README.md that do not hold:

- 'eventignorewin' for a hidden buffer is Neovim's own check, not a
  rule openFile applies. The README now names the rule openFile uses
  for a window that already shows the buffer, and says that Neovim
  decides for a window that did not show it.
- A buffer opened while its file did not exist gets W13, which runs no
  FileChangedShell. That is a third case.
- An Ex `:checktime` that the user types finishes the reload despite an
  erroring BufReadPost autocommand. openFile's call from Lua stops it.
  After a FileChangedShell error a later `:w` still warns. After a
  BufReadPost error it does not.

_Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `xhigh`_
@ThomasK33

Copy link
Copy Markdown
Member Author

@codex review

@ThomasK33

Copy link
Copy Markdown
Member Author

@codex security review

@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review

Security review completed. No security issues were found in this pull request.

Reviewed commit: a0b4ee8c97

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🚀

Reviewed commit: a0b4ee8c97

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@ThomasK33
ThomasK33 added this pull request to the merge queue Nov 1, 2026
Merged via the queue into main with commit 0fa2832 Nov 1, 2026
6 checks passed
@ThomasK33
ThomasK33 deleted the fix/open-file-reload-edge-cases branch November 1, 2026 11:31
ThomasK33 added a commit that referenced this pull request Nov 1, 2026
…, #397, #399

check.sh --mutants caught every guard on the tree merged with #394. This merge
changes no fact (all 21 read TRUE) and not the model, so the mutant result
holds. check.sh passes.

_Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `xhigh`_
ThomasK33 added a commit that referenced this pull request Nov 1, 2026
Besides server/client.lua and server/frame.lua, the record takes in the
selection.lua, tools/open_file.lua and visual_commands.lua changes from
#396 and #397, which main had not recorded. None of them reaches diff
state, an openDiff answer, a disconnect or a diff command: the only diff
word in them is open_file's check of a window's 'diff' option.

Part of #393

_Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `xhigh`_
@github-actions github-actions Bot mentioned this pull request Nov 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant