A lightweight bridge between Neovim and Claude Code CLI, enabling real-time selection sharing without complex plugins.
- Real-time selection tracking - Your Neovim selection is captured as you select
- Automatic context injection - Claude Code receives your selection when you send a message
- tmux statusbar integration - See your current selection in the tmux status bar
- Zero dependencies - Just Lua, Bash, and your existing tools
- Works with tmux - No need for Neovim splits; use your existing tmux panes
┌─────────────────┐ ┌──────────────────────┐ ┌─────────────────┐
│ Neovim │────────▶│ /tmp/nvim_selection │◀────────│ Claude Code │
│ (visual mode) │ │ .txt │ │ (hook) │
└─────────────────┘ └──────────────────────┘ └─────────────────┘
│ │
│ ▼
│ ┌──────────────────┐
└──────────────────▶│ tmux statusbar │
│ (real-time) │
└──────────────────┘
git clone https://github.com/YOUR_USERNAME/claude-nvim-bridge.git
cd claude-nvim-bridge
./install.sh- Copy the Lua module to your Neovim config:
cp lua/claude-selection.lua ~/.config/nvim/lua/- Add to your
init.lua:
require('claude-selection').setup()- Install Claude Code hooks:
mkdir -p ~/.claude/hooks
cp hooks/nvim-selection.sh ~/.claude/hooks/
chmod +x ~/.claude/hooks/nvim-selection.sh- Add to
~/.claude/settings.json:
{
"hooks": {
"UserPromptSubmit": [
{
"matcher": "",
"hooks": [
{
"type": "command",
"command": "~/.claude/hooks/nvim-selection.sh"
}
]
}
]
}
}- (Optional) tmux statusbar integration:
cp hooks/tmux-selection.sh ~/.claude/hooks/
chmod +x ~/.claude/hooks/tmux-selection.shAdd to ~/.tmux.conf:
# Claude selection in statusbar
set -g status-style 'bg=#1a1a1a fg=#888888'
set -g status-justify centre
set -g status-right-length 100
set -g window-status-current-format '#(~/.claude/hooks/tmux-selection.sh)'
set -g window-status-format ''
set -g status-interval 1Reload tmux: Ctrl+b r or tmux source-file ~/.tmux.conf
- Open Neovim in one tmux pane, Claude Code in another
- Select text in Neovim (visual mode:
v,V, orCtrl-V) - The selection appears in your tmux statusbar in real-time
- Send a message to Claude Code
- Claude automatically sees your selection with file path and line numbers
Example of what Claude receives:
=== Neovim Selection ===
File: /path/to/file.py:42-48
def calculate_albedo(surface, wavelength):
"""Calculate surface albedo for given wavelength."""
return surface.reflectance(wavelength)
=== End Selection ===
require('claude-selection').setup({
selection_file = '/tmp/nvim_selection.txt', -- Where to write selections
enable_autocmd = true, -- Auto-capture on cursor move
})Edit ~/.claude/hooks/tmux-selection.sh to change:
- Colors (default: cyan for filename, white for content)
- Content preview length (default: 30 characters)
- Format of the display
- Neovim autocmd listens to
CursorMovedevents in visual mode - On each cursor movement, the current selection is written to
/tmp/nvim_selection.txt - Claude Code hook (
UserPromptSubmit) reads this file when you send a message - The file content is injected as context into your conversation
- tmux statusbar (optional) polls the file every second for real-time display
| Feature | claude-nvim-bridge | claudecode.nvim |
|---|---|---|
| Dependencies | None | WebSocket, snacks.nvim |
| Setup complexity | Simple | More complex |
| Real-time tracking | Yes (file-based) | Yes (WebSocket) |
| tmux integration | Built-in | Requires provider config |
| Selection injection | Via hook | Native protocol |
| Diff support | No | Yes |
| @ mentions | No | Yes |
Use this if: You want a simple, hackable solution that works with tmux.
Use claudecode.nvim if: You need full IDE features (diffs, @ mentions, etc.)
- Check the hook script is executable:
chmod +x ~/.claude/hooks/nvim-selection.sh - Verify the file is being written:
cat /tmp/nvim_selection.txt - Check Claude Code settings:
cat ~/.claude/settings.json
- Reload tmux config:
Ctrl+b r - Check script is executable:
chmod +x ~/.claude/hooks/tmux-selection.sh - Test manually:
~/.claude/hooks/tmux-selection.sh
This can happen with edge cases. Try selecting at least 2 characters.
PRs welcome! Ideas for improvements:
- Support for multiple selection files (per-project)
- Integration with other AI tools (Copilot, Cursor, etc.)
- Vim support (not just Neovim)
- Better handling of very long selections
MIT License - See LICENSE
- Inspired by claudecode.nvim
- Built for use with Claude Code by Anthropic
