Skip to content

fix(close_tab): close only the diff with that tab name, never a user buffer - #373

Merged
ThomasK33 merged 4 commits into
mainfrom
fix/close-tab-followups
Nov 1, 2026
Merged

ThomasK33 merged 4 commits into
mainfrom
fix/close-tab-followups

Conversation

@ThomasK33

Copy link
Copy Markdown
Member

Why

The goal is to clear the open follow-up issues (#362 and #363 now, #350, #326 and #335 earlier), one small reviewed PR per bug. Part of #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

    this PR after the same calls:

    this PR: the user's README.md buffer stays

  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 fix(terminal): adopt a native terminal only while its job has not ended #364, fix(open_file): close the openFile gaps from #362 #365, fix(tools): pass the component first in close_tab and getDiagnostics log calls #366 and fix(open_file): never change the buffer when openFile selects #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 • Model: anthropic:claude-opus-5-5 • Thinking: xhigh

…t markers

close_tab skipped the diff path for a tab name without both the `✻` and `⧉`
markers. It then looked for a buffer by that name, or by a file name taken from
it, and deleted that buffer. A user's README.md buffer went away for the name
`README.md` or for a marked name that lost its closing marker. A diff opened
with a plain tab name stayed open, and its openDiff call never got an answer.

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

Claude Code calls close_tab only with the tab_name it gave openDiff, and the
VS Code extension closes only a tab whose label equals that name. close_tab
now always hands the name to diff.close_diff_by_tab_name and never deletes a
buffer. A name that matches no diff closes nothing.

The answer stays TAB_CLOSED in every case. Claude Code 2.1.312 does not read
the text (it logs only a failed call), and VS Code answers TAB_CLOSED when no
tab matches. PROTOCOL.md and the tools README now say exactly when.

_Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `xhigh`_
The model already describes close_tab as a close by name for any tab
(ClaudeClosesTab -> CloseByName), and every fact still reads TRUE, so the
model and its facts do not change. check.sh passes.

The record also confirms four files that changed on main since the last
record and cannot reach diff state or an openDiff answer: terminal/native.lua
(#364), tools/get_diagnostics.lua and the close_tab log calls (#366), and
tools/open_file.lua (#365, #370).

_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-01T02:11:42.727527Z 03ca54a Manual request
🔒 Security Review ✅ Completed 2026-11-01T02:12:53.901236Z 03ca54a 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 Review: Didn't find any major issues. Hooray!

Reviewed commit: 03ca54ac25

ℹ️ 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: 03ca54ac25

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.

…emoved

The open-diff gotcha still said close_tab matches other names as buffer
names. After this PR it closes only the diff with that exact tab name.

_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 22b1772 Nov 1, 2026
5 checks passed
@ThomasK33
ThomasK33 deleted the fix/close-tab-followups branch November 1, 2026 02:29
@github-actions github-actions Bot mentioned this pull request Nov 1, 2026
ThomasK33 added a commit that referenced this pull request Nov 1, 2026
Re-recorded on the merge with main (#373, #367, #372). The facts and the
model are unchanged by the merge, and check.sh passes. The only covered
file main changed outside the record is selection.lua, which cannot reach
diff state.

Part of #363

_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