If you live in Neovim and want an AI assistant that never sends your code to the cloud, the simplest robust route is CodeCompanion.nvim talking to Ollama on your own PC. You get a chat buffer that can see your code and LSP errors, plus inline edits you review as a diff before they land. This guide covers the setup from a working Neovim install to your first local edit.
What you need
Neovim 0.12 or later. CodeCompanion's installation page lists 0.12 as the minimum. Run nvim --version to check; Neovim 0.12.7 was the latest release on GitHub when we checked.
curl, which CodeCompanion uses to talk to Ollama.
A plugin manager. The examples here use lazy.nvim; CodeCompanion's docs also give examples for Neovim's built-in vim.pack and Packer.
Ollama, installed and running. Our guides cover installing Ollama on Linux and running models locally on Windows.
Enough VRAM for a capable model. Local models are limited by your hardware, and CodeCompanion's tools need a model that supports tool calling. See how much VRAM you need, or our guide to running an LLM on an 8GB card.
CodeCompanion's own local-models guide uses Qwen3 8B as its example:
ollama pull qwen3:8b
Then check it supports tool calling:
ollama show qwen3:8b
Look for tools under the model's capabilities. This matters more than it might seem: CodeCompanion's inline mode edits your buffer by calling a tool, and file tools such as @{files} only work with tool-calling models. Its docs list qwen3, qwen3-coder, gpt-oss, devstral and llama3.1 among models that report tools, but warn that smaller models often call the wrong tool or stop halfway, and suggest 20B parameters or more as a sensible starting point for its @{agent} mode. If you're torn between two coding models, our Devstral Small 2 vs Qwen3 Coder comparison may help.
Step 2: Install CodeCompanion
Add the plugin to your lazy.nvim spec, pinned to a release as the developer recommends to avoid breaking changes:
{
"olimorris/codecompanion.nvim",
version = "^19.0.0",
opts = {},
dependencies = {
"nvim-lua/plenary.nvim",
"nvim-treesitter/nvim-treesitter",
},
},
The docs warn that if you pin your plugins to releases, you should keep plenary.nvim on its master branch. Restart Neovim so lazy.nvim installs everything.
Step 3: Point it at Ollama
CodeCompanion's default adapter is GitHub Copilot, so you need to tell it to use Ollama. Set the adapter and model for both the chat buffer and inline edits. With lazy.nvim, this goes in opts (the contents of setup()):
opts = {
interactions = {
chat = {
adapter = { name = "ollama", model = "qwen3:8b" },
},
inline = {
adapter = { name = "ollama", model = "qwen3:8b" },
},
},
},
Always include the model. The docs explain that if you set only adapter = "ollama", CodeCompanion picks one of your installed models and which one isn't predictable, and that the table form without a model throws an error when you open a chat. The model name is the tag shown by ollama list.
By default the adapter connects to http://localhost:11434. If Ollama runs on another PC on your network, set the same OLLAMA_HOST environment variable the Ollama CLI reads, for example export OLLAMA_HOST="http://192.168.1.100:11434". Our guide to sharing Ollama on your local network covers the server side.
Run :checkhealth codecompanion to confirm the dependencies are in place.
Step 4: Chat about your code
Open a file and run :CodeCompanionChat. Type a message and send it with Ctrl + S in insert mode or Enter in normal mode. To share the file you opened the chat from, include #{buffer}:
What does the code in #{buffer} do?
Other editor context includes #{diagnostics} for LSP errors, #{selection} for a visual selection and #{terminal} for your latest terminal output; typing # lists everything available. Press ga in the chat buffer to switch to another model you've pulled. :CodeCompanionChat Toggle hides and restores the chat without losing its history.
To let the model edit files, add @{files} to a message. Some tools, such as reading a file, ask for your approval before they run, and edits are shown as a diff before they're written; accept a change with g2 or reject it with g3.
Step 5: Edit code in place
For smaller changes you don't need the chat. Select some lines in visual mode and run:
:'<,'>CodeCompanion Use early returns
The model edits only the selected lines (it can still see the rest of the buffer for context) and shows the change as a diff. Move between hunks with } and {, accept or reject the hunk under the cursor with ga or gr, or accept or reject all the rest with g2 or g3. Press q to stop a request that's taking too long.
The built-in prompt library saves typing: :'<,'>CodeCompanion /explain explains a selection, /fix fixes it, /lsp explains its LSP diagnostics, and :CodeCompanion /commit writes a commit message for your staged changes. :CodeCompanionActions lists them all. CodeCompanion sets no global keymaps, so map the commands you use most yourself.
Step 6: Tune it for your hardware
CodeCompanion lets you set three Ollama options on the adapter that make a real difference on a home PC:
opts = {
adapters = {
http = {
ollama = function()
return require("codecompanion.adapters").extend("ollama", {
schema = {
num_ctx = { default = 32768 },
think = { default = false },
keep_alive = { default = "30m" },
},
})
end,
},
},
},
num_ctx sets the context window Ollama loads the model with. Ollama's own default is 4,096 tokens, which fills up quickly once you share a whole file, but a larger window uses more memory. See Ollama context length explained.
think turns reasoning on or off for models that support it. Turning it off skips the model's reasoning step; see how to turn off thinking in Ollama.
keep_alive controls how long the model stays in memory after a request. Ollama's default is 5 minutes, after which the next request has to load the model again. Our guide to keeping Ollama models loaded explains the trade-off.
If you lower num_ctx below the model's maximum, CodeCompanion's docs recommend setting its context-management triggers as token counts rather than percentages, because it calculates the percentages from the model's maximum context window, not your setting.
Troubleshooting
The chat errors or hangs when it opens. CodeCompanion asks Ollama for its models when a chat opens and waits up to 3 seconds before giving up. Make sure Ollama is running (ollama list should respond).
Inline edits or @{files} do nothing. The model probably doesn't report tool support, so CodeCompanion doesn't send the tools. Check with ollama show and pick a tool-calling model.
Errors about system messages once tools are added. Some model templates need a single system message; the local-models guide includes a handler that merges them.
It's slow. Confirm Ollama is using your GPU and reduce num_ctx if the model is spilling out of VRAM.
Want to compare other options? See our best Neovim AI plugins for local LLMs and CodeCompanion vs avante.nvim. If you also use VS Code, our Ollama in VS Code guide covers the equivalent setup there.