Skip to content

ACP Protocol Reference

CodeCompanion implements the Agent Client Protocol (ACP) to enable you to work with coding agents from within Neovim. ACP is an open standard that enables structured interaction between clients (like CodeCompanion) and AI agents, providing capabilities such as session management, file system operations, tool execution, and permission handling.

This page provides a technical reference for what's supported in CodeCompanion and how it's been implemented.

Protocol Support

CodeCompanion provides comprehensive support for the ACP specification:

Feature CategorySupport LevelDetails
Core Protocol✅ FullJSON-RPC 2.0, streaming responses, message buffering
Session Management✅ FullCreate, load, and persist sessions with state tracking
Authentication✅ FullMultiple auth methods, adapter-level hooks
File System✅ FullRead/write text files with line ranges
Permissions✅ FullInteractive UI with diff preview for tool approval
Content Types✅ FullText, images, embedded resources
Tool Calls✅ FullContent blocks, file diffs, status updates
Session Modes✅ FullMode switching and state management
MCP Integration✅ FullStdio, HTTP, and SSE transports
Agent PlansVisual display of an agent's execution plan
Terminal OperationsTerminal capabilities not implemented

Supported Adapters

AdapterDescriptionSpecial Features
Claude CodeAnthropic's Claude Code CLIOAuth authentication, tool output trimming
Gemini CLIGoogle's Gemini CLIMultiple auth methods (OAuth, API key, Vertex AI), YOLO mode
Auggie CLIAugment Code CLIStandard ACP support
CodexOpenAI CodexFull ACP implementation

Client Capabilities

CodeCompanion advertises the following capabilities to ACP agents:

lua
{
  fs = {
    readTextFile = true,   -- Read files with optional line ranges
    writeTextFile = true   -- Write/create files
  },
  terminal = false         -- Terminal operations not supported
}

Content Support

Content TypeSend to AgentReceive from Agent
Text
Images
Embedded Resources
Audio
File DiffsN/A

Session Updates Handled

CodeCompanion processes the following session update types:

  • Message chunks: Streamed text from agent responses
  • Thought chunks: Agent reasoning displayed separately
  • Tool calls: Full execution lifecycle with status tracking
  • Mode changes: Automatic UI updates when modes switch
  • Available commands: Dynamic command registration for completion

Implementation Notes

Message Buffering

JSON-RPC message boundaries don't always align with I/O boundaries. CodeCompanion buffers stdout from the agent process and extracts complete JSON-RPC messages line-by-line, ensuring robust parsing even with partial reads.

State Management

Unlike HTTP adapters which are stateless (sending the full conversation history with each request), ACP adapters are stateful. The agent maintains the conversation context, so CodeCompanion only sends new messages with each prompt. Session IDs are tracked throughout the conversation lifecycle.

Tool Call Caching

Tool call state is maintained in memory to support permission requests. When an agent requests permission for a tool call, the cached details enable features like the diff preview UI for file edits.

File Context Handling

When sending files as embedded resources to agents, CodeCompanion re-reads the file content rather than using the chat buffer representation. This avoids HTTP-style <attachment> tags that are used for LLM adapters but don't make sense for ACP agents.

Slash Commands

ACP agents can advertise their own slash commands dynamically. You can access them with \command in the chat buffer. CodeCompanion transforms this to /command before sending your prompt to the agent.

Graceful Degradation

CodeCompanion checks an agent's capabilities during initialization and gracefully falls back to supported content types. For example, if an agent doesn't support embedded context, files are sent as plain text instead.

Cleanup and Lifecycle

CodeCompanion ensures clean disconnection from ACP agents by hooking into Neovim's VimLeavePre autocmd. This guarantees that agent processes are properly terminated even if Neovim exits unexpectedly.

Key Features

  • Streaming: Real-time response streaming with chunk-by-chunk rendering
  • Permission System: Interactive approval for file operations with diff preview
  • Session Persistence: Resume previous conversations across Neovim sessions
  • Mode Management: Switch between agent modes (e.g. ask, architect, code)
  • MCP Servers: Connect agents to external tools via the Model Context Protocol
  • Slash Command Completion: Auto-complete agent-specific commands with \command syntax
  • Error Handling: Comprehensive error messages and graceful degradation

Protocol Version

CodeCompanion currently implements ACP Protocol Version 1.

The protocol version is negotiated during initialization. If an agent selects a different version, CodeCompanion will log a warning but continue to operate, following the agent's selected version.

Known Limitations

  • Terminal Operations: The terminal/* family of methods (terminal/create, terminal/output, terminal/release, etc.) are not implemented. CodeCompanion doesn't advertise terminal capabilities to agents.

  • Agent Plan Rendering: Plan updates from agents are received and logged, but they're not currently rendered in the chat buffer UI.

  • Cancellation: The session/cancel notification isn't currently sent by the client, though CodeCompanion properly handles cancelled states when agents report them.

  • Model Selection: The session/set_model method isn't implemented, as this feature is currently marked as unstable in the ACP specification.

  • Audio Content: Audio content blocks aren't sent in prompts, despite capability detection.

See Also

Released under the MIT License.