Skip to content

Configuring Agent Client Protocol (ACP)

This section contains configuration which is specific to ACP adapters only. There is a lot of shared functionality between ACP and http adapters. Therefore it's recommended you read the two pages together.

Changing Auth Method

NOTE

The auth methods for each ACP adapter are output in the logs when the log_level is set to DEBUG.

It's important to note that each agent adapter handles authentication differently. CodeCompanion endeavours to share the available options in the agent's adapter as a comment. However, it's recommended to consult the documentation of the agent you're working with.

An example of changing the Gemini CLI's auth method to use the API key and a 1Password vault:

lua
require("codecompanion").setup({
  adapters = {
    acp = {
      gemini_cli = function()
        return require("codecompanion.adapters").extend("gemini_cli", {
          defaults = {
            auth_method = "gemini-api-key", -- "oauth-personal"|"gemini-api-key"|"vertex-ai"
          },
          env = {
            GEMINI_API_KEY = "cmd:op read op://personal/Gemini_API/credential --no-newline",
          },
        })
      end,
    },
  },
})

Setup: Claude Code

To use Claude Code within CodeCompanion, you'll need to take the following steps:

  1. Install Claude Code
  2. Install the Zed ACP adapter for Claude Code

Using Claude Pro Subscription

  1. In your CLI, run claude setup-token. You'll be redirected to the Claude.ai website for authorization:
  2. Back in your CLI, copy the OAuth token (in yellow):
  3. In your CodeCompanion config, extend the claude_code adapter and include the OAuth token (see the section on environment variables for other ways to do this):
lua
require("codecompanion").setup({
  adapters = {
    acp = {
      claude_code = function()
        return require("codecompanion.adapters").extend("claude_code", {
          env = {
            CLAUDE_CODE_OAUTH_TOKEN = "my-oauth-token",
          },
        })
      end,
    },
  },
})

Using an API Key

  1. Create an API key in your Anthropic console.
  2. In your CodeCompanion config, extend the claude_code adapter and set the ANTHROPIC_API_KEY:
lua
require("codecompanion").setup({
  adapters = {
    acp = {
      claude_code = function()
        return require("codecompanion.adapters").extend("claude_code", {
          env = {
            ANTHROPIC_API_KEY = "my-api-key",
          },
        })
      end,
    },
  },
})

Setup: Codex

To use OpenAI's Codex, install an ACP-compatible adapter like this one from Zed.

By default, the adapter will look for an OPENAI_API_KEY in your shell, however you can also authenticate via ChatGPT. This can be customized in the plugin configuration:

lua
require("codecompanion").setup({
  adapters = {
    acp = {
      codex = function()
        return require("codecompanion.adapters").extend("codex", {
          defaults = {
            auth_method = "openai-api-key", -- "openai-api-key"|"codex-api-key"|"chatgpt"
          },
          env = {
            OPENAI_API_KEY = "my-api-key",
          },
        })
      end,
    },
  },
})

Released under the MIT License.