Repository navigation
docs(open_file): name the limits of openFile's acwrite step - #413
Conversation
…e Claude's file While openFile shows a buffer with Neovim's file check turned off, the buffer's 'buftype' is acwrite. For an acwrite buffer :write skips the E13 check and the changed-file check, and runs BufWriteCmd autocommands. So a user's `autocmd BufEnter new.txt ++nested silent! write` together with a `BufWriteCmd *` handler that writes <afile> writes the buffer over the file Claude just wrote. Real Neovim 0.8.3 and 0.12.3 show it in 34 of 80 runs on a067325: an empty or old buffer, or the user's unsaved text, replaces Claude's text on disk. Before #408 only the unsaved-text case with 'eventignore' did that. The mock now models 'write', :write with E13, E142 and E676, and BufWriteCmd. The six new tests fail on this commit. --- _Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `xhigh`_
--- _Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `xhigh`_
While openFile shows a buffer with Neovim's file check turned off, it now also turns the global 'write' option off, and back on after. An acwrite buffer skips the E13 and changed-file checks of :write and goes to BufWriteCmd, so a user's nested BufEnter, BufWinEnter or BufLeave write plus a `BufWriteCmd *` handler wrote the buffer over Claude's file. With 'write' off such a write fails with E142, and the handler never runs. `noautocmd set` keeps OptionSet autocommands out of it. The tools README names the limits that stay: plugins that skip a buffer with 'buftype' set skip it in those autocommands, an autocommand that sets acwrite itself is undone, W13 can still come for a buffer openFile cannot know as new, a BufWriteCmd write keeps the tracking, and a reload can change the text under a pending command. Real Neovim 0.8.3 to 0.12.3, 160 runs with five user autocommand setups: openFile no longer writes over Claude's file in any run where main before #408 kept it (a067325 did in 20). The 8 runs that still write are 'eventignore' runs with unsaved text where the user's handler writes when openFile focuses the preview window, after the step, as before #408. --- _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. No block or call site changed. The change can only stop a write: while openFile's acwrite step runs, a nested autocommand's :wall no longer reaches the BufWriteCmd of a pending diff's proposal buffer, so that write saves no diff. The model already lets a user never save a diff, so it still describes the code. 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`_
--- _Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `xhigh`_
|
@codex review |
|
@codex security review |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
🛡️ Codex Security ReviewSecurity review completed. No security issues were found in this pull request. Reviewed commit: Only the user who started this review can view the report in Codex. ℹ️ About Codex security reviews in GitHubThis is an experimental Codex feature. Security reviews are triggered when:
Once complete, Codex will leave suggestions, or a comment if no findings are found. |
|
Codex Review: Didn't find any major issues. Delightful! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
…-followups # Conflicts: # .agents/skills/verify-diff-lifecycle/covered.lock
The lock from main matches its diff changes. Against it, only the `file lua/claudecode/tools/open_file.lua` line reads STALE, for the 'write' guard of this branch. check.sh on the merged 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`_
|
@codex review |
|
@codex security review |
|
Codex Review: Didn't find any major issues. Already looking forward to the next diff. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
🛡️ Codex Security ReviewSecurity review completed. No security issues were found in this pull request. Reviewed commit: Only the user who started this review can view the report in Codex. ℹ️ About Codex security reviews in GitHubThis is an experimental Codex feature. Security reviews are triggered when:
Once complete, Codex will leave suggestions, or a comment if no findings are found. |
…md gap Turning the global 'write' option off during the acwrite step broke a common autosave. With `autocmd BufLeave * update`, or a Lua callback that runs `update`, and unsaved changes in the current buffer, openFile failed with E142 from that BufLeave autocommand on Neovim 0.8.3 to 0.12.3, where main saves the buffer and shows the file. `set nohidden autowriteall` failed the same way. This commit removes the guard, its six tests and the mock code they needed, so open_file.lua, its spec and covered.lock match main again. The tools README now names the gap the guard tried to close: a user's ++nested BufEnter, BufWinEnter or BufLeave write during the step, plus a user BufWriteCmd handler that matches the file and writes <afile>, writes the buffer over Claude's file. Without ++nested, or without such a handler, the write fails with E676 and the file stays. --- _Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `xhigh`_
|
@codex review |
|
@codex security review |
|
Codex Review: Didn't find any major issues. Breezy! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
🛡️ Codex Security ReviewSecurity review completed. No security issues were found in this pull request. Reviewed commit: Only the user who started this review can view the report in Codex. ℹ️ About Codex security reviews in GitHubThis is an experimental Codex feature. Security reviews are triggered when:
Once complete, Codex will leave suggestions, or a comment if no findings are found. |
…mit (coder#420) ## 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 4 of coder#416, the openFile follow-ups of coder#413. This PR changes no code. It documents two more openFile limits in the tools README. Earlier versions of this PR changed how openFile tracks a buffer opened before its file existed: they counted writes with undotree()'s `save_last` instead of BufWritePost. That made two regressions. A user's BufNewFile `bwipeout` failed `:edit`, which round 1 of review found and the PR fixed. Then, with `cpoptions+=+`, `:w {file}` counts up `save_last` while Neovim keeps W13, so the W13 dialog came back and the user's `l` replaced their unsaved text. Each new mechanism in this area has made a regression, so this PR keeps main's code. ## What changed `lua/claudecode/tools/README.md`, openFile paragraph of Side Effects: - A write that runs no BufWritePost does not end the new-file tracking. That covers a write from an autocommand without `++nested` (such as `autocmd BufLeave * update`) and a write through a BufWriteCmd handler. openFile then keeps running its acwrite step for that buffer, and reads the file into it with `:edit` when it has no unsaved changes. No question comes, and unsaved text stays. - The y/n question that Neovim asks when a user's autocommand writes a changed buffer while openFile switches buffers, and what each answer does. `open_file.lua`, its spec and `covered.lock` match main. ## Scope Per sub-item of coder#416 item 4: | Follow-up | Decision | | ---------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------ | | A nested write plus a matching BufWriteCmd handler writes the buffer over Claude's file during the acwrite step. | Stays documented as in coder#413. No per-buffer state meets all four needs (below), and a guard of openFile's own cannot run first. | | With 'eventignore', unsaved text, a BufLeave `:wall` and `preview = true`, Neovim asks "write anyway (y/n)?". | Checked in a real terminal and documented. It is not specific to 'eventignore' or preview. | | A write from an autocommand without `++nested` does not end the new-file tracking. | Documented as a known limit. The fix that counted writes broke W13 with `cpoptions+=+`. | Why the nested-write gap stays: a fix may touch only the target buffer, and must not block or prompt other writes. The buffer needs a state that (1) skips Neovim's file check, (2) keeps 'modified', (3) keeps the E13 and changed-file checks of `:write`, and (4) changes nothing else that autocommands see. - `acwrite` meets 1 and 2 but not 3. - `nowrite` and `nofile` fail 2. - `help` meets 1 to 3. But Neovim marks the buffer as a help buffer, so a config that checks `&buftype ==# 'help'` on BufEnter acts on the user's file. - 'readonly' stops `:w` only. `:w!` writes, and 'confirm' asks. - A buffer-local or group BufWriteCmd autocommand that openFile adds runs after the user's `BufWriteCmd *` on 0.8.3 and 0.12.3, in the order they were defined, so it cannot stop the write. The y/n question, in a real terminal (vcn.sh). The user has unsaved text in a buffer whose file Claude changed, a BufLeave `++nested silent! wall`, and another modified buffer: - openFile's switch makes `:wall` write the buffer, and Neovim asks "The file has been changed since reading it!!! Do you really want to write to it (y/n)?". openFile's reply waits for the answer. - `y` writes the unsaved text over Claude's file. - `n` and Escape write nothing, and the buffer keeps its text. - CTRL-C writes nothing, keeps the focus in the old window, and fails openFile with "Keyboard interrupt". - `l` and other keys repeat the question. - After `y`, a hit-enter prompt holds the reply until Enter: on 0.8 and 0.10, and on 0.12 with the default 'messagesopt'. - The other modified buffer is written before the question. - The same question comes without 'eventignore' and on the window path. This is Neovim's own check of the user's write, as when the user switches windows by hand. ## Blast Radius Documentation only. No runtime code changes. ## Verification - **The y/n question, vcn.sh:** `y`, `n`, Escape, CTRL-C and `l` on 0.12.3. `y` and `n` on 0.8.3. `y` and `n` without 'eventignore' on the window path. The verifier's runs add 0.10.4, where `y` also stops at the hit-enter prompt. - **The tracking limit, real Neovim 0.8.3 and 0.12.3, main's code:** a new-file buffer that `autocmd BufLeave * update` or a BufWriteCmd handler wrote, then Claude changes the file, then openFile. - The user's BufEnter autocommand sees `acwrite`, so the step ran. - With no unsaved changes, the buffer gets Claude's text. With unsaved changes typed after the write, the buffer keeps them. - No question comes in any run. - **The acwrite step options:** `avoid.lua` (from coder#413) and the BufWriteCmd order script, as described under Scope. - **Gates:** `mise run check`, `mise run test` (1036 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#416 --- _Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `xhigh`_
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 #409, the follow-ups of the openFile reload work in #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 * updatefailed 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:acwriteitself is undone.open_file.lua, its spec andcovered.lockmatch main.Scope
Known gap, documented, not fixed. While openFile shows a buffer with Neovim's file check turned off, the buffer's 'buftype' is
acwritefor that one step. A write of anacwritebuffer skips Neovim's E13 and changed-file checks and goes to BufWriteCmd. Claude's file is replaced only when all of these hold:++nestedon BufEnter or BufWinEnter of that buffer, or on BufLeave of the buffer the window leaves, writes the buffer (:write,:update,:wall).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://*andfugitive://*, not every file. Before #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 #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()undereventignore=all, 'shortmess' withFWsAIcadded, and:buffer. Only a set 'buftype' avoids it.nowriteandnofilemake 'modified' read as off, which #408 already showed drops unsaved text.helpmarks the buffer as a help buffer, so a config that checks&buftype ==# 'help'on BufEnter acts on it.Per sub-item of #409 item 6:
BufWriteCmd *handler during the step can write over Claude's file.buftype == ""in BufEnter or BufWinEnter seeacwriteand can skip their setup. In the 'eventignore' case nothing runs BufEnter again.acwriteitself is undone.:fileshows[New], but that text is translated. Neovim asks the same W13 when the user enters the buffer.uundoes a:checktimereload and the new-file:edit.uundoes it. A BufWriteCmd autocommand of openFile's own would take over every write in Neovim.:wwrites the half-read text over the file (#408's probe: the buffer keepsone|two||, and:wwrites that).Blast Radius
Documentation only. No runtime code changes.
Verification
BufEnter ++nested silent! writewith aBufWriteCmd *handler (buffer opened before its file existed, with and without unsaved text, and 'eventignore' without unsaved text), andBufWinEnter ++nested silent! updateorBufLeave * ++nested silent! wallwith the handler (buffer opened before its file existed, unsaved text).++nestedwrite without a handler fails with E676, and a write that is not nested never runs theBufWriteCmd *handler. Claude's file stays in all 8 runs.other2.luacasesbl_update_ns,bl_lua_updateandawa_nohiddensucceed and save the other buffer, as on main.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.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.lockmatches the code (check.sh --hash-only).Part of #409
Generated with
xum• Model:anthropic:claude-opus-5-5• Thinking:xhigh