Open terminal-based AI coding agents inside Neovim and send editor context to them.
ai-harness.nvim is a small Neovim wrapper around command-line AI tools such as pi, claude, codex, aider, or any other interactive command that can run in a terminal.
It does not implement its own AI chat UI. Authentication, model selection, permissions, and tool execution are handled by the AI harness command you choose to run.
- Open an AI harness in a left/right/top/bottom split, tab, or floating window.
- Send useful editor context to the harness:
- current file
- visual selection/range
- visible lines
- open buffers
- diagnostics
- git diffs
- Highlight file references in AI output, such as
src/main.lua:42:3. - Jump from AI output back into Neovim with
gfor mouse click.
- Neovim 0.10 or newer recommended.
- At least one terminal AI harness installed and available in
$PATH, for example:piclaudecodexaider
With lazy.nvim:
{
"juantot9/ai-harness.nvim",
config = function()
require("ai-harness").setup({
default_cmd = "pi",
window = {
type = "split",
position = "right",
size = 0.35,
full_height = true,
},
})
end,
}Use a different default harness if preferred:
require("ai-harness").setup({
default_cmd = "claude",
})Open the default harness:
:AIHarnessOpenOpen a specific command:
:AIHarnessOpen claude
:AIHarnessOpen aiderSend the current file:
:AIHarnessSendFileSend a visual selection:
:'<,'>AIHarnessSendSelectionWhen the AI output contains a reference like this:
lua/ai-harness/init.lua:10
Move the cursor over it and press gf, or click the highlighted reference.
:AIHarnessOpen [cmd]
:AIHarnessToggle [cmd]
:AIHarnessSendFile
:'<,'>AIHarnessSendSelection
:AIHarnessSendVisible
:AIHarnessSendOpenBuffers
:AIHarnessSendDiagnostics
:AIHarnessSendGitDiff
:AIHarnessSendGitDiffStaged
:AIHarnessGotoReference [file[:line[:col]]]local ai = require("ai-harness")
vim.keymap.set("n", "<leader>aa", function() ai.open() end, { desc = "Open AI harness" })
vim.keymap.set("n", "<leader>at", function() ai.toggle() end, { desc = "Toggle AI harness" })
vim.keymap.set("n", "<leader>af", ai.send_current_file, { desc = "Send current file" })
vim.keymap.set("v", "<leader>as", ":AIHarnessSendSelection<CR>", { desc = "Send selection" })
vim.keymap.set("n", "<leader>av", ai.send_visible_context, { desc = "Send visible lines" })
vim.keymap.set("n", "<leader>ad", ai.send_diagnostics, { desc = "Send diagnostics" })
vim.keymap.set("n", "<leader>ag", ai.send_git_diff, { desc = "Send git diff" })
vim.keymap.set("n", "<leader>aG", ai.send_git_diff_staged, { desc = "Send staged git diff" })Default configuration:
require("ai-harness").setup({
default_cmd = "pi",
window = {
type = "split", -- "split", "float", or "tab"
position = "right", -- "right", "left", "bottom", or "top"
size = 0.35,
full_height = true,
float = {
width = 0.8,
height = 0.8,
border = "rounded",
},
},
keymaps = {
terminal_goto_reference = "gf",
},
highlight = {
enabled = true,
max_lines = 500,
debounce_ms = 150,
},
})Window positions:
require("ai-harness").setup({
window = {
type = "split",
position = "left", -- "right", "left", "bottom", or "top"
size = 0.35,
},
})For floating windows:
require("ai-harness").setup({
window = {
type = "float",
float = {
width = 0.8,
height = 0.8,
border = "rounded",
},
},
})Reference highlighting is limited to recent terminal lines by default for predictable performance. gf and click detection still parse the current line directly.
To disable highlighting:
require("ai-harness").setup({
highlight = {
enabled = false,
},
})The plugin recognizes simple file references in AI output:
file
file:line
file:line:column
src/main.lua:42
/home/user/project/src/main.lua:42:3
Detection is intentionally simple and may highlight some false positives, such as URLs or version-like strings.
Clone the repository and run the tests:
git clone https://github.com/juantot9/ai-harness.nvim.git
cd ai-harness.nvim
make test