A dedicated Google Cloud Vertex AI adapter extension for Anthropic models in codecompanion.nvim.
This adapter safely bridges CodeCompanion's native Anthropic capabilities (such as Prompt Caching and Extended Thinking) to Vertex AI's strict API requirements.
- Native Vertex Routing: Dynamically routes requests based on your
CLOUD_ML_REGION. - Prompt Caching Support: Supports Anthropic prompt caching mechanisms perfectly on Google Cloud to save tokens on large contexts.
- Extended Thinking Safety: Properly handles Anthropic's strict
temperature = 1requirement when reasoning mode is enabled. - Cost Protection: Defaults
extended_thinkingtofalseglobally to prevent runaway API costs, allowing you to explicitly opt-in per interaction.
- Neovim >= 0.9.0
olimorris/codecompanion.nvimgcloudCLI installed and authenticated viagcloud auth application-default login
You must export these variables in your shell profile (e.g., ~/.bashrc or ~/.zshrc):
export ANTHROPIC_VERTEX_PROJECT_ID="your-project-id"
export CLOUD_ML_REGION="us-east5"
Install the plugin using your preferred package manager and pass the adapter into your CodeCompanion setup.
Using lazy.nvim:
{
"olimorris/codecompanion.nvim",
dependencies = {
"nvim-lua/plenary.nvim",
"nvim-treesitter/nvim-treesitter",
{
"YourUsername/codecompanion-anthropic-vertex.nvim",
}
},
opts = {
extensions = {
anthropic_vertex = {
enabled = true,
}
},
adapters = {
anthropic_vertex = function()
return require("codecompanion._extensions.anthropic_vertex").adapter()
end,
},
interactions = {
chat = {
adapter = "anthropic_vertex",
},
inline = {
adapter = "anthropic_vertex",
},
cmd = {
adapter = "anthropic_vertex",
},
},
},
}
Models like Claude 3.7 Sonnet support "Extended Thinking" (reasoning tokens). Because reasoning tokens can quickly become expensive (up to 16,000 hidden tokens per request), this adapter disables Extended Thinking by default.
If you want to enable it, the safest approach is to turn it on specifically for the chat interaction, while leaving it off for quick inline or cmd generations.
You can do this by converting the adapter string into a table and overriding the schema in your interactions block:
interactions = {
chat = {
adapter = {
name = "anthropic_vertex",
schema = {
extended_thinking = {
default = true, -- Enable reasoning tokens for chat sessions
},
},
},
},
inline = {
adapter = "anthropic_vertex", -- Remains false (default) to save money
},
},
- Built with AI: The entire logic, debugging, and structure of this plugin was designed and generated entirely by an AI assistant.
- CodeCompanion: A massive thank you to olimorris for creating
codecompanion.nvim. This adapter relies entirely on his brilliant foundational architecture.
Apache License 2.0. See LICENSE for details.