avante.nvim

repository·main·Indexed 12 days ago

https://github.com/yetone/avante.nvim

A Neovim plugin that brings Cursor-like AI capabilities to the editor, featuring AI-driven code suggestions, one-click applications, and a terminal-based agent experience called 'Zen Mode'. It supports multiple LLM providers including Claude, OpenAI, Azure, Gemini, Cohere, Copilot, and local options via Ollama. The plugin includes a RAG service with support for OpenAI, DashScope, and Ollama for embeddings, and allows project-specific AI behavior customization via an avante.md file.

Tokens
21.8K
Snippets
69
Records
80
Agent score
96%

What's inside avante.nvim

  1. Overview of avante.nvim

    main
    avante.nvim is a Neovim plugin designed to emulate the behavior of the Cursor AI IDE. It provides AI-driven code assistance, allowing users to interact with AI to ask questions about current code files and receive intelligent suggestions for improvements or modifications. A key feature is the ability to apply AI suggestions directly to source files with a single command.
  2. Use Project-Specific Custom Prompts (.avanterules)

    main

    You can define custom prompts for specific modes by placing *.{mode}.avanterules files in your project root. Avante will detect these based on the project root (LSP workspace, LSP root_dir, etc.).

    Supported Modes:

    • planning.avanterules (for planning mode)
    • editing.avanterules (for editing mode)
    • suggesting.avanterules (for suggesting mode)

    Template Engine: Files ending in .avanterules are Jinja templates rendered using minijinja.

    Loading Priority:

    1. rules.project_dir (configured in setup)
    2. rules.global_dir (configured in setup)
    3. Project root directory

    Configuration: You can define custom directories for these rules in the setup function.

    require('avante').setup({
      rules = {
        project_dir = '.avante/rules', -- Relative to project root or absolute
        global_dir = '~/.config/avante/rules', -- Absolute path
      },
    })
  3. Understand the dual_boost experimental feature

    main

    The dual_boost feature is an experimental mode that generates two separate responses from two different providers (first_provider and second_provider) and then uses a third prompt to combine them into a single response.

    Configuration keys:

    • enabled: Boolean to enable the feature.
    • first_provider: The first LLM to call.
    • second_provider: The second LLM to call.
    • prompt: The template used to merge outputs. It supports {{provider1_output}} and {{provider2_output}} placeholders.
    • timeout: Timeout in milliseconds.
    dual_boost = {
      enabled = false,
      first_provider = "openai",
      second_provider = "claude",
      prompt = "Based on the following two reference outputs, generate a response that combines elements of both but reflects your own judgment and unique perspective. Do not provide any explanation, just give the response directly. Reference output 1: [{{provider1_output}}], Reference output 2: [{{provider2_output}}]",
      timeout = 60000,
    }
  4. Use project-specific `.avanterules` files

    main

    Avante supports mode-specific custom rules using .avanterules files (which are Jinja templates). Avante looks for these files in the project root based on a hierarchy: LSP workspace folders > LSP root_dir > filename root pattern > CWD.

    To match a specific mode, name the file *.{mode}.avanterules (e.g., typescript.planning.avanterules for planning mode in TypeScript projects).

    You can configure where Avante looks for these rules using the rules option:

    • rules.project_dir: Relative to project root (e.g., .avante/rules).
    • rules.global_dir: Absolute path (e.g., ~/.config/avante/rules).

    Loading Priority:

    1. rules.project_dir
    2. rules.global_dir
    3. Project root
    require('avante').setup({
      rules = {
        project_dir = '.avante/rules',
        global_dir = '~/.config/avante/rules',
      },
    })
  5. Install avante.nvim using other package managers

    main

    You can install avante.nvim using several other Neovim plugin managers. Most require a build step (make or do = 'make') and specific dependencies.

    vim-plug

    Requires plenary.nvim and nui.nvim. To build from source, pass source=true to the plugin definition.

    mini.deps

    Use the hooks property to run vim.cmd('make') after checkout.

    Packer

    Use the run property to execute make.

    " vim-plug
    Plug 'yetone/avante.nvim', { 'branch': 'main', 'do': 'make' }
    
    " Packer
    use {
      'yetone/avante.nvim',
      branch = 'main',
      run = 'make',
      config = function() require('avante').setup() end
    }
  6. Integrate Avante with blink.cmp

    main

    If you use blink.cmp, you can integrate Avante's completion sources (Mentions, Slash Commands, Shortcuts, and Files) using blink.compat or the Kaiser-Yang/blink-cmp-avante plugin.

    Available Completion Sources:

    • Mentions (@): @codebase, @diagnostics, @file, @quickfix, @buffers.
    • Slash Commands (/): /help, /init, /clear, /new, /compact, /lines <start>-<end> <question>, /commit.
    • Shortcuts (#): Predefined prompt templates.
    • Files: File selection for context.
    -- Example blink.cmp configuration with Avante sources
          default = {
            ...,
            "avante_commands",
            "avante_mentions",
            "avante_shortcuts",
            "avante_files",
          }
    
          providers = {
            avante_commands = {
              name = "avante_commands",
              module = "blink.compat.source",
              score_offset = 90,
              opts = {},
            },
            avante_files = {
              name = "avante_files",
              module = "blink.compat.source",
              score_offset = 100,
              opts = {},
            },
            avante_mentions = {
              name = "avante_mentions",
              module = "blink.compat.source",
              score_offset = 1000,
              opts = {},
            },
            avante_shortcuts = {
              name = "avante_shortcuts",
              module = "blink.compat.source",
              score_offset = 1000,
              opts = {},
            }
            ...
          }
  7. Authenticate with Claude Pro/Max Subscription

    main

    To use your Claude subscription instead of an API key, set the auth_type of the claude provider to "max" in your configuration.

    After re-opening Neovim, the authentication process will start in your browser. Once authorized, copy the provided code into the Neovim prompt. If you need to re-initiate authentication, run :AvanteSwitchProvider claude.

    -- Providers = { ...
    
      claude = {
        -- ...
        auth_type = "max",
      },
  8. Enable Fast Apply with Morph

    main

    Fast Apply provides instant code edits with high accuracy (96-98%) by using specialized models. To use it, you must enable the feature in your configuration, obtain a Morph API key from morphllm.com, and set the MORPH_API_KEY environment variable.

    Morph Model Options:

    • morph-v3-fast: 4500+ tok/sec, 96% accuracy, 16k context.
    • morph-v3-large: 2500+ tok/sec, 98% accuracy, 16k context.
    • auto: 2500-4500 tok/sec, 98% accuracy, 16k context.
    behaviour = {
      enable_fastapply = true,  -- Enable Fast Apply feature
    },
    
    providers = {
      morph = {
        model = "morph-v3-large",
      },
    }
    export MORPH_API_KEY="your-api-key"
  9. Install avante.nvim using lazy.nvim

    main

    The recommended way to install avante.nvim is via lazy.nvim. Note that you must include the build step. If you want to build from source, you must set BUILD_FROM_SOURCE=true in your make command (though the provided snippet uses a conditional for Windows/Unix).

    Important Requirements:

    • Neovim 0.11.0 or later is required.
    • If building from source, cargo is required.
    • For Windows users, powershell is used for the build process.

    Recommended Neovim Option: To ensure the sidebar can be fully collapsed, set vim.opt.laststatus = 3 in your Neovim configuration.

    {
      "yetone/avante.nvim",
      build = vim.fn.has("win32") ~= 0
          and "powershell -ExecutionPolicy Bypass -File Build.ps1 -BuildFromSource false"
          or "make",
      event = "VeryLazy",
      version = false, -- Never set this value to "*"!
      opts = {
        provider = "claude",
        -- add other opts here
      },
      dependencies = {
        "nvim-lua/plenary.nvim",
        "MunifTanjim/nui.nvim",
        -- optional dependencies
        "nvim-telescope/telescope.nvim",
        "hrsh7th/nvim-cmp",
        "folke/snacks.nvim",
        -- ...
      },
    }
  10. Use Agent Client Protocol (ACP) providers

    main

    Avante supports the Agent Client Protocol (ACP), allowing integration with AI agents that use standardized JSON-RPC communication. ACP providers are configured in the acp_providers section. Supported agents include gemini-cli, claude-code, goose, codex, and kimi-cli.

    Prerequisites:

    • Gemini CLI: Install gemini and set GEMINI_API_KEY.
    • Claude Code: Install acp-claude-code via npm and set ANTHROPIC_API_KEY.
    acp_providers = {
      ["gemini-cli"] = {
        command = "gemini",
        args = { "--experimental-acp" },
        env = {
          NODE_NO_WARNINGS = "1",
          GEMINI_API_KEY = os.getenv("GEMINI_API_KEY"),
        },
      },
      ["claude-code"] = {
        command = "claude-agent-acp",
        args = { },
        env = {
          NODE_NO_WARNINGS = "1",
          ANTHROPIC_API_KEY = os.getenv("ANTHROPIC_API_KEY"),
        },
      },
      ["goose"] = {
        command = "goose",
        args = { "acp" },
      },
      ["codex"] = {
        command = "codex-acp",
        args = {},
        env = {
          NODE_NO_WARNINGS = "1",
          OPENAI_API_KEY = os.getenv("OPENAI_API_KEY"),
        },
      },
    }