plugins.codecompanion.settings

Options provided to the require('codecompanion').setup function.

Type: attribute set of anything

Default: { }

Example:

{
  adapters = {
    ollama = {
      __raw = ''
        function()
          return require('codecompanion.adapters').extend('ollama', {
              env = {
                  url = "http://127.0.0.1:11434",
              },
              schema = {
                  model = {
                      default = 'qwen2.5-coder:latest',
                      -- default = "llama3.1:8b-instruct-q8_0",
                  },
                  num_ctx = {
                      default = 32768,
                  },
              },
          })
        end
      '';
    };
  };
  opts = {
    log_level = "TRACE";
    send_code = true;
    use_default_actions = true;
    use_default_prompts = true;
  };
  strategies = {
    agent = {
      adapter = "ollama";
    };
    chat = {
      adapter = "ollama";
    };
    inline = {
      adapter = "ollama";
    };
  };
}

Declared by:

plugins.codecompanion.settings.adapters

In CodeCompanion, adapters are interfaces that act as a bridge between the plugin’s functionality and an LLM.

Refer to the documentation to learn about the adapters spec.

Type: null or (attribute set of (anything or raw lua code))

Default: null

Plugin default:

{
  anthropic = "anthropic";
  azure_openai = "azure_openai";
  copilot = "copilot";
  gemini = "gemini";
  non_llms = {
    jina = "jina";
  };
  ollama = "ollama";
  openai = "openai";
  opts = {
    allow_insecure = false;
    proxy = null;
  };
  xai = "xai";
}

Example:

{
  ollama = {
    __raw = ''
      function()
        return require("codecompanion.adapters").extend("ollama", {
          schema = {
            model = {
              default = "llama3:latest"
            }
          }
        })
      end
    '';
  };
  openai = {
    __raw = ''
      function()
        return require("codecompanion.adapters").extend("openai", {
          schema = {
            model = {
              default = "gpt-4o"
            }
          }
        })
      end
    '';
  };
}

Declared by:

plugins.codecompanion.settings.display

Appearance settings.

Type: null or (attribute set of anything)

Default: null

Plugin default: See upstream documentation

Example:

{
  display = {
    action_palette = {
      opts = {
        show_default_prompt_library = true;
      };
      provider = "default";
    };
    chat = {
      window = {
        layout = "vertical";
        opts = {
          breakindent = true;
        };
      };
    };
  };
}

Declared by:

plugins.codecompanion.settings.opts

General settings for the plugin.

Type: null or (attribute set of anything)

Default: null

Plugin default: See upstream documentation

Example:

{
  log_level = "TRACE";
  send_code = true;
  use_default_actions = true;
  use_default_prompts = true;
}

Declared by:

plugins.codecompanion.settings.prompt_library

The plugin comes with a number of pre-built prompts.

As per the config, these can be called via keymaps or via the cmdline. These prompts have been carefully curated to mimic those in GitHub’s Copilot Chat.

Of course, you can create your own prompts and add them to the Action Palette or even to the slash command completion menu in the chat buffer. Please see the RECIPES guide for more information.

Type: null or (attribute set of ((attribute set of anything) or raw lua code))

Default: null

Plugin default: See upstream documentation

Example:

{
  "Custom Prompt" = {
    description = "Prompt the LLM from Neovim";
    opts = {
      index = 3;
      is_default = true;
      is_slash_cmd = false;
      user_prompt = true;
    };
    prompts = [
      {
        content = {
          __raw = ''
            function(context)
              return fmt(
                [[I want you to act as a senior %s developer. I will ask you specific questions and I want you to return raw code only (no codeblocks and no explanations). If you can't respond with code, respond with nothing]],
                context.filetype
              )
            end
          '';
        };
        opts = {
          tag = "system_tag";
          visible = false;
        };
        role = {
          __raw = "system";
        };
      }
    ];
    strategy = "inline";
  };
  "Generate a Commit Message" = {
    description = "Generate a commit message";
    opts = {
      auto_submit = true;
      index = 10;
      is_default = true;
      is_slash_cmd = true;
      short_name = "commit";
    };
    prompts = [
      {
        content = {
          __raw = ''
            function()
              return fmt(
                [[You are an expert at following the Conventional Commit specification. Given the git diff listed below, please generate a commit message for me:
            
                ```diff
                %s
                ```
                ]],
                vim.fn.system("git diff --no-ext-diff --staged")
              )
            end
          '';
        };
        opts = {
          contains_code = true;
        };
        role = "user";
      }
    ];
    strategy = "chat";
  };
}

Declared by:

plugins.codecompanion.settings.strategies

The plugin utilises objects called Strategies. These are the different ways that a user can interact with the plugin.

  • The chat strategy harnesses a buffer to allow direct conversation with the LLM.
  • The inline strategy allows for output from the LLM to be written directly into a pre-existing Neovim buffer.
  • The agent and workflow strategies are wrappers for the chat strategy, allowing for tool use and agentic workflows.

Type: null or (attribute set of (anything or raw lua code))

Default: null

Plugin default: See upstream documentation

Example:

{
  agent = {
    adapter = "ollama";
  };
  chat = {
    adapter = "ollama";
  };
  inline = {
    adapter = "ollama";
  };
}

Declared by: