Skip to content

docs(open_file): name the limits of openFile's acwrite step - #413

Merged
ThomasK33 merged 8 commits into
mainfrom
fix/open-file-acwrite-followups
Nov 1, 2026
Merged

ThomasK33 merged 8 commits into
mainfrom
fix/open-file-acwrite-followups

Conversation

@ThomasK33

@ThomasK33 ThomasK33 commented Nov 1, 2026 •

Copy link
Copy Markdown
Member

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 * 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 #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() under eventignore=all, 'shortmess' with FWsAIc added, and :buffer. Only a set 'buftype' avoids it. nowrite and nofile make 'modified' read as off, which #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 #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 #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 #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 (#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 fix(open_file): never let Neovim ask W13 or W11, and finish a reload that an autocommand fails in #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 #409


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

…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`_
@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-01T15:59:52.670000Z 5aebdd0 Manual request
🔒 Security Review ✅ Completed 2026-11-01T16:00:30.139542Z 5aebdd0 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: 7dbc1fc1a7

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. Delightful!

Reviewed commit: 7dbc1fc1a7

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

…-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`_
@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. Already looking forward to the next diff.

Reviewed commit: 9249cb4f74

ℹ️ 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: 9249cb4f74

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.

…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`_
@ThomasK33 ThomasK33 changed the title fix(open_file): turn 'write' off while openFile's acwrite step runs docs(open_file): name the limits of openFile's acwrite step Nov 1, 2026
@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. Breezy!

Reviewed commit: 5aebdd0e90

ℹ️ 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: 5aebdd0e90

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.

ThomasK33 added a commit to joshmedeski/claudecode.nvim that referenced this pull request Nov 10, 2026
…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`_
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