.codecompanion/acp/acp.md
ACP (Agent Client Protocol) is a JSON-RPC based protocol that enables sophisticated communication between CodeCompanion.nvim and AI agents like Claude Code and Gemini CLI. Unlike traditional HTTP-based API calls, ACP provides session-based interactions with streaming responses, tool execution, and interactive permission handling.
Warning! The schema file is huge:
@.codecompanion/acp/acp_json_schema.json
ACP is a protocol specification that defines how clients (like CodeCompanion.nvim) communicate with AI agents through a standardized message format. Key features include:
@./lua/codecompanion/acp/init.lua
The main ACP connection manager that handles:
@./lua/codecompanion/adapters/acp/claude_code.lua @./lua/codecompanion/adapters/acp/helpers.lua
Adapter implementations for specific ACP agents:
claude_code.lua - Claude Code agent integrationgemini_cli.lua - Gemini CLI agent integrationhelpers.lua - Shared utilities for ACP adapters@./lua/codecompanion/acp/prompt_builder.lua
A fluent API for constructing and sending prompts with streaming response handling:
local prompt = PromptBuilder.new(connection, messages)
:on_message_chunk(function(chunk) ... end)
:on_thought_chunk(function(thought) ... end)
:on_tool_call(function(tool) ... end)
:with_options({ bufnr = bufnr })
:send()
@./lua/codecompanion/interactions/chat/acp/handler.lua @./lua/codecompanion/interactions/chat/acp/request_permission.lua @./lua/codecompanion/interactions/chat/acp/formatters.lua
Chat-specific ACP integration:
handler.lua - Main chat buffer ACP handlerrequest_permission.lua - Interactive permission request UIformatters.lua - Formats the ACP output and returns it to the handler to work withClient → Agent: initialize request
Agent → Client: capabilities and auth methods
Client → Agent: authenticate request
Agent → Client: success/failure response
Client → Agent: session/new request
Agent → Client: session ID
Client → Agent: session/prompt request
Agent → Client: streaming session/update notifications
Agent → Client: session/request_permission
Client → Agent: permission response
Agent → Client: tool execution results
agent_message_chunk - Streamed response contentagent_thought_chunk - Agent reasoning/planningtool_call - Tool execution requesttool_call_update - Tool execution progress/completionplan - High-level execution planWhen agents need to execute potentially sensitive operations, they request permission. This can come in two forms:
{
"method": "session/request_permission",
"params": {
"sessionId": "abc123",
"options": [
{"optionId": "allow_once", "name": "Allow", "kind": "allow_once"},
{"optionId": "reject", "name": "Reject", "kind": "reject_once"}
],
"toolCall": {
"title": "Writing to config.lua",
"kind": "edit",
"content": [{"type": "diff", "path": "config.lua", ...}]
}
}
}
Note that the two calls below are linked by the
toolCallId:
{
"jsonrpc": "2.0",
"method": "session/update",
"params": {
"sessionId": "01992f51-373e-772d-9632-bb7d38a8d47b",
"update": {
"toolCallId": "toolu_01FzKhxc4Mo5abCyAipUdLo3",
"sessionUpdate": "tool_call",
"status": "pending",
"title": "Edit `/Some/Path/Neovim/codecompanion.nvim/test.txt`",
"kind": "edit",
"content": [
{
"type": "diff",
"path": "/Some/Path/Code/Neovim/codecompanion.nvim/test.txt",
"oldText": "Hello World",
"newText": "Hello World\nHave a wonderful day! 🌟"
}
],
"locations": [
{
"path": "/Some/Path/Code/Neovim/codecompanion.nvim/test.txt"
}
]
}
}
}
{
"jsonrpc": "2.0",
"id": 0,
"method": "session/request_permission",
"params": {
"options": [
{
"kind": "allow_always",
"name": "Always Allow",
"optionId": "allow_always"
},
{
"kind": "allow_once",
"name": "Allow",
"optionId": "allow"
},
{
"kind": "reject_once",
"name": "Reject",
"optionId": "reject"
}
],
"sessionId": "01992f51-373e-772d-9632-bb7d38a8d47b",
"toolCall": {
"toolCallId": "toolu_01FzKhxc4Mo5abCyAipUdLo3"
}
}
}
ACP is seamlessly integrated into CodeCompanion's chat buffer experience:
ACP adapters are configured in the main config:
adapters = {
claude_code = {
name = "claude_code",
type = "acp",
commands = {
default = {"npx", "--yes", "@zed-industries/claude-code-acp"}
},
env = {
CLAUDE_CODE_OAUTH_TOKEN = "your_token_here"
}
}
}
Official Claude Code agent with:
Google's Gemini CLI agent with:
Fully support OpenAI's Codex.
ACP agents can interact with the file system through standardized methods:
fs/read_text_file - Read file contentsfs/write_text_file - Write file contentsAll file operations require user permission and show diffs when applicable. The file containing this logic is:
@./lua/codecompanion/interactions/chat/acp/fs.lua
Robust error handling throughout the ACP stack: