Skip to content

fix(open_file): close the openFile gaps from #362 - #365

Merged
ThomasK33 merged 8 commits into
mainfrom
fix/open-file-followups
Oct 31, 2026
Merged

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

Conversation

@ThomasK33

@ThomasK33 ThomasK33 commented Oct 31, 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. It closes the four openFile gaps in item 3 of #362:

  1. startLine: false or endLine: false counted as absent, so the call opened the file or used a default line.
  2. When endText was not found, the answer said "positioned at", but the handler selected the startText match.
  3. The line count checked before opening matched a loaded buffer by exact name. A file opened through a symlink missed the buffer's unsaved lines, and a valid startLine got -32602.
  4. With 'selection' inclusive, a range ending on an empty line in the middle of the file also selected that line's line break.

What changed

  • The line check tests for nil, so false now answers -32602 before the file opens.
  • When endText is not found, openFile only places the cursor on the startText match, with no selection. This is what the VS Code extension does: it sets an empty selection at the start of the match and answers "positioned at". openFile first leaves Visual or Select mode, because a line range earlier in the same call can leave it on, and moving the cursor in it would stretch that selection.
  • The count before opening finds the buffer that :edit will reuse with bufexists() and bufadd(). Both use Neovim's own lookup, by name or by the inode Neovim cached for the buffer. A file symlink, a directory symlink, and a hard link all find it, and a symlink retargeted after its buffer loaded does not.
  • The empty-line case stays as it is, and the code and the tools README now explain it. No '> position on an empty line leaves out its line break in inclusive mode. Ending on the line above gives the same yanked text, but Claude's selection_changed then reports abc on line 1 instead of abc\n through line 2.

Scope

Blast Radius

The change touches only openFile calls that pass startLine/endLine or an endText that is not found, plus calls on files that are loaded under another name. A request with false line values now fails where it used to succeed. Claude Code sends integers or leaves these fields out.

Verification

  • Headless matrix through tools.handle_invoke: 36 cases on Neovim 0.8.3, 0.9.5, 0.10.4, and 0.12.3, each with 'selection' inclusive and exclusive (288 runs). Compared with main, only 5 cases change: the 3 false cases (now -32602, file not opened), and the endText-not-found case with and without a line range in the same call (now normal mode, cursor on two). A combined call whose endText is found still selects two\nthree, as on main.
  • Alias probe on 0.8.3 and 0.12.3: 4 lines on disk, 2 unsaved lines in the loaded buffer, and startLine: 5, endLine: 6. Main answered -32602 through a file symlink, a directory symlink, a hard link, and a buffer loaded through a file symlink. This head selects five\nsix in all 6 cases, and :edit reuses the one buffer. When the symlink is retargeted to a 2-line file, startLine: 5 answers -32602 and leaves no extra buffer.
  • On 0.12.3 through the verify-claudecode-nvim harness, the call order lines 3-4, then two..zzz, leaves normal mode with the cursor at 2:1, and Claude's last selection_changed is empty at line 1 (0-based), character 0. startLine: false, endLine: 3 answers -32602.
  • busted tests/unit/tools/open_file_spec.lua: all 30 cases pass. Each fix landed after a test commit whose new case failed on the code before it, and one more case pins the empty-line behavior. mise run check and mise run test (799 passing) are green.

Part of #362


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

Three new cases fail on the current handler:
- startLine or endLine set to false is treated as absent, so the call
  opens the file instead of answering -32602.
- A buffer loaded under another name for the same file, such as a
  symlink, is not found, so its unsaved lines do not count.
- When endText is not found, the handler selects the startText match
  although the answer says it positioned the cursor there.

Two more cases pin behavior that stays: a loaded buffer for a different
file is not used, and the end mark stays on an empty endLine. The mocks
now record the cursor and give each file an inode through fs_stat().

Part of #362

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

openFile leaves Neovim in visual mode after it selects a range. When
the next call only places the cursor, moving the cursor in visual mode
would stretch the old selection. The mock now tracks the mode that gv
and <Esc> set, and the new case fails on the current handler.

Part of #362

_Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `xhigh`_
- startLine or endLine set to false now answers -32602 before the file
  opens. The check tests for nil instead of truthiness.
- When endText is not found, openFile places the cursor on the
  startText match with no selection, as the VS Code extension does,
  so the "positioned at" answer is true. It first leaves the visual mode
  an earlier openFile may have left.
- The line count checked before opening now finds a loaded buffer by
  inode, as :edit does, so a symlink, a symlinked directory, or a hard
  link to the file counts the buffer's unsaved lines.
- An inclusive range that ends on an empty line still covers that
  line's line break. No mark position on an empty line avoids it, and
  ending on the line above moves the selection Claude receives off
  endLine. The code and the tools README now say so.

Part of #362

_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 Oct 31, 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-10-31T23:27:40.669042Z 96c5da5 Manual request
🔒 Security Review ✅ Completed 2026-10-31T23:27:58.437150Z 96c5da5 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: b29ca59d2d

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: b29ca59d2d

ℹ️ 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
…ffer

A buffer loaded through a symlink keeps the inode Neovim cached when it
loaded. If the symlink is retargeted, the buffer's name stats as the new
file, but :edit still opens a new buffer for it. The count before
opening now must follow Neovim's own lookup, which the new bufexists()
and bufadd() mocks model. The new case fails on the current handler.

Part of #362

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

Restatting each loaded buffer's name could match a buffer that :edit
would not reuse: after a symlink is retargeted, the buffer's name stats
as the new file, but Neovim still holds the buffer's old inode and opens
a new buffer. The check then counted the old buffer's unsaved lines,
accepted a startLine past the end of the new file, and clamped the
selection to its last line.

bufexists() and bufadd() use Neovim's own lookup, by name or by the
cached inode. bufexists() comes first because bufadd() creates a buffer
when none exists. The spec drops the fs_stat() mocks and the two cases
that only checked them.

Part of #362

_Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `xhigh`_
The Escape existed to leave a Visual mode an earlier openFile left, so
the cursor move would not stretch that selection. Real runs on Neovim
0.8.3 and 0.12.3 show the premise is wrong. The :edit that openFile runs
in the target window already ends Visual and Select mode, whether the
file is the same one or another. When the user is in Visual mode in a
different window, placing the cursor in the target window leaves that
selection alone. The branch never ran, so it goes, with its mode mock
and the test that only checked that mock.

Part of #362

_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. Nice work!

Reviewed commit: 652a2cff20

ℹ️ 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: 652a2cff20

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.

… call

One openFile call can pass both startLine and a startText. The line
range runs gv first and leaves Visual mode on (Select mode when
'selectmode' has "cmd"). When endText is then not found, moving the
cursor in that mode stretches the line selection: real Neovim 0.8.3 and
0.12.3 select "two\nt" where main selects "two". The mock now tracks
the mode that gv, :edit, and <Esc> set. The new case fails on the
current handler.

Part of #362

_Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `xhigh`_
652a2cf removed the Escape on the premise that :edit ends Visual mode.
That holds across calls but not inside one: a call with both startLine
and startText runs gv for the line range first. When endText was then
not found, the cursor move stretched the line selection ("two\nt" on
0.8.3 and 0.12.3). With 'selectmode' set to "cmd", gv enters Select
mode and the second gv typed over the selection ("one|gvhree|four").

openFile now leaves Visual or Select mode before it places the cursor
for a text match. The combined call then only places the cursor when
endText is not found, and selects the text as main did when it is found.

Part of #362

_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. Another round soon, please!

Reviewed commit: 96c5da5ad8

ℹ️ 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: 96c5da5ad8

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
ThomasK33 added this pull request to the merge queue Oct 31, 2026
Merged via the queue into main with commit 37dc8eb Oct 31, 2026
5 checks passed
@ThomasK33
ThomasK33 deleted the fix/open-file-followups branch October 31, 2026 23:49
@github-actions github-actions Bot mentioned this pull request Oct 31, 2026
hareki pushed a commit to hareki/claudecode.nvim that referenced this pull request Nov 1, 2026
)

## Why

This PR is one of the small, reviewed fixes that close the open
follow-up issues in claudecode.nvim. Verifying coder#365 and this PR showed
that `openFile` can change the text of the user's buffer, and that it
can make the wrong kind of selection:

- Select mode replaces the selection with any typed key, and openFile
sent `:normal!` keys while Select mode could be on. With `'selectmode'`
containing `cmd`, `gv` starts Select mode, and the `zz` after it was
typed over a text match: `{startText: "two", endText: "three"}` turned
`one|two|three|four` into `one|zz|four`. When the user held Select mode
in another window, `gv` itself was typed (`gvne|two|three|four` on
Neovim 0.8.3).
- When the user had typed an operator such as `d` and openFile ran while
it waited for a motion, the operator acted on the selection:
`one|two|three|four` became `one||four`.
- `gv` reselects in the buffer's last Visual mode. After `V`, `gH`, or
CTRL-V in that buffer, a text match came out linewise or blockwise.
- Skipping the selection while an operator waited was not enough. The
operator stayed pending, so the user's next motion acted from the line
where the user typed `d`: after `gg0d`, an openFile call for line 150,
and `w`, a 200-line file lost 149 lines (51 left).
- The charwise pass (`v<Esc>`) caused its own `ModeChanged` pair, and
the selection tracker sent Claude a bogus `selection_changed` with the
text `t`.

## What changed

- A new `leave_visual_or_select_mode` helper ends any Visual or Select
mode. `select_range` calls it, then runs a charwise Visual pass
(`v<Esc>`), then sets the marks and runs `gv`. So every selection is
charwise.
- The text path centers the match with `zz` before `gv`, so `gv` is the
last key openFile sends. A selection ends in Visual mode, or in Select
mode when `'selectmode'` has `cmd`.
- When an operator is pending (mode `no`), openFile selects nothing,
places the cursor, and cancels the operator. It feeds `<Esc>` with
`nvim_feedkeys` flags `ni`: `i` puts the key ahead of anything the user
types next, and `n` skips the user's mappings. The answer says `(a
pending operator was cancelled and nothing was selected)`.
- The charwise pass runs as `noautocmd normal! v<Esc>`, so user
`ModeChanged` handlers and the selection tracker see only the final
`gv`.

## Scope

- coder#365 merged as `37dc8eb`. This branch merged `origin/main` without a
rebase. The merge result equals cherry-picking `ab58b00` and `2518d20`
onto main. The new commits are `ab58b00`, `0e789d5`, `ef86836`, and
`2290939` (failing tests), `2518d20`, `615e643`, `545bd09`, and
`037d759` (fixes), and `dbe1731` (marks the new real-Neovim spec as
pending under the busted mock run).
- The window now centers the first line of a text match instead of the
last one.
- `preview: true` still applies the selection to the main window's
buffer. That has another cause (the code targets the main window, but
`pedit` shows the file in the preview window) and is left for its own
fix.

## Blast Radius

The change touches only `openFile` calls that select text or lines. With
`'selectmode'` set to `""` or `mouse,key` and no pending operator, the
selected text and the final mode are the same as before, except that the
selection is now charwise when the buffer's last Visual mode was not.
While an operator is pending, Claude now gets a cursor position instead
of a selection, and the user's operator is cancelled: a `d` typed before
the call does nothing. In Insert mode, Terminal mode, and on the command
line, openFile feeds no `<Esc>`.

## Verification

- The verifier's driver (keys typed through `nvim_input`, call scheduled
the way Claude's arrives): 29 scenarios on Neovim 0.8.3, 0.9.5, 0.10.4,
and 0.12.3, with `'selection'` inclusive and exclusive and 4
`'selectmode'` values (928 runs per tree). There are 1144 violations on
main and 128 on the coder#365 merge (all from a pending `d`), and none on
this head. A violation is a changed or modified buffer, text typed into
another buffer or a terminal, or a selection that differs from the
`'selectmode'` `""` run. Every selection is charwise, including after
`V`, `gH`, and CTRL-V. With a pending operator, the mode stays `no` and
the buffer stays unchanged.
- A second driver run types the user's next key after the call: 9
scenarios × 4 versions × 2 `'selection'` × 4 `'selectmode'`, 32 runs per
scenario. In the 5 scenarios that type `gg0d` in a 200-line file before
the call, main leaves a modified buffer of 96 to 200 lines, and
`615e643` leaves 51 to 101 lines. This head leaves all 200 lines
unmodified in every run. That includes a `w` typed ahead before openFile
runs, and a user `<Esc>` mapping, which ran 0 times. When the call opens
another file, that file (`one|two|three|four`) became `one||four` on
main and `three|four` on `615e643`. It stays unchanged here.
Insert-mode, command-line, and terminal runs give the same results as
`615e643` (0 of 96 differ).
- `tests/integration/open_file_selection_spec.lua` runs the handler in
real Neovim with the selection tracker on: it records only the `n>v`
mode change and no `selection_changed`. It fails before `037d759` on
0.8.3 and 0.12.3 and passes on 0.8.3, 0.9.5, 0.10.4, and 0.12.3.
- The earlier selectmode matrix (36 cases × 4 versions × 2 `'selection'`
× 4 `'selectmode'`, 1152 runs) still shows no changed buffer and the
same results as `2518d20`.
- `busted tests/unit/tools/open_file_spec.lua`: the 5 new cases fail on
the code before their fixes, and all cases pass. `mise run check` and
`mise run test` (810 passing, 1 pending) are green.

Part of coder#362

---
_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
…buffer (coder#373)

## Why

The goal is to clear the open follow-up issues (coder#362 and coder#363 now, coder#350,
coder#326 and coder#335 earlier), one small reviewed PR per bug. Part of coder#363.
This PR handles items 4 and 5.

Item 5: `close_tab` could delete a buffer the user opened. A `tab_name`
without both the `✻` and `⧉` markers skipped the diff path. `close_tab`
then looked up a buffer with `vim.fn.bufnr(tab_name)`, which also
accepts part of a name, or by a file name it took from `tab_name`, and
ran `nvim_buf_delete` on it. On main, on Neovim 0.8.3 and 0.12.3:

- `README.md` and `✻ [Claude Code] README.md (e18e1e)` (closing marker
missing) deleted the user's `README.md` buffer.
- `notes` deleted `notes.txt`, and `x/app.lua` deleted `app.lua`.
- A diff that `openDiff` opened with a plain `tab_name` such as
`plain-tab` stayed open. `close_tab` tried to delete the modified
proposed buffer, failed with `-32000`, and Claude's `openDiff` call
never got an answer.

What the clients do:

- Claude Code 2.1.312 calls `close_tab` only with the `tab_name` it gave
`openDiff`: `✻ [Claude Code] <file name> (<6 hex>) ⧉`. I read both call
sites in the installed CLI bundle. In 2.1.310 and 2.1.311 the call and
its error handling look the same.
- The VS Code extension (2.1.309) closes only the tab whose label equals
`tab_name`. It answers `TAB_CLOSED` even when no tab matches.

`close_tab` now always hands `tab_name` to `diff.close_diff_by_tab_name`
and never deletes a buffer. A name that matches no diff closes nothing.

Item 4: `close_tab` answers `TAB_CLOSED` whether it closed the diff,
kept a diff the user accepted for another client, or found no diff. I
kept that answer and documented it exactly. A different answer text has
no reader. Claude Code 2.1.312 does not read the text: it awaits the
call and logs only a call that fails, so the model never sees it. VS
Code gives the same answer for "no match", and a client written against
VS Code can compare the text with `TAB_CLOSED`.

## What changed

- `lua/claudecode/tools/close_tab.lua`: no marker check and no buffer
lookup or `nvim_buf_delete`. The handler calls
`diff.close_diff_by_tab_name(tab_name, client and client.id or nil)` and
answers `TAB_CLOSED`.
- `tests/unit/tools/close_tab_spec.lua` (new), through
`tools.handle_invoke`:
- A diff opened with the plain tab name `plain-tab` closes, and its
`openDiff` gets `DIFF_REJECTED`.
- `README.md`, `/tmp/project/README.md`, a marked name without `⧉`, and
a full marked name with no diff all answer `TAB_CLOSED` and leave the
user's buffer.
- `tests/unit/tools/tool_log_lines_spec.lua`: I removed the two calls
that drove the deleted buffer paths.
- `PROTOCOL.md` and `lua/claudecode/tools/README.md`: what `close_tab`
closes, and the three cases that answer `TAB_CLOSED`.
- `.agents/skills/verify-diff-lifecycle/covered.lock`: re-recorded. See
Verification item 4.

`diff.lua` does not change.

## Scope

Only `close_tab`. `closeAllDiffTabs`, `openDiff`, and the diff lifecycle
do not change. The answer text does not change.

## Blast Radius

Users whose Claude client sends `close_tab` with a name that matches no
open diff. Before, such a name could delete one of their buffers, or
fail with `-32000` on a modified one. Now it changes nothing and answers
`TAB_CLOSED`. The real Claude Code CLI always sends the name of a diff
it opened, so for its diffs nothing changes. A client that opens a diff
with a plain `tab_name` now gets its diff closed and its `openDiff`
answered by `close_tab`. Before, that diff stayed open.

## Verification

1. **Real Neovim, headless** (`repro.lua`, 0.8.3 and 0.12.3, same result
on both):

   | `close_tab` name | main | this PR |
   | --- | --- | --- |
   | `README.md` | deletes `README.md` | keeps it |
| `✻ [Claude Code] README.md (e18e1e)` | deletes `README.md` | keeps it
|
   | `notes` | deletes `notes.txt` | keeps it |
   | `x/app.lua` | deletes `app.lua` | keeps it |
| `plain-tab` (diff open with that name) | `-32000`, diff stays, no
`openDiff` answer | `TAB_CLOSED`, diff closed, `openDiff` gets
`DIFF_REJECTED` |

2. **verify-claudecode-nvim** (agent-tty, real Neovim 0.12.3,
`ws-client.mjs` as Claude). The user opens `notes.txt`, `app.lua` and
`README.md`, then Claude sends the same `close_tab` calls and two
`openDiff` + `close_tab` pairs.
- main: all three buffers are gone, and the window shows `[No Name]`.
`close_tab plain-tab` answers `-32000`, and the `openDiff` gets no
answer within 5 s. The marked name `✻ [Claude Code] app.lua (a1b2c3) ⧉`
closes its diff with `DIFF_REJECTED`.
- this PR: all three buffers stay listed. Both diffs close, and each
`openDiff` gets `DIFF_REJECTED`. 0 active diffs remain, and the client
stays alive.

   main after the `close_tab` calls:

![main: the user's README.md buffer is
gone](https://github.com/user-attachments/assets/0b1550b4-86ee-4b29-830b-b4b2176fdcdd)

   this PR after the same calls:

![this PR: the user's README.md buffer
stays](https://github.com/user-attachments/assets/8fbedf45-b8ac-4044-9d68-dcd0a9d7a1a4)

3. **Unit tests**: `80ca130` adds 2 tests, and both fail on main. One
finds the plain-tab diff still open, and the other finds the user's
buffer deleted for `README.md`. `b60eacb` makes them pass. `mise run
check` (0 warnings), `mise run test` (812 successes, 0 failures),
`stylua --check`, and `prettier --check` pass on the head commit.
4. **verify-diff-lifecycle**: every fact reads TRUE, and the model
passes (89,205 and 5,269 states). The model already describes
`close_tab` as a close by name for any tab (`ClaudeClosesTab` ->
`CloseByName`), so the model and its facts do not change. On main the
check already read STALE for files changed by coder#364, coder#365, coder#366 and coder#370
(terminal adoption, the `getDiagnostics` and `close_tab` log calls,
`openFile`). None of them reaches diff state or an `openDiff` answer.
`03ca54a` re-records `covered.lock`, and `check.sh` reads PASS.

---
_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