Description
Bug Description
When using claudecode.nvim with a custom window layout (e.g., 30:70 sidebar ratio), performing diff operations or file creation causes all windows to suddenly resize to equal 50:50 ratios, breaking the user's carefully configured layout.
To Reproduce
- Set up Neovim with a sidebar (e.g., neo-tree, nvim-tree) at 30% width ratio
- Use Claude Code to perform any of these operations:
- Create a new file
- Open a diff view
- Execute git diff commands
- Expected: Window ratios remain unchanged (30:70)
- Actual: All windows suddenly resize to equal ratios (50:50)
Visual Example
Before (desired layout):
┌─────────────────────────────────┬──────────┐
│ Main Editor │ Sidebar │
│ 70% │ 30% │
│ │ │
└─────────────────────────────────┴──────────┘
After diff operation (broken layout):
┌─────────────────┬─────────────────┐
│ Sidebar │ Main Editor │
│ 50% │ 50% │
│ │ │
└─────────────────┴─────────────────┘
## Expected Behavior
A clear and concise description of what you expected to happen.
## Environment
- Neovim version: [e.g. 0.9.2]
- Claude Code CLI version: [e.g. 1.0.0]
- OS: [e.g. macOS 14.1]
- Plugin version: [e.g. 0.1.0]
## Error Messages
If applicable, add error messages or logs.
Paste any error messages here
## Root Cause
The issue is caused by `vim.cmd("wincmd =")` commands in the diff module that force all windows to equal sizes, ignoring existing window ratios.
**Affected code locations:**
- `lua/claudecode/diff.lua:262` in `_open_native_diff()` function
- `lua/claudecode/diff.lua:671` in `_create_diff_view_from_window()` function
## Code Analysis
```lua
-- In _open_native_diff() function (line 262)
vim.cmd("edit " .. vim.fn.fnameescape(old_file_path))
vim.cmd("diffthis")
vim.cmd("vsplit")
vim.cmd("edit " .. vim.fn.fnameescape(tmp_file))
-- ...
vim.cmd("wincmd =") -- ← This line causes the issue
The wincmd =
command equalizes all window sizes in the current tab, overriding any custom ratios the user has set up.
Impact
- Severity: High - Disrupts user workflow and breaks carefully configured layouts
- Frequency: Every time diff operations or file creation is performed
- User Experience: Very disruptive, forces users to manually resize windows after each operation
Suggested Fix
Replace vim.cmd("wincmd =")
with more targeted window sizing that only affects the diff windows:
-- Instead of: vim.cmd("wincmd =")
-- Use targeted sizing for just the diff windows:
local diff_width = math.floor(vim.api.nvim_win_get_width(target_window) / 2)
vim.api.nvim_win_set_width(new_win, diff_width)
Or preserve and restore original window ratios:
-- Before diff operation:
local original_widths = {}
for _, win in ipairs(vim.api.nvim_list_wins()) do
original_widths[win] = vim.api.nvim_win_get_width(win)
end
-- After diff setup, restore non-diff windows to original sizes
-- (instead of using wincmd =)
Workaround
Currently, users must manually resize their windows back to the desired ratios after each diff operation.
Additional Context
This affects users who have:
- File explorers (neo-tree, nvim-tree) with custom widths
- Multiple split layouts with specific ratios
- Any non-equal window arrangements
The issue occurs with both the snacks.nvim terminal provider and native Neovim terminal fallback.