ACP ā Agent Client Protocol for Crystal
An unofficial Crystal implementation of the Agent Client Protocol (ACP), which defines a JSON-RPC 2.0 based communication standard between code editors (clients) and AI coding agents.
š Full documentation is available at acp.cr.hahwul.com
Installation
Add the dependency to your shard.yml:
dependencies:
acp:
github: hahwul/acp
Then run:
shards install
Quick Start
require "acp"
# 1. Connect to an agent process via stdio
transport = ACP::ProcessTransport.new("my-agent", ["--stdio"])
client = ACP::Client.new(transport, client_name: "my-editor")
# 2. Initialize the connection (handshake)
init_result = client.initialize_connection
# 3. Create a new session
session = ACP::Session.create(client, cwd: Dir.current)
# 4. Handle streaming updates
client.on_update = ->(update : ACP::Protocol::SessionUpdateParams) do
case u = update.update
when ACP::Protocol::AgentMessageChunkUpdate
print u.text # Stream agent text to the terminal
when ACP::Protocol::ToolCallUpdate
puts "\nš§ #{u.title} [#{u.status}]"
when ACP::Protocol::AgentThoughtChunkUpdate
puts "š #{u.text}"
end
nil
end
# 5. Send a prompt and wait for the result
result = session.prompt("Explain this codebase in one paragraph.")
puts "\n[Done ā stop reason: #{result.stop_reason}]"
# 6. Clean up
client.close
Examples
Several examples are provided in the examples/ directory:
simple_client.crā Basic connection and promptingcontent_blocks.crā Rich prompts with multiple content typesclaude_code_agent.crā Claude Code as an ACP agentgemini_agent.crā Gemini CLI as an ACP agentcodex_agent.crā Codex via ACP adapterinteractive_client.crā Full-featured interactive CLI client
crystal run examples/claude_code_agent.cr
crystal run examples/gemini_agent.cr
crystal run examples/interactive_client.cr -- my-agent --stdio
Development
crystal spec
crystal tool format
Contributing
- Fork it (https://github.com/hahwul/acp/fork)
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Add some feature') - Push to the branch (
git push origin my-new-feature) - Create a new Pull Request
Contributors
- hahwul - creator and maintainer
License
This project is licensed under the MIT License - see the LICENSE file for details.