Terminal background color stuck on red after crash
Description
When pasting a large amount of text into the Claude Code input in Neovim, the Claude Code window crashes and exits immediately. Upon reopening with :ClaudeCode, the terminal buffer has a persistent red background that cannot be cleared.
Steps to Reproduce
- Open Neovim
- Run
:ClaudeCodeto open Claude Code - Paste a very large text into the input field
- Claude Code crashes and exits
- Run
:ClaudeCodeagain - The Claude Code window now has a red background
Expected Behavior
The Claude Code window should display with normal colors after reopening, or gracefully handle large input without crashing.
Actual Behavior
- The window crashes when large text is pasted
- After reopening, the output area has a bright red background
- Other Neovim windows in the same session display correctly
- Workarounds like
:bd!,reset,Ctrl-l, and terminal reset escape sequences do not fix the issue
Environment
- OS: macOS (Darwin 24.6.0)
- Neovim: v0.11.5
- Claude Code version: 2.0.72
Screenshots
๐ CodeRabbit Plan Mode
Generate an implementation plan and prompts that you can use with your favorite coding agent.
- [ ] Create Plan
๐ Similar Issues
Related Issues
- https://github.com/greggh/claude-code.nvim/issues/49
- https://github.com/greggh/claude-code.nvim/issues/68
- https://github.com/greggh/claude-code.nvim/issues/67
- https://github.com/greggh/claude-code.nvim/issues/16
๐ค Suggested Assignees
๐งช Issue enrichment is currently in open beta.
To disable automatic issue enrichment, add the following to your .coderabbit.yaml:
issue_enrichment:
auto_enrich:
enabled: false
๐ฌ Have feedback or questions? Drop into our discord or schedule a call!
I resolved by this changes in my nvim plugin.
diff --git a/lua/core/autocmds.lua b/lua/core/autocmds.lua
index e9b71aa..82ef145 100644
--- a/lua/core/autocmds.lua
+++ b/lua/core/autocmds.lua
@@ -10,14 +10,26 @@ aucmd("BufReadPost", {
end
})
--- Highlight trailing whitespace
+-- Highlight trailing whitespace (skip terminal buffers)
aucmd({ "BufWinEnter", "ColorScheme" }, {
callback = function()
+ if vim.bo.buftype == "terminal" then
+ return
+ end
vim.cmd("highlight ExtraWhitespace ctermbg=red guibg=red")
vim.cmd("match ExtraWhitespace /\\s\\+$/")
end
})
+-- Clear match highlighting in terminal buffers
+aucmd({ "TermOpen", "TermEnter", "BufEnter" }, {
+ callback = function()
+ if vim.bo.buftype == "terminal" then
+ vim.fn.clearmatches()
+ end
+ end
+})
+
-- Auto-create directories on save
aucmd("BufWritePre", {
callback = function(event)