Skip to content

[BUG] Neovim crashes when accepting new file diff with render-markdown.nvim installed #218

@tomerlevy1

Description

@tomerlevy1

Description

Neovim crashes (exit code 139) when accepting a new file diff via :w with render-markdown.nvim installed. Existing file diffs work fine — this only happens with new files.

Minimal Reproduction

-- Save as repro.lua, run: nvim -u repro.lua
vim.g.mapleader = " "
vim.g.maplocalleader = "\\"

local lazypath = vim.fn.stdpath("data") .. "/lazy-repro/lazy.nvim"
if not vim.uv.fs_stat(lazypath) then
	vim.fn.system({
		"git",
		"clone",
		"--filter=blob:none",
		"--branch=stable",
		"https://github.com/folke/lazy.nvim.git",
		lazypath,
	})
end
vim.opt.rtp:prepend(lazypath)

require("lazy").setup({
	{
		"folke/snacks.nvim",
		priority = 1000,
		lazy = false,
		opts = {},
	},
	{
		"coder/claudecode.nvim",
		opts = {
			terminal = { split_side = "left", split_width_percentage = 0.5 },
			diff_opts = { open_in_new_tab = true, hide_terminal_in_new_tab = true },
		},
		keys = { { "<C-,>", "<cmd>ClaudeCode<cr>", desc = "Toggle Claude" } },
	},
	{
		"MeanderingProgrammer/render-markdown.nvim",
		dependencies = { "nvim-treesitter/nvim-treesitter", "nvim-tree/nvim-web-devicons" },
		opts = {},
	},
}, { root = vim.fn.stdpath("data") .. "/lazy-repro" })

Steps to Reproduce

  1. Start Neovim with the config above
  2. Open Claude terminal (<C-,>)
  3. Ask Claude to create a new .md file
  4. When the diff appears, make sure cursor is in the proposed (right) buffer
  5. Type :w to accept
  6. Neovim crashes with exit code 139

What I've found so far

  • Only happens with new files, not existing file diffs
  • Removing render-markdown.nvim prevents the crash
  • I added file-based logging (breadcrumbs) throughout the code. All the Lua code in _resolve_diff_as_saved() and the BufWriteCmd callback completes successfully — the crash seems to happen after the callback returns control back to Neovim
  • Adding pcall(vim.cmd, "diffoff") at the end of the BufWriteCmd callback (after _resolve_diff_as_saved but before return true) prevents the crash. I'm not 100% sure why, but it seems like turning off diff mode before Neovim does its post-write redraw avoids whatever triggers the crash
  • I wasn't able to reproduce the crash outside of claudecode's MCP flow (i.e., manually setting up the same buffer/diff state doesn't crash), so there may be a timing or event-loop component I don't fully understand

Suggested fix

This one-liner in register_diff_autocmds prevents the crash, and all existing tests pass with it:

callback = function()
    M._resolve_diff_as_saved(tab_name, new_buffer)
    pcall(vim.cmd, "diffoff")  -- prevents crash with render-markdown.nvim
    return true
end,

Environment

  • Neovim: 0.11.0
  • OS: macOS (Darwin 24.6.0)
  • render-markdown.nvim: latest
  • claudecode.nvim: latest

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions