A Neovim plugin that integrates with Anthropic's Claude AI model directly in your editor, providing AI-powered assistance for your coding workflows.
- Interactive Chat Interface: Communicate with Claude within Neovim
- Code-Specific Interface: Send code for refactoring, optimization, or explanation
- Visual Selection Support: Select code and send it to Claude with a simple command
- Direct Code Application: Apply Claude's suggestions directly to your buffer
- Response Continuation: Continue Claude's responses when they get truncated
- Token Usage Monitoring: Track your API usage with built-in token counters
- Adaptive UI: Interface adapts to window size for optimal screen usage
- Neovim 0.7.0 or later
- An Anthropic API key (Claude API access)
curlinstalled on your system
Using lazy.nvim
{
'IntoTheNull/claude.nvim',
config = function()
require('claude').setup({
-- Your configuration here (see Configuration section)
})
end,
-- Add keymaps in the keys table (LazyVim style)
keys = {
-- Chat interface
{ "<leader>ac", "<cmd>Claude<cr>", desc = "Open Claude Chat" },
-- Coding interface
{ "<leader>ar",
":<C-u>ClaudeCoding<CR>",
mode = "v",
desc = "Refactor with Claude"
},
},
}Using packer.nvim
use {
'IntoTheNull/claude.nvim',
config = function()
require('claude').setup({
-- Your configuration here
})
-- Add keymaps manually
vim.api.nvim_set_keymap('v', '<leader>ar', ':<C-u>ClaudeCoding<CR>',
{ noremap = true, silent = true, desc = "Refactor with Claude" })
vim.api.nvim_set_keymap('n', '<leader>ac', '<cmd>Claude<cr>',
{ noremap = true, silent = true, desc = "Open Claude Chat" })
end
}Using vim-plug
Plug 'IntoTheNull/claude.nvim'
" Set up keymaps in your vimrc after plugin loads
vnoremap <leader>ar :<C-u>ClaudeCoding<CR>
nnoremap <leader>ac :Claude<CR>Add the following to your Neovim configuration:
require('claude').setup({
-- Command to retrieve your API key (required)
-- SECURITY NOTE: This should be a command that fetches from a secure store
-- rather than hardcoding the key directly in your config
api_key_cmd = "cat ~/.config/claude/api_key.txt",
-- Model selection (optional)
model = "claude-3-7-sonnet-20250219", -- Default to the latest model
-- Token limits (optional)
max_tokens = 4000,
-- Model parameters (optional)
temperature = 0.7,
top_p = 1.0,
-- UI customization (optional)
window = {
-- These sizes are now relative maximums (98% on large screens, 97% on small)
width = 0.8, -- Base percentage of window width
height = 0.8, -- Base percentage of window height
border = "rounded", -- Border style: "none", "single", "double", "rounded"
},
-- Keybindings (optional)
keymaps = {
close = "<C-c>",
submit = "<C-CR>",
yank_last = "<C-y>",
scroll_up = "<C-k>",
scroll_down = "<C-j>",
help = "<C-h>",
quit = "q",
continue = "<C-u>",
},
-- Behavior options
silent = false, -- Set to true to disable popup notifications
show_token_count = true, -- Show token usage information
})Open the chat interface with:
:Claude
Or use your configured keymap (e.g., <leader>ac).
In the chat interface:
- Type your message in the input field
- Send with
<C-CR>(Ctrl+Enter) orEnterin normal mode - Close with
<C-c>orq - Copy Claude's last response with
<C-y> - Navigate chat history with
<C-k>(up) and<C-j>(down) - Get help with
<C-h> - Continue a previous response with
<C-u>or by typing "continue" and pressing Enter
-
Select code in visual mode and use:
:ClaudeCodingOr use your configured visual mode keymap (e.g.,
<leader>ar). -
Enter instructions for Claude in the bottom panel
-
Press
<C-s>orEnter(in normal mode) to submit
Key bindings in the coding interface:
<C-s>: Submit code for processing<C-i>: Use Claude's output as new input (iterate)<C-y>: Copy Claude's code to clipboard<C-a>: Apply code to original buffer<Tab>: Cycle focus between panels<C-h>: Show help windowq: Close coding interface
:ClaudeSubmitLine: Submit current line to Claude and copy response to clipboard:ClaudeSubmitRange: Submit selected range to Claude and copy response to clipboard:ClaudeContinue: Continue the previous response:ClaudeCodingResize: Manual trigger for resizing the coding interface
- Run
:Claudeor press your chat keymap (e.g.,<leader>ac) - Ask a question: "Explain the difference between promises and async/await in JavaScript."
- Press
<C-CR>to send
- Select code in visual mode
- Press your refactor keymap (e.g.,
<leader>ar) - Enter an instruction: "Refactor this code to use async/await instead of callbacks"
- Press
<C-s>to submit - Review the output and press
<C-a>to apply changes to your original buffer
-- Access Claude programmatically
local claude = require('claude')
-- Send a message and handle the response
claude.api.send_message(claude, "Explain the visitor pattern", function(response)
print(response)
end)The project includes a linting configuration for luacheck:
# Run the linter
./scripts/lint.shSee LINTING.md for more details.
The project includes a comprehensive test suite using Plenary.nvim:
# Run the tests
./scripts/run_tests.shSee TESTING.md for more details on writing and running tests.
If you see "Failed to get API key" errors:
- Check that your
api_key_cmdreturns a valid API key - Ensure there are no extra newlines or whitespace in the key
- Verify your API key has permissions for the model you're using
If the interface doesn't resize properly:
- Try the
:ClaudeCodingResizecommand to manually trigger resize - Check for conflicts with other UI plugins
If keybindings aren't working:
- Check for mapping conflicts with
:verbose map <key> - Ensure your terminal supports the key combinations
- Try using the commands directly (e.g.,
:Claudeinstead of the keymap)
For security considerations, see SECURITY.md.
MIT
- Anthropic for creating Claude
- All contributors to this project