A Neovim plugin that provides seamless integration between Neovim and Claude Code or other similar terminal based coding agent like OpenCode, allowing you to send file context and queries directly to the agent from within your Neovim either via CLI or tmux. Messages can be sent to the agent in another tmux terminal or to a chat buffer split within Neovim.
The goal of this plugin is not to provide the full IDE experience that Claude Code offers. This plugin aims to make it easy to chat with claude code without running a terminal inside Neovim, and to interact with a Claude Code session already running in agent mode in another terminal via tmux (or clipboard).
- Context Sharing: Send current file, all open buffers, or line ranges to Claude Code
- Tmux Integration: Flexible targeting - window name, current window, or process search
- Interactive Chat: Query Claude Code with persistent chat buffer
- Interactive Prompts: Edit context and add questions before sending (uses Telescope if available)
- Git Integration: Send git diffs and recently changed files as context
- Visual Mode Support: Send selected line ranges as context
- Fallback Support: Copies context to clipboard when tmux is unavailable
- Neovim 0.7+
- Claude Code CLI installed and configured
- tmux (optional, for automatic window switching)
Using lazy.nvim
{
"samir-roy/code-bridge.nvim",
config = function()
require('code-bridge').setup({
tmux = {
target_mode = 'window_name', -- 'window_name', 'current_window', 'find_process'
window_name = 'claude', -- used when target_mode = 'window_name'
process_name = 'claude', -- used when target_mode = 'current_window' or 'find_process'
switch_to_target = true, -- whether to switch to target after sending
},
interactive = {
use_telescope = true, -- use telescope for interactive prompts (default: true)
}
})
end
}Using packer.nvim
use {
"samir-roy/code-bridge.nvim",
config = function()
require('code-bridge').setup()
end
}Clone this repository to your Neovim configuration directory:
git clone https://github.com/samir-roy/code-bridge.nvim ~/.config/nvim/pack/plugins/start/code-bridge.nvimThen add to your init.lua:
require('code-bridge').setup()The plugin provides extensive commands for different workflows:
Send current file context to the agent via tmux. Works in normal and visual mode.
:CodeBridgeTmux
:'<,'>CodeBridgeTmux " with visual selectionSend all open buffers as context. In visual mode, includes your selection from current file plus all other buffers.
Context Format:
- Normal mode:
@filename.ext - Visual mode:
@filename.ext#L1-5
Edit the context prompt before sending (uses Telescope input if available).
Edit all-buffers context prompt before sending.
Send current git changes (unstaged) to the agent.
Send staged changes only to the agent.
Send recently modified files. In git repos: prioritizes pending changes + recent commits. Outside git: uses Vim's recent files.
Edit recent files context before sending.
Opens an interactive chat with the coding agent inside Neovim itself. A persistent markdown buffer for the conversation is opened in a split pane. Your message along with the file context is sent to the agent and the response is shown in the conversation buffer. Subsequent messages are part of the same chat thread as long as the chat pane is kept open. Closing the pane clears the chat history.
Similar to :CodeBridgeQuery but without file context - useful for general questions.
Hides the chat buffer window without clearing the chat history. The chat buffer remains in memory and can be reopened with the next query or with the show command.
Shows the chat buffer window if it exists but is hidden.
Clears the chat history and closes the chat. This also cancels any running queries.
Cancels any currently running query.
For optimal experience, set up a tmux session with a window named "claude":
# Create or attach to tmux session
tmux new-session -d -s coding
# Create claude window
tmux new-window -t coding -n claude
# Start Claude Code in the claude window
tmux send-keys -t coding:claude 'claude' EnterThe plugin will:
- Check if you're in a tmux session
- Find the claude target based on your configuration:
- window_name: Look for a window named "claude"
- current_window: Search for claude process in current window only
- find_process: Search all panes across all windows for claude process
- Send the context and optionally switch to the target
- Fall back to clipboard if tmux is unavailable or target not found
Add these to your configuration for quick access:
-- Basic tmux commands
vim.keymap.set("n", "<leader>ct", ":CodeBridgeTmux<CR>", { desc = "Send file to claude" })
vim.keymap.set("v", "<leader>ct", ":CodeBridgeTmux<CR>", { desc = "Send selection to claude" })
vim.keymap.set("n", "<leader>ca", ":CodeBridgeTmuxAll<CR>", { desc = "Send all buffers to claude" })
-- Advanced tmux commands
vim.keymap.set("n", "<leader>ci", ":CodeBridgeTmuxInteractive<CR>", { desc = "Interactive prompt to claude" })
vim.keymap.set("n", "<leader>cd", ":CodeBridgeTmuxDiff<CR>", { desc = "Send git diff to claude" })
vim.keymap.set("n", "<leader>cr", ":CodeBridgeTmuxRecent<CR>", { desc = "Send recent files to claude" })
-- Chat interface
vim.keymap.set("n", "<leader>cq", ":CodeBridgeQuery<CR>", { desc = "Query claude with context" })
vim.keymap.set("v", "<leader>cq", ":CodeBridgeQuery<CR>", { desc = "Query claude with selection" })
vim.keymap.set("n", "<leader>cc", ":CodeBridgeChat<CR>", { desc = "Chat with claude" })
vim.keymap.set("n", "<leader>ch", ":CodeBridgeHide<CR>", { desc = "Hide chat window" })
vim.keymap.set("n", "<leader>cs", ":CodeBridgeShow<CR>", { desc = "Show chat window" })
vim.keymap.set("n", "<leader>cx", ":CodeBridgeWipe<CR>", { desc = "Wipe chat and clear history" })
vim.keymap.set("n", "<leader>ck", ":CodeBridgeCancelQuery<CR>", { desc = "Cancel running query" })The plugin works out of the box with no configuration required. The following options are available:
target_mode: How to find claude ('window_name','current_window','find_process')window_name: Window name to search for when using'window_name'mode (default:'claude')process_name: Process name to search for when using'current_window'or'find_process'mode (default:'claude')switch_to_target: Whether to switch to the target after sending context (default:true)use_telescope: Use Telescope for interactive prompts when available (default:true)
The plugin can be configured with various tmux targeting modes:
'window_name' (default): Search for a tmux window by name
require('code-bridge').setup({
tmux = {
target_mode = 'window_name',
window_name = 'claude', -- window name to search for
},
interactive = {
use_telescope = true, -- use telescope for interactive prompts
}
})'current_window': Search for claude process in the current tmux window
require('code-bridge').setup({
tmux = {
target_mode = 'current_window',
process_name = 'claude',
switch_to_target = true, -- switch to claude pane after sending
}
})'find_process': Find any pane running a claude process
require('code-bridge').setup({
tmux = {
target_mode = 'find_process',
process_name = 'claude', -- process name to search for
}
})- Open a file in Neovim
- Select some lines in visual mode
- Run
:CodeBridgeQuery - Type your question about the selected code
- View Claude's response in the chat buffer
- Continue the conversation with follow-up queries
- Make changes to your code
- Run
:CodeBridgeTmuxDiffto send git changes to Claude - Claude analyzes your changes and provides feedback
- Open several related files in Neovim
- Select important code in current file (visual mode)
- Run
:CodeBridgeTmuxAllInteractive - Add question like "How do these components work together?"
- Claude gets context from all files plus your selection
- Working on a project over time
- Run
:CodeBridgeTmuxRecentto send recent changes - Ask your question like "Summarize recent changes"
| Command | Purpose | Context |
|---|---|---|
:CodeBridgeTmux |
Basic file sending | Current file/selection |
:CodeBridgeTmuxAll |
Multi-file analysis | All open buffers |
:CodeBridgeTmuxInteractive |
Edit prompt first | Current file + your question |
:CodeBridgeTmuxAllInteractive |
Edit multi-file prompt | All buffers + your question |
:CodeBridgeTmuxDiff |
Code review | Git changes (unstaged) |
:CodeBridgeTmuxDiffStaged |
Staged review | Git changes (staged) |
:CodeBridgeTmuxRecent |
Recent context | Recent files + pending changes |
:CodeBridgeTmuxRecentInteractive |
Edit recent context | Recent files + your question |
:CodeBridgeQuery |
Interactive chat | File context + chat UI |
:CodeBridgeChat |
Simple chat | Chat UI only |
Licensed under the GNU General Public License v2.0. See LICENSE for details.
Issues and pull requests are welcome! Please ensure your contributions align with the project's goals of providing a Neovim-Claude integration that does not open a terminal inside Neovim and continue using existing Claude Code session in another terminal.
