[FEATURE] IDE Integration
Claude Code now has IDE integration with VSCode/Intellij through an MCP server provided by an extension.
I believe similar integration should be possible in Neovim.
I'm hoping they open-source the extensions or properly document the API for IDE integration, though it appears to be very simple by looking at the (obfuscated) VSCode extension.
See: https://github.com/anthropics/claude-code/issues/1234
That integration looked great in the presentation. I hope they release some docs, otherwise we'll just have to deobfuscate that code and see what we can do. I won't have time to do that for the next few days, but early next week i'll try to give it a look.
There are some light docs here https://docs.anthropic.com/en/docs/claude-code/sdk.
Not related to the IDE integration unfortunately. Ideally we can use the IDE MCP integration that VSCode has to get diffs in Nvim instead of in the terminal. (Not using the CLI as an SDK)
I'm pretty sure the VS Code extension shows diffs by exposing an openDiff MCP tool. The docs I linked show how to start Claude with additional MCP servers, which should be all you need to expose an openDiff tool.
https://docs.anthropic.com/en/docs/claude-code/sdk#mcp-configuration
They also show how to run Claude in non-interactive mode with multi-turn conversations and JSON streaming, which could be used to build a custom UI (which even the VS Code extension doesn't have, yet).
https://docs.anthropic.com/en/docs/claude-code/sdk#session-management
Yeah, it seems like it's just a matter of exposing specific tools. I don't think it's as simple as exposing any arbitrary tool though. There is some specific integrations that are used even without the LLM actually calling the tool. E.g. it will show that you have a file open or text selected in the bottom right even before any messages are sent.
can we throw claude code at the problem? i volunteer as tribute
it works. needs obvious cleaning up. and more testing. first time vibe coding. ngl was kinda fun!
Very exciting, @thatguyinabeanie!
Took a brief look, but don't have time to dig in too deeply at the moment.
Does this expose a traditional MCP server or were you able to reverse any of the context features of claude-code's builtin IDE integrations? (E.g. showing current file/current selection)
I don't believe these are traditional MCP tool calls but are instead pushed to claude-code? Not sure if that's a standard MCP feature or not. 🤔
@garrett-hopper broooo. claude vibe coded the heck out of that in like 5 minutes. its wild!!
this is getting reaaly close to being complete.
idk why github actions wont pick up to run the test. maybe config on your end? @greggh? probably because im not a maintainer on the repo.
This may or may not be helpful: https://twitter.com/hrishioa/status/1929544709585912308
This would be great, looking forward to it
this is getting reaaly close to being complete.
idk why github actions wont pick up to run the test. maybe config on your end? @greggh? probably because im not a maintainer on the repo.
Definitely my fault there. I'll get that all fixed up this weekend. Been a busy week of kids graduating.
I've cleaned up the actions, basically made it a lot less strict for now.
this is getting reaaly close to being complete.
idk why github actions wont pick up to run the test. maybe config on your end? @greggh? probably because im not a maintainer on the repo.
I could definitely use the help here if you were volunteering to help maintain...
https://github.com/coder/claudecode.nvim/ has put in a lot of hard yards with regards to IDE support. I wonder if there's a more programmatic and repeatable way to de-obfuscate the VScode plugin for continued development to try and keep up.
Waiting as well for a proper solution.
In the meantime, here's my hack for focused file/text selection awareness:
Whenever you leave a buffer (main case, switching to the Claude-Code window), it will store the full name of the file, if in normal mode and if visually selected any text, additional selection range will be added. The hook reads from this single-line file and injects it to the prompt.
:)
add to init.lua:
-- Global variables to store last visual selection range
_G.last_visual_start = nil
_G.last_visual_end = nil
vim.api.nvim_create_autocmd("ModeChanged", {
pattern = "*",
callback = function(event)
local from_to = event.match
if from_to == "v:n" or from_to == "V:n" or from_to == "\22:n" then
-- Exiting visual mode
local start_pos = vim.fn.getpos("'<")
local end_pos = vim.fn.getpos("'>")
print(string.format("Exited visual mode, selection lines: %d to %d", start_pos[2], end_pos[2]))
_G.last_visual_start = start_pos[2]
_G.last_visual_end = end_pos[2]
elseif from_to:match("n:") then
-- Entering normal mode directly: clear selection
_G.last_visual_start = nil
_G.last_visual_end = nil
end
end,
})
local home_dir = os.getenv("HOME")
local target_fn = home_dir .. "/.claude/nvim_buffer_info"
vim.api.nvim_create_autocmd("BufLeave", {
callback = function(event)
local bufnr = event.buf
local bufname = vim.api.nvim_buf_get_name(bufnr)
local filename = vim.fn.fnamemodify(bufname, ":p") -- absolute path
local output
if _G.last_visual_start and _G.last_visual_end then
output = string.format("%s:%d-%d", filename, _G.last_visual_start, _G.last_visual_end)
else
output = filename
end
local f = io.open(target_fn, "w")
if f then
f:write(output .. "\n")
f:close()
else
vim.notify("Failed to write to " .. target_fn, vim.log.levels.ERROR)
end
end,
})
add a hook in claude:
in my case: ~/.claude/hooks/UserPromptSubmit/prompt_inject_nvim_buffer_info
#!/usr/bin/env -S uv run --script
import json
import sys
"""prompt_inject_nvim_buffer_info.py
{
"session_id": "abc123",
"transcript_path": "/Users/.../.claude/projects/.../00893aaf-19fa-41d2-8238-13269b9b3ca0.jsonl",
"cwd": "/Users/...",
"hook_event_name": "UserPromptSubmit",
"prompt": "Write a function to calculate the factorial of a number"
}
"""
try:
with open('/Users/user/.claude/nvim_buffer_info', 'r') as f:
nvim_buffer_info = f.read()
output = json.load(sys.stdin)
output['prompt'] = f'@{nvim_buffer_info} ' + output['prompt']
print(output)
# Allow the prompt to proceed with the additional context
sys.exit(0)
except Exception:
# Allow the prompt to proceed without the additional context
sys.exit(1)
and in ~/.claude/settings.json :
insert this section under hooks:
"UserPromptSubmit": [
{
"matcher": "",
"hooks": [
{
"type": "command",
"command": "uv run /Users/user/.claude/hooks/UserPromptSubmit/prompt_inject_nvim_buffer_info.py"
}
]
}
]
[I used uv package to run but should run also with direct python call]
Doesn't this plugin already have that? https://github.com/coder/claudecode.nvim
I'm wondering, what are the benefits of using this one if it does not have this IDE integration over the one I linked?