Skip to content

fix(open_file): never let Neovim ask W13 or W11, and finish a reload that an autocommand fails in - #408

Merged
ThomasK33 merged 17 commits into
mainfrom
fix/open-file-reload-questions
Nov 1, 2026
Merged

ThomasK33 merged 17 commits into
mainfrom
fix/open-file-reload-questions

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 (#401). It covers the three openFile reload items of #401 item 3, which came from #396.

  • W13 loses unsaved text. The user opens new.txt before it exists and types in it without saving. Claude then creates the file and calls openFile. Neovim asks W13 ("File has been created after editing started"), which runs no FileChangedShell, so openFile's autocommand cannot answer it. The dialog holds the reply. The user's next l answers "Load File", which replaces the user's text with Claude's file. While the user types in another file, the dialog first eats the keys before l (live on 0.12.3: hello became lo).
  • A failing user BufReadPost autocommand stopped openFile's reload halfway, because an error inside a command run from Lua aborts it. The buffer kept the old text plus two empty lines, but Neovim took the new file as read, so a later :w wrote that text over Claude's file without a warning.
  • W11 on entering a buffer. When openFile showed a loaded buffer in a window that did not show it, and 'eventignore', or 'eventignorewin' of the windows that show it, ignored FileChangedShell, Neovim's own check asked W11 (or W12 for unsaved changes).

What changed

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

  • openFile tracks buffers that Neovim opened before their file existed: BufNewFile marks a buffer, and reading it, writing its own file, or unloading it clears the mark. When the module loads, it also marks loaded buffers whose file is missing. Such a buffer is shown with Neovim's check turned off ('buftype' is acwrite for that one step, because Neovim checks only normal buffers, and acwrite keeps 'modified' as it is). Without unsaved changes openFile then reads the file with :edit, as W13's "Load File" does. With unsaved changes it keeps them, and a later :w fails with E13 until :w!. The one exception is Visual or Select mode that CTRL-O started (Neovim 0.10+): :edit would end it, so the buffer keeps its text.
  • The same step runs when 'eventignore', or 'eventignorewin' of the target window or of a window that shows the buffer, ignores FileChangedShell. openFile then checks the file itself, with the rules it already used for a window that shows the buffer.
  • openFile runs a reload (:checktime or the :edit above) as before. When the command fails after the reload began (BufReadPre fired), the buffer reads its file again under :silent!, which lets the read end as a typed :checktime does, and then openFile fails with the error. Only this failure path uses :silent!, because under it v:errmsg also holds errors that autocommands hide on purpose, and pcall() inside autocommands returns true for errors. Before it shows a hidden buffer, openFile checks the file, so no reload runs inside the enter. An error from that check is raised after the file is shown.
  • A buffer whose 'buftype' is set is shown as it is: Neovim never checks its file.
  • lua/claudecode/tools/README.md describes the new rules. It now names one case where Neovim can still ask: a user's FileChangedShell autocommand that deletes openFile's.
  • tests/unit/tools_spec.lua and tests/server_test.lua mock the autocommand API, because openFile creates its BufNewFile autocommands when it loads.

Scope

  • With 'noautoread' and FileChangedShell ignored for the windows that show the buffer, the buffer still keeps the old text. No dialog appears. This is unchanged from fix(open_file): count a grown file, honor 'eventignorewin', and keep one terminal window #396.
  • openFile tracks new-file buffers from the time the Claude Code server starts. A buffer opened earlier counts only if its file was still missing then. Claude creates files while connected, so the file is missing at that time.
  • An erroring user autocommand still fails openFile, as before. The difference is that the reload finishes first.
  • Two cases still behave as on main: with BufNewFile in 'eventignore' when the buffer is made, openFile does not know the buffer, and Neovim can ask W13. With BufReadPre in 'eventignore', a failing BufReadPost leaves the half-read buffer.
  • A buffer that a BufWriteCmd handler saved still counts as new, so a later openFile reads its file again with :edit when it has no unsaved changes.

Blast Radius

openFile only, and only for loaded buffers:

  • A hidden buffer whose file changed is reloaded before it is shown. Its BufReadPost then runs in Neovim's autocommand window, as it already did for the :edit path.
  • For the buffers that need the step, autocommands that run while openFile shows the buffer see 'buftype' set to acwrite.

Verification

  • Live with the verify-claudecode-nvim harness, Neovim 0.12.3: the user opens new.txt before it exists and types MY NOTES, then Claude creates new.txt and calls openFile.
    • Normal mode, main: the W13 dialog blocks the reply, and the user's l replaces MY NOTES with Claude's text. This PR: the reply comes at once, and MY NOTES stays (modified).
    • While the user types hello in hello.txt, main: the dialog eats he, and l loads the file. This PR: the reply comes at once, hello is typed in full, and MY NOTES stays.
    • Nothing typed in new.txt, main: the dialog asks first. This PR: openFile loads Claude's text and selects it without asking.
  • Headless probe, 63 scenarios on Neovim 0.8.3, 0.9.5, 0.10.4 and 0.12.3:
    • Main gets a Neovim question (v:warningmsg W11, W12 or W13) in 63 runs. This PR gets none.
    • The scenarios that differ from main are all intended: the W13 cases (hidden, shown, preview, in another tab, with 'winfixbuf', while typing, CTRL-O Visual, a preview window an autocommand closes), the erroring BufReadPost cases, and the 'eventignore' and 'eventignorewin' enter cases. A markdown reload (Neovim's ftplugin hides an E31 itself), a user's silent! autocommand, pcall() inside an autocommand, an erroring FileChangedShell, and an acwrite buffer behave as on main.
    • In the erroring BufReadPost cases, main leaves one|two|| and its :w writes that text over the file. This PR leaves the whole file, and :w writes it unchanged.
  • Earlier verifier matrices, 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 in 416 of 416, and the fix(open_file): keep the user's Visual mode, unsaved changes and focus #387 openFile probes in 60 of 60 (only JSON key order differs).
  • Review round 1: Codex found that the 'nowrite' step reset a set 'buftype' to empty, and that a closed preview window gave an invalid-window error. An independent advisor pass found that the :silent! reload failed openFile on a normal markdown reload. All three are fixed in f678bc1, with tests that fail on c8f657a against the old code.
  • Review round 4: Codex found that when an autocommand shows another buffer in the window, the :edit for a new file's buffer re-reads that other buffer, and empties a 'nofile' buffer. Real Neovim 0.8.3 to 0.12.3 confirm it: main keeps a dashboard buffer's text, 027526d empties it. 9f7a91c runs :edit only while the window shows the buffer, with two tests that fail on dc51d9b. The 63-scenario probe matches f678bc1 in 240 of 244 runs. The other 4 differ only in JSON key order.
  • Review round 5: Codex found that the new BufWritePost autocommand fails with "Invalid buffer id" when an earlier BufWritePost autocommand wipes the buffer. Real Neovim 0.8.3 to 0.12.3 confirm it: :w writes the file and then reports the error. 0b18f59 checks that the buffer is valid, with a test that fails on beef9de.
  • Independent verifier: the step first set 'buftype' to nowrite, and Neovim reads 'modified' as off for a nowrite buffer. A user's autocmd BufEnter new.txt if !&modified | edit | endif then dropped the unsaved text without a dialog. Main asks W13 or W12 there. ca68d1b uses acwrite, which Neovim also does not check and which keeps 'modified'. Real Neovim 0.8.3 to 0.12.3, 64 runs with four user autocommands: 8113819 drops the text in 48 runs, ca68d1b keeps it in all 64, and no run asks. Four unit tests fail on 30c7166.
  • Tests: the 14 new unit tests fail on the test commit 2076fe4 and pass with the fix. mise run check, mise run test (1014 passed, shuffled, after merging main), and the integration suite (49 passed on 0.8.3, 58 passed on 0.12.3) all pass.
  • covered.lock: the covered-lock check read STALE on the file lua/claudecode/tools/open_file.lua line only. No block or call site changed. This change cannot reach diff state, an openDiff answer, a disconnect or a diff command: open_file.lua does not load the diff modules, the proposal buffers are acwrite scratch buffers that openFile shows as they are, and an accepted diff leaves the file's buffer modified, which openFile never reloads. check.sh passes on this tree (every code fact TRUE, 89,205 and 5,269 states), and 7315aeb re-records the lock.

Before the fix, W13 blocks the reply, and the user's next l loads the file over the unsaved text:

Before: W13 dialog during openFile

After the fix, openFile answers at once and the unsaved text stays:

After: MY NOTES kept

Part of #401


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

…401

- A buffer opened before its file existed (Neovim fires BufNewFile)
  makes Neovim ask W13 once Claude creates the file, when openFile
  shows it or checks it. The reply waits, and the user's next `l`
  loads the file and drops the text the user typed there.
- A failing user BufReadPost autocommand stops openFile's reload
  halfway: the buffer keeps the old text with two empty lines.
- When the buffer is shown only in windows whose 'eventignorewin'
  ignores FileChangedShell, or 'eventignore' ignores it, Neovim's own
  check as openFile shows the buffer in another window asks W11.

The specs fail until the next commit. The module now loads after the
mocks, and the preview mock models BufNewFile and W13, 'buftype',
:silent!, a failing BufReadPost, and the check :edit makes before it
switches buffers.

_Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `xhigh`_
…that an autocommand fails in

- W13: openFile now tracks buffers that Neovim opened before their file
  existed (BufNewFile, until the buffer is read or written). W13 runs
  no FileChangedShell, so openFile shows such a buffer with Neovim's
  check turned off ('buftype' nowrite for that step). Without unsaved
  changes it then reads the file with :edit. With unsaved changes it
  keeps them, and a later :w fails with E13. Before, the W13 dialog
  held the reply, and the user's next `l` loaded the file and dropped
  the text the user typed.
- W11: when 'eventignore', or 'eventignorewin' of the target window or
  of a window that shows the buffer, can make Neovim skip FileChangedShell
  as a window gets the buffer, openFile turns that check off too and
  checks the file itself afterwards.
- Reloads run under :silent!, so a failing user BufReadPost autocommand
  no longer stops them halfway with wrong text that a later :w writes
  over Claude's file without a warning. openFile checks a hidden
  buffer's file before it shows it, so no reload runs inside the enter,
  and it raises the autocommand's error after the file is shown.

tools/README.md describes the new rules. tools_spec and server_test
mock the autocommand API that openFile now uses when it loads.

_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-01T13:59:20.917007Z 8113819 Manual request
🔒 Security Review ✅ Completed 2026-11-01T14:00:04.969580Z 8113819 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: 7c67f20a80

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 chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7c67f20a80

ℹ️ 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".

Comment thread lua/claudecode/tools/open_file.lua Resolved
Comment thread lua/claudecode/tools/open_file.lua Resolved
- Neovim's markdown ftplugin hides an E31 with `sil! nunmap` while a
  file reloads, which leaves the error in v:errmsg, and openFile fails
  on it although nothing went wrong.
- A buffer whose 'buftype' is set, which Neovim never checks, gets an
  empty 'buftype' after openFile turned Neovim's check off for it.
- An autocommand that closes the preview window as it gets a buffer
  opened before its file existed makes openFile fail with a raw
  invalid-window error instead of "No preview window shows the file".

The specs fail until the next commit. The preview mock now fires
BufReadPre, keeps the file readable after a read, models an error an
autocommand hides itself, and refuses an invalid window in
nvim_win_call.

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

- openFile runs a reload as before, not under :silent!. Under the
  outer :silent!, v:errmsg also held errors that autocommands hid on
  purpose (Neovim's markdown ftplugin runs `sil! nunmap`), so openFile
  failed on a normal reload, and pcall() inside autocommands returned
  true for errors. Now only when the reload command fails after the
  reload began (BufReadPre fired) does the buffer read its file again
  under :silent!, so it gets the whole file, and then openFile fails
  with the error.
- A buffer whose 'buftype' is set is shown as it is: Neovim does not
  check its file, so openFile neither turns that check off, which
  reset 'buftype' to empty, nor checks it itself.
- When an autocommand closes the window as it gets the buffer, openFile
  skips its own check, so the preview path fails with "No preview
  window shows the file" instead of an invalid-window error.

_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 Review: Didn't find any major issues. 🎉

Reviewed commit: f678bc1a45

ℹ️ 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".

@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review

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

Reviewed commit: f678bc1a45

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.

The covered-lock check read STALE on one line only:
`file lua/claudecode/tools/open_file.lua`. No block or call site changed.

The openFile change cannot reach diff state, an openDiff answer, a
disconnect or a diff command. open_file.lua does not load the diff
modules. Each proposal buffer is an 'acwrite' scratch buffer with its own
name, and openFile shows a buffer with a special 'buftype' as it is. The
diff does not watch the file's own buffer, and an accepted diff leaves
that buffer modified, which openFile never reloads.

check.sh on this tree: every code fact TRUE, main 89205 states pass,
live 5269 states pass.

---
_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 Review: Didn't find any major issues. Hooray!

Reviewed commit: faa2f18f5f

ℹ️ 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".

@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review

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

Reviewed commit: faa2f18f5f

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.

…questions

# Conflicts:
#	.agents/skills/verify-diff-lifecycle/covered.lock
The covered-lock check read STALE on one line only:
`file lua/claudecode/tools/open_file.lua`. No block or call site changed.

The openFile change cannot reach diff state, an openDiff answer, a
disconnect or a diff command. open_file.lua does not load the diff
modules. Each proposal buffer is an 'acwrite' scratch buffer with its own
name, and openFile shows a buffer with a special 'buftype' as it is. The
diff does not watch the file's own buffer, and an accepted diff leaves
that buffer modified, which openFile never reloads.

check.sh on this tree (main at f9f0c64 merged): every code fact TRUE, main 89205 states pass,
live 5269 states pass.

---
_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: 027526d09b

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 chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 027526d09b

ℹ️ 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".

Comment thread lua/claudecode/tools/open_file.lua Resolved
Comment thread lua/claudecode/tools/open_file.lua Resolved
Comment thread lua/claudecode/tools/open_file.lua Resolved
When a BufEnter or BufWinEnter autocommand shows another buffer in the
window that gets a buffer opened before its file existed, openFile runs
a bare :edit in that window. :edit re-reads the other buffer, and it
empties a 'nofile' buffer such as a plugin's dashboard. Both tests fail
on this commit. Real Neovim 0.8.3 and 0.12.3 show the same: main keeps
the dashboard text, the branch empties it.

---
_Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `xhigh`_
openFile read the file into a buffer opened before its file existed
with a bare :edit in the window that got the buffer. When an autocommand
had shown another buffer in that window, :edit re-read that buffer
instead, and emptied a 'nofile' buffer. openFile now runs :edit only when
the window still shows the buffer. Otherwise the buffer keeps its text,
as on main.

---
_Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `xhigh`_
The covered-lock check read STALE on the
`file lua/claudecode/tools/open_file.lua` line only. The new check makes
openFile run :edit less often. It cannot reach diff state, an openDiff
answer, a disconnect or a diff command. check.sh: every code fact TRUE,
main 89205 states pass, live 5269 states pass.

---
_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: 02d079847c

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 chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 02d079847c

ℹ️ 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".

Comment thread lua/claudecode/tools/open_file.lua Resolved
Comment thread lua/claudecode/tools/open_file.lua Resolved
…e buffer

openFile's BufWritePost autocommand asks for the name of the buffer. When
an earlier BufWritePost autocommand wipes it (`autocmd BufWritePost *.tmp
bwipeout`), Neovim still runs openFile's, and the call fails with
"Invalid buffer id". The file is written, but :w reports the error. Real
Neovim 0.8.3 and 0.12.3 show it. The new test fails on this commit.

---
_Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `xhigh`_
openFile's BufWritePost autocommand now checks that the buffer is still
valid before it asks for its name. An earlier BufWritePost autocommand
that wipes the buffer no longer turns a finished :w into an "Invalid
buffer id" error. The BufUnload autocommand already forgot the buffer.

---
_Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `xhigh`_
The covered-lock check read STALE on the
`file lua/claudecode/tools/open_file.lua` line only. The change guards
openFile's own new-file tracking and cannot reach diff state, an openDiff
answer, a disconnect or a diff command. check.sh: every code fact TRUE,
main 89205 states pass, live 5269 states pass.

---
_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 Review: Didn't find any major issues. Keep it up!

Reviewed commit: 81138190e8

ℹ️ 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".

@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review

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

Reviewed commit: 81138190e8

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.

While openFile shows a buffer with Neovim's file check turned off, it
sets the buffer's 'buftype' to nowrite. Neovim reads 'modified' as off
for a nowrite buffer. So a user's
`autocmd BufEnter new.txt if !&modified | edit | endif` loads the file
again and drops the unsaved text, without a dialog. This happens for a
buffer opened before its file existed, and for a changed file when
'eventignore' ignores FileChangedShell. Main asks W13 or W12 and keeps
the text unless the user answers `l`.

The mock now runs BufEnter autocommands when a window enters a buffer,
and reads 'modified' as Neovim does for nofile, nowrite, terminal and
prompt buffers. The four new tests fail on this commit. A real-Neovim
script loses "USER TYPED" in 16 of 16 runs on 0.8.3 and 0.12.3.

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

While openFile shows a buffer with Neovim's file check turned off, it now
sets 'buftype' to acwrite instead of nowrite. Neovim checks the file of
neither, but it reads 'modified' as off for a nowrite buffer. A user's
`autocmd BufEnter new.txt if !&modified | edit | endif` then loaded the
file again and dropped the unsaved text. With acwrite, 'modified' stays
on, and the unsaved text stays.

Real Neovim 0.8.3, 0.9.5, 0.10.4 and 0.12.3, 64 runs (a buffer opened
before its file existed, or a changed file with 'eventignore' set to
FileChangedShell; four user autocommands; window and preview): 8113819
drops "USER TYPED" in 48 runs, this commit keeps it in all 64, and no
run asks.

---
_Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `xhigh`_
The covered-lock check read STALE on the
`file lua/claudecode/tools/open_file.lua` line only. The change sets a
different 'buftype' on the file's own buffer while openFile shows it. It
cannot reach diff state, an openDiff answer, a disconnect or a diff
command. check.sh: every code fact TRUE, main 89205 states pass, live
5269 states pass.

---
_Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `xhigh`_
@ThomasK33
ThomasK33 added this pull request to the merge queue Nov 1, 2026
Merged via the queue into main with commit a067325 Nov 1, 2026
7 checks passed
@ThomasK33
ThomasK33 deleted the fix/open-file-reload-questions branch November 1, 2026 14:49
@github-actions github-actions Bot mentioned this pull request Nov 1, 2026
hareki pushed a commit to hareki/claudecode.nvim that referenced this pull request Nov 4, 2026
…-nvim (coder#435)

## Why

This PR is one of the small, reviewed changes that apply the approved
/reflect lessons to claudecode.nvim. It adds five lessons to the live
verification skill, so an agent checks the paths that headless runs and
the `none` provider hide.

## What changed

- `SKILL.md`: the description also triggers for bug reproductions and
for changes that can raise a prompt or change the mode. A proof now
types the user's next keys after such a call. Launch notes the
`messagesopt` flag for debug runs, with the Neovim 0.8 form. A new
section checks the real Claude CLI handshake.
- `features/open-file.md`: four Neovim buffer-state gotchas, and a step
that repeats write and reload changes under three common user configs,
on main and on head.
- `features/send-at-mention.md`: a send lane with a real terminal
(native or snacks), and a sharper `none` provider gotcha.

## Scope

- Docs only. No plugin code, no harness script.
- coder#423 is not addressed here. The new lane reproduces it, see
Verification.

## Blast Radius

Only agents that run this skill read these files. Every new command was
run as written.

## Verification

All runs used real Neovim through `vcn.sh` (0.12.3 unless named) or
headless `nvim -u NONE`.

- Prompt check: on main before coder#408 (f9f0c64), headless openFile
answered W13 at once and kept `MY NOTES`. Live, the reply did not come
within 2 s, and the user's `l` loaded `claude text`. On this head, the
reply came at once and `MY NOTES` stayed.
- Debug launch: without the flag, one openDiff at debug level parked
0.12.3 at `Press ENTER` and doctor failed. With the flag, RPC answered.
On 0.8.3, plain `set` failed launch (E518). `silent! set` launched, but
openDiff still stopped at `Press ENTER`.
- Buffer facts, on 0.8.3, 0.10.4, 0.11.5 and 0.12.3: all four gotchas
held. 'eventignorewin' gave E518 on 0.8.3 and 0.10.4.
- User configs: the three launches gave the same buffer text,
`&modified` and file hash on main and on this head.
- Send lane, as written: native printed `n|hello.txt` with the mapping
and with the typed command. Snacks with the `<cmd>` mapping printed
`i|hello.txt`, and `x` typed `xbeta`, which reproduces coder#423. Snacks with
the typed command printed `n|hello.txt`.
- CLI handshake block, as written: `Status: ✔ Connected`. Under `strace
-f`, none of its execve calls carried the token. A wrong token gave
`Status: ✘ Failed to connect`, and `type: "ws-ide"` was refused.
- Review round 1: the security lane found the token in `claude` argv.
The block now uses a `headersHelper` that reads the lock file.
- Verifier nits: the block now sets `VCN_STATE` in its first line and
quotes the lock path. Run in a fresh shell with a state dir whose name
has a space, the block printed `Status: ✔ Connected`. The previous block
printed `Status: ✘ Failed to connect` there.
- `proof-launch-refusals.sh` printed 18 PASS lines, and the full run
printed `PASS opendiff-accept`. `mise run check` (0 warnings, 0 errors),
`mise run test` (1059 successes, 0 failures), and `mise run
format-check` pass.

---
_Generated with [`xum`](https://github.com/coder/xum) • Model:
`anthropic:claude-opus-5-5` • Thinking: `xhigh`_
hareki pushed a commit to hareki/claudecode.nvim that referenced this pull request Nov 10, 2026
The next claudecode.nvim release. Merging this PR creates the release
tag and GitHub Release, then starts Communique GitHub Release note
generation.
---


## [0.4.0] - 2026-11-09

### Added

- `:ClaudeCodeSendText {text}` command and
`require("claudecode.terminal").send_to_terminal(text, opts)` to send
arbitrary text to the open Claude terminal as if typed at the prompt
(submitting by default; `:ClaudeCodeSendText!` inserts without
submitting). Multi-line text is sent via bracketed paste. Works with the
in-editor `native`/`snacks` providers only.
([coder#197](coder#197),
[coder#272](coder#272))
- `:checkhealth claudecode` health check that verifies Neovim version,
`setup()`, the Claude CLI, terminal provider, WebSocket server, lock
file, and live connection state.
([coder#275](coder#275))
- `:ClaudeCodeCloseAllDiffs` command to close pending Claude diffs at
once. A diff accepted with `:w` closes once the file holds the accepted
text; otherwise the accepted text is put into the buffer as unsaved
changes for `:w`/`:e!` so edits are never discarded.
([coder#248](coder#248),
[coder#261](coder#261))
- `diff_opts.layout = "unified"`: a VS Code-style unified diff rendered
in a single buffer with interleaved deleted/added lines, as a compact
alternative to `"vertical"`/`"horizontal"`. Documented to require Neovim
>= 0.9.0. Customizable via the
`ClaudeCodeInlineDiffAdd`/`Delete`/`AddSign`/`DeleteSign` highlight
groups. ([coder#195](coder#195),
[coder#295](coder#295),
[coder#297](coder#297))
- `User ClaudeCodeSendComplete` autocmd, fired once per file when a send
is accepted while Claude is connected, with `data = { file_path,
start_line, end_line, context }` (lines 0-indexed). Enables post-send
logic such as focusing a Claude session running outside Neovim.
([coder#228](coder#228),
[coder#265](coder#265))
- `User ClaudeCodeDiffOpened` / `ClaudeCodeDiffClosed` autocmds carrying
diff metadata, plus `diff_opts.auto_resize_terminal` (default `true`) to
opt out of plugin-managed terminal width during diffs and
`terminal.diff_split_width_percentage` to set a distinct terminal width
while a diff is open.
([coder#270](coder#270))
- `terminal.auto_insert` option (default `true`): set to `false` to stay
in Normal mode when refocusing the Claude terminal and preserve your
scroll position instead of jumping to the prompt.
([coder#233](coder#233))
- `ClaudeCodeTreeAdd` / `<leader>as` support in snacks.nvim pickers
(`snacks_picker_list`), covering `Snacks.explorer()` and modal
`Snacks.picker.files()`/`grep()`.
([coder#192](coder#192),
[coder#269](coder#269))
- netrw file selection for `<leader>as` / `:ClaudeCodeTreeAdd`,
supporting marked files and the file under the cursor.
([coder#62](coder#62))

### Changed

- Model picker labels are now version-free evergreen aliases (`Claude
Opus (Latest)`, `Claude Sonnet (Latest)`, `Claude Haiku (Latest)`), with
new 1M-context variants (`opus[1m]`, `sonnet[1m]`) and a `Default
(account recommended)` entry.
([coder#146](coder#146),
[coder#256](coder#256))
- `:checkhealth claudecode` and the MCP `serverInfo.version` now report
the real plugin version from the `VERSION` file instead of a hard-coded
value. ([coder#437](coder#437))

### Fixed

- The Snacks provider no longer fails to launch Claude when a model
alias contains shell-glob characters (e.g. `opus[1m]`); the command is
now passed as an argv list with no shell interpretation.
([coder#256](coder#256))
- The native terminal now adopts only terminal buffers it started
(marked with `b:claudecode_native_terminal`), instead of any visible
terminal whose name contains `claude`. Upgrade note: a terminal that an
older plugin version started (for example after `:Lazy reload` following
an upgrade), or that a session file restored, carries no mark and is no
longer adopted. The next open starts a second Claude session, and the
old terminal keeps running until you close its buffer or quit Claude in
it. ([coder#349](coder#349),
[coder#352](coder#352),
[coder#364](coder#364))
- `closeAllDiffTabs` is now scoped to claudecode's own tracked diffs and
no longer wipes out an open diffview.nvim, fugitive, or native
`:diffsplit` review; `openFile`/`openDiff` also never reuse a window
that is in diff mode.
([coder#277](coder#277),
[coder#290](coder#290))
- `close_tab` now closes only the diff with that tab name and never
deletes a user buffer.
([coder#373](coder#373))
- Closing the native terminal, for example with `:ClaudeCodeClose`, now
stops the Claude job instead of leaving it running.
([coder#336](coder#336))
- The Claude terminal now adds loopback hosts to `no_proxy`/`NO_PROXY`
so a configured proxy no longer tunnels Claude's `ws://127.0.0.1` IDE
connection and times out queued @ mentions.
([coder#70](coder#70),
[coder#268](coder#268))
- `focus_after_send = true` with `provider = "none"`/`"external"` now
emits a one-time warning pointing to the `User ClaudeCodeSendComplete`
autocmd instead of failing silently.
([coder#228](coder#228),
[coder#265](coder#265))
- Rejecting a Claude diff with `:q` / `:close` / `<C-w>c` (or closing
the tab) now resolves it as rejected via a `WinClosed` autocmd.
([coder#266](coder#266))
- Quickly-made and single-line visual selections are now pushed to
Claude reliably; selections are flushed synchronously on visual-mode
exit and persist until the cursor moves, including in the external
`/ide` flow and Select mode.
([coder#246](coder#246),
[coder#267](coder#267),
[coder#367](coder#367),
[coder#381](coder#381),
[coder#388](coder#388))
- Pending diffs are now automatically closed when the client that opened
them disconnects or the integration stops, so orphaned proposals no
longer linger.
([coder#248](coder#248),
[coder#261](coder#261))
- `openDiff` now works when the Claude terminal is the only window,
creating a split to host the diff instead of failing with "No suitable
editor window found".
([coder#260](coder#260))
- Fixed the "climbing cursor" in the Snacks terminal, where the cursor
sat one row above Claude's prompt after hide and show. On Neovim >= 0.10
a floating terminal is now hidden instead of closed. A split is still
closed on hide and created again on show, which keeps the cursor in
place. Floating terminals on Neovim < 0.10 keep the old behavior.
([coder#240](coder#240),
[coder#183](coder#183),
[coder#271](coder#271))
- Worked around a Neovim core bug (< 0.12.2) that fragmented large
bracketed pastes into the terminal; controlled by
`terminal.fix_streamed_paste` (`"auto"` by default).
([coder#252](coder#252))
- `openFile` now selects exactly the requested line range or matched
text, keeps the user's Visual mode, unsaved changes, focus and preview
window intact, never prompts W11/W12, and never picks the preview window
as the main editor window.
([coder#353](coder#353),
[coder#365](coder#365),
[coder#370](coder#370),
[coder#375](coder#375),
[coder#382](coder#382),
[coder#384](coder#384),
[coder#387](coder#387),
[coder#396](coder#396),
[coder#408](coder#408))
- `getDiagnostics` now handles plain file paths without a `file://` URI
scheme, and IDE diagnostics return grouped URI-based payloads with
editor-native ranges and severity names.
([coder#163](coder#163),
[coder#274](coder#274))
- `:ClaudeCodeAdd` and `openFile` now handle `$` in file paths.
([coder#286](coder#286))
- Prevented a segfault when accepting a new-file diff with
`render-markdown.nvim` installed, by turning off diff mode before the
post-write redraw.
([coder#224](coder#224))
- The auth token is now generated from a CSPRNG and the lock file is
written atomically with mode `0600` in a `0700` directory.
([coder#259](coder#259))
- Detect system sleep/wake and reset client keepalive timestamps to
prevent false disconnections.
([coder#141](coder#141))
- The WebSocket server now retries port binding on `EADDRINUSE`
(parallel instances), closes connections on malformed/oversized or
binary frames with the correct status, joins fragmented messages,
validates UTF-8 per message, and never repeats a client id within a
process. ([coder#258](coder#258),
[coder#283](coder#283),
[coder#378](coder#378),
[coder#383](coder#383),
[coder#390](coder#390),
[coder#395](coder#395),
[coder#405](coder#405),
[coder#422](coder#422),
[coder#431](coder#431))
- Legacy `diff_opts` (e.g. `vertical_split`, `open_in_current_tab`) now
take effect again after the config merge-order regression.
([coder#142](coder#142))
- `:q` on a diff window no longer hangs; floating diff terminals keep
focus; empty buffers are wiped when the terminal provider is `none`; and
accepted diffs are handed over in the buffer's own line-ending format.
([coder#178](coder#178),
[coder#223](coder#223),
[coder#266](coder#266),
[coder#392](coder#392))

### Compatibility

- Integration tests now run on Neovim v0.8.0, and a new-tab diff no
longer fails there because Neovim 0.8 has no `statuscolumn`. The unified
layout is documented to require Neovim >= 0.9.0, and the v0.8.0
integration tests skip it.
([coder#369](coder#369),
[coder#394](coder#394))

---
Maintained by the release-please workflow. CHANGELOG.md and the release
PR body are regenerated by Communique on every push to main, so manual
edits to this PR are overwritten.

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Thomas Kosiewski <tk@coder.com>
ThomasK33 added a commit to joshmedeski/claudecode.nvim that referenced this pull request Nov 10, 2026
## Why

Goal of this batch: close the open follow-up issues in
coder/claudecode.nvim, each fix as its own small, reviewed PR. This PR
handles item 6 of coder#409, the follow-ups of the openFile reload work in
coder#408.

This PR changes no code. It documents each follow-up, with the reason it
stays, in the tools README. An earlier version of this PR turned the
global 'write' option off during openFile's acwrite step. That broke a
common autosave (`autocmd BufLeave * update` failed openFile with E142),
so it is gone. Each extra mechanism in this area has produced a new
regression, so this PR adds none.

## What changed

- `lua/claudecode/tools/README.md`, openFile paragraph of Side Effects:
- Names the known gap: a nested write during the acwrite step, plus a
user BufWriteCmd handler, writes the buffer over Claude's file.
- Plugins that skip buffers whose 'buftype' is set skip this buffer in
the autocommands of that step, and an autocommand that sets `acwrite`
itself is undone.
- W13 can still come for a buffer that openFile cannot know as new, and
a write through a BufWriteCmd handler does not end the tracking.
- Under a pending operator, the reload rules can still load the file
into the buffer the command runs in.
- `open_file.lua`, its spec and `covered.lock` match main.

## Scope

Known gap, documented, not fixed. While openFile shows a buffer with
Neovim's file check turned off, the buffer's 'buftype' is `acwrite` for
that one step. A write of an `acwrite` buffer skips Neovim's E13 and
changed-file checks and goes to BufWriteCmd. Claude's file is replaced
only when all of these hold:

1. The step runs: the buffer was opened before its file existed, or
'eventignore' (or 'eventignorewin') ignores FileChangedShell when
openFile shows the buffer in a window that did not show it.
2. A user autocommand defined with `++nested` on BufEnter or BufWinEnter
of that buffer, or on BufLeave of the buffer the window leaves, writes
the buffer (`:write`, `:update`, `:wall`).
3. A user BufWriteCmd autocommand whose pattern matches the file, such
as `BufWriteCmd *`, writes `<afile>`.

Without `++nested`, Neovim runs no BufWriteCmd for that write, and
without a matching handler the write fails with E676. In both cases the
file stays (checked on 0.8.3 and 0.12.3). BufWriteCmd handlers of common
plugins match their own names, such as `*.gpg`, `suda://*`, `oil://*`
and `fugitive://*`, not every file. Before coder#408, Neovim stopped this
write with E13 for a buffer opened before its file existed, after it
asked W13. With 'eventignore' and unsaved text, main before coder#408 also
wrote the buffer over the file, because the handler skips the
changed-file check there too.

The acwrite step itself stays: no tested way avoids it. Neovim checks a
buffer's file whenever a window enters it, and skips that check only for
a buffer whose 'buftype' is set. W13 ("file created after editing
started") runs no FileChangedShell autocommand, so nothing can answer
it. On Neovim 0.8.3, 0.9.5, 0.10.4 and 0.12.3, eight ways to show such a
buffer with unsaved text all raise W13: `:edit`, `noautocmd edit`,
`silent! edit`, `keepalt keepjumps lockmarks edit`,
`nvim_win_set_buf()`, `nvim_win_set_buf()` under `eventignore=all`,
'shortmess' with `FWsAIc` added, and `:buffer`. Only a set 'buftype'
avoids it. `nowrite` and `nofile` make 'modified' read as off, which
coder#408 already showed drops unsaved text. `help` marks the buffer as a
help buffer, so a config that checks `&buftype ==# 'help'` on BufEnter
acts on it.

Per sub-item of coder#409 item 6:

| Follow-up | Decision |
|
------------------------------------------------------------------------------------------------------------------------------------------------------------
|
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
| A nested write plus a user `BufWriteCmd *` handler during the step can
write over Claude's file. | Documented as a known gap (conditions
above). Turning 'write' off closed it but made a common autosave fail
openFile. |
| Plugins that check `buftype == ""` in BufEnter or BufWinEnter see
`acwrite` and can skip their setup. In the 'eventignore' case nothing
runs BufEnter again. | Documented. Any value that turns the check off is
visible. Running BufEnter again after the step runs every user BufEnter
autocommand twice. The setup runs the next time a window enters the
buffer. |
| A user autocommand that sets 'buftype' to `acwrite` itself is undone.
| Documented. openFile cannot tell that value from its own. |
| W13 still asks when the buffer and its file both existed before the
Claude server started. | Documented. No Neovim API tells such a buffer
apart: `:file` shows `[New]`, but that text is translated. Neovim asks
the same W13 when the user enters the buffer. |
| openFile can load the file again under a pending operator. |
Documented. This is the rule that coder#387 uses for every changed file and
that 'autoread' uses. On 0.8.3 and 0.12.3 one `u` undoes a `:checktime`
reload and the new-file `:edit`. |
| A buffer made while 'eventignore' ignores BufNewFile is not tracked as
new. A buffer saved by a BufWriteCmd handler stays tracked. |
Documented. The first gives W13 as before coder#408. The second makes
openFile read the file again into a buffer without unsaved changes,
which drops no unsaved text, and one `u` undoes it. A BufWriteCmd
autocommand of openFile's own would take over every write in Neovim. |
| The repair read after a failing autocommand ends Visual mode. |
Documented (the README already said it). Without the repair a later `:w`
writes the half-read text over the file (coder#408's probe: the buffer keeps
`one\|two\|\|`, and `:w` writes that). |

## Blast Radius

Documentation only. No runtime code changes.

## Verification

- **The gap, real Neovim 0.8.3 and 0.12.3,** 80 planned runs per tree (a
buffer opened before its file existed, or a changed file with
'eventignore' set to FileChangedShell; with and without unsaved text;
window and preview; five setups of user autocommands). The code is
a067325's, which main still has:
- a067325 writes over Claude's file in 20 runs where main before coder#408
(f9f0c64) kept it: `BufEnter ++nested silent! write` with a `BufWriteCmd
*` handler (buffer opened before its file existed, with and without
unsaved text, and 'eventignore' without unsaved text), and `BufWinEnter
++nested silent! update` or `BufLeave * ++nested silent! wall` with the
handler (buffer opened before its file existed, unsaved text).
- Both trees write over it in 12 runs: 'eventignore' with unsaved text
and the handler.
- **The E676 cases, same code, 0.8.3 and 0.12.3:** a `++nested` write
without a handler fails with E676, and a write that is not nested never
runs the `BufWriteCmd *` handler. Claude's file stays in all 8 runs.
- **The autosave regression of the earlier version is gone:** the
verifier's `other2.lua` cases `bl_update_ns`, `bl_lua_update` and
`awa_nohidden` succeed and save the other buffer, as on main.
- **The acwrite step:** `avoid.lua` (eight ways to show the buffer, plus
four 'buftype' values) on 0.8.3, 0.9.5, 0.10.4 and 0.12.3, as described
under Scope.
- **Gates:** `mise run check`, `mise run test` (1014 passed, shuffled),
`prettier --check`, and the integration suite (51 passed on 0.8.3, 62
passed on 0.12.3) pass. `covered.lock` matches the code (`check.sh
--hash-only`).

Part of coder#409

---

_Generated with [`xum`](https://github.com/coder/xum) • Model:
`anthropic:claude-opus-5-5` • Thinking: `xhigh`_
hareki pushed a commit to hareki/claudecode.nvim that referenced this pull request Nov 11, 2026
…oder#468)

## Why

When Claude creates a file whose buffer the user opened before the file
existed, openFile must not write the user's unsaved text over Claude's
file. On main it can: openFile's acwrite step (coder#408) makes Neovim skip
the E13 check that refuses `:w` of such a buffer, so a `++nested`
BufEnter, BufWinEnter or BufLeave autocommand that writes the buffer
reaches a user `BufWriteCmd *` handler, and that handler overwrites
Claude's file.

## What changed

- `without_neovim_file_check` (`lua/claudecode/tools/open_file.lua`)
also sets 'readonly' on a buffer opened before its file existed, unless
'readonly' is already on. After the step it turns 'readonly' off only
when it is still on, the same restore rule the 'buftype' code uses. A
write of that buffer without `!` during the step now fails with E45,
where Neovim gives E13. A write with `!` passes, as it does without the
step. Exceptions, all stated in the README: with 'confirm', Neovim asks
"'readonly' option is set ... Do you wish to write anyway?" (plain
Neovim asks "Overwrite existing file?"), and yes writes. With 'writeany'
or `cpo+=O`, the step still fails with E45 where Neovim would write
(stricter). With 'shortmess' lacking `F`, the file message of the
`:edit` names `[readonly]`.
- `lua/claudecode/tools/README.md`: the openFile paragraph now states
the scope plainly. A user BufWriteCmd autocommand that matches the file
runs before Neovim checks whether the file changed. So such a handler,
and a write with `!`, overwrite Claude's file in or out of openFile.
That is Neovim's behavior, and openFile does not change it. The old
sentence said Neovim asks "The file has been changed since reading
it!!!" outside the step. That is false when such a handler exists.
- Verify skill `features/open-file.md`: a **File created after its
buffer** step and a gotcha for the BufWriteCmd order.
- `covered.lock` re-recorded. Only the file hash of `open_file.lua`
changed. No diff-lifecycle block or call site changed, and `check.sh`
passes.

Known gap, stated in the README: a buffer renamed with `:file`
(BF_NOTEDITED) or read with errors (BF_READERR) also gets E13 from
Neovim, and in the 'eventignore' step it gets no 'readonly', because no
Neovim API exposes those flags. Reproduced on main and on this head with
`probe_flags.lua`.

Other buffers are not affected: 'readonly' is buffer-local and is set
only for the duration of the step. A buffer whose file existed when it
was opened gets no 'readonly'. For such a buffer, a matching user
BufWriteCmd handler overwrites Claude's file the same way without
openFile (case `plain_bufenter` below).

## Evidence

Spec that fails without the fix:
`tests/integration/open_file_new_file_write_spec.lua` (real Neovim, so
CI runs it in `integration-tests` on stable and v0.8.0). On main, 3 of
its 8 tests fail: Claude's file is overwritten. With the fix, all 8 pass
on Neovim 0.12.3 and 0.8.0, and the full integration suite passes on
both (127 and 107 tests). Two tests pin the scope and the restore:
dropping the new-file condition, or turning 'readonly' off only while
'buftype' is still acwrite, each turns one of them red.

Headless repro (Neovim 0.12.3, `probe_433.lua` with 9 cases):
- main `52ccd4c`: Claude's file is overwritten in `bfnew_bufenter`,
`bfnew_bufwinenter` and `bfnew_bufleave_wall`.
- With the fix: Claude's file stays in all `bfnew_*` cases.
- Unchanged by design: `ei_bufenter`, `ei_bufenter_bang` and
`plain_bufenter` (a buffer whose file existed) still overwrite, with or
without the step. That is Neovim's BufWriteCmd order.

Live run (real Neovim in agent-tty, scripted Claude client, verify
skill). Setup: `:e new.txt`, type `USER UNSAVED`, `:e hello.txt`,
`:autocmd BufEnter * ++nested update`, a `BufWriteCmd *` handler that
writes `<afile>`, then Claude writes `CLAUDE` to `new.txt` and calls
openFile on it.

| | main `52ccd4c` | this PR |
| --- | --- | --- |
| `new.txt` on disk | `USER UNSAVED` (overwritten) | `CLAUDE` |
| openFile answer | `Opened file` | error naming `E45: 'readonly' option
is set` |
| buffer | `USER UNSAVED`, 'modified' off | `USER UNSAVED`, 'modified'
on, 'readonly' off, 'buftype' empty |
| prompt (default options) | none | none (`vcn.sh doctor` all ok). With
'confirm' Neovim asks before the write, as plain Neovim does |
| `autocmd BufLeave * update` autosave | writes the left buffer | writes
the left buffer, openFile succeeds |

Screenshot after openFile with this PR (no prompt, `new.txt [+]` keeps
`USER UNSAVED`): kept in the owner workspace as `head-after.png`,
because `gh --attach` was refused for this token.

Gate: `mise run all` exits 0 (1206 unit tests, luacheck 0 warnings,
treefmt 0 changed). `verify-diff-lifecycle/check.sh` passes.

Fixes coder#433

---
_Generated with [`xum`](https://github.com/coder/xum) • Model:
`anthropic:claude-opus-5-5` • Thinking: `xhigh`_
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