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:
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:
Using Claude Pro Subscription
- In your CLI, run
claude setup-token. You'll be redirected to the Claude.ai website for authorization: - Back in your CLI, copy the OAuth token (in yellow):
- In your CodeCompanion config, extend the
claude_codeadapter and include the OAuth token (see the section on environment variables for other ways to do this):
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
- Create an API key in your Anthropic console.
- In your CodeCompanion config, extend the
claude_codeadapter and set theANTHROPIC_API_KEY:
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:
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,
},
},
})