The most ergonomic way to integrate Claude AI into your Elixir applications.
- π Native Streaming: Built on Elixir Streams for real-time responses
- π¬ Automatic Conversation Continuity: Claude remembers context across queries
- π Production-Ready Supervision: Fault-tolerant GenServers with automatic restarts
- π οΈ Built-in File Operations: Read, edit, and analyze files with zero configuration
- β‘ High-Performance Concurrency: Multiple concurrent sessions with Elixir's actor model
- π§ Zero-Config Phoenix Integration: Drop-in support for LiveView and Phoenix apps
# Start a session and query Claude
{:ok, session} = ClaudeCode.start_link(api_key: "your-key")
# Real-time streaming responses
session
|> ClaudeCode.query_stream("Explain Elixir GenServers")
|> ClaudeCode.Stream.text_content()
|> Enum.each(&IO.write/1) # Watch Claude type in real-time! π¬
# Conversation continuity - Claude remembers context
ClaudeCode.query(session, "My favorite language is Elixir")
ClaudeCode.query(session, "What's my favorite language?")
# => "Your favorite language is Elixir!"
Step 1: Add to your mix.exs
def deps do
[{:claude_code, "~> 0.2.0"}]
end
Step 2: Install dependencies
mix deps.get
Step 3: Get the Claude CLI
# Install from claude.ai/code
claude --version # Verify installation
Step 4: Configure your API key
# config/config.exs
config :claude_code, api_key: System.get_env("ANTHROPIC_API_KEY")
π Ready to go! Try the quick demo above.
# Basic usage
{:ok, session} = ClaudeCode.start_link()
{:ok, response} = ClaudeCode.query(session, "Hello, Claude!")
# File operations
ClaudeCode.query(session, "Review my mix.exs file",
allowed_tools: ["View", "Edit"])
# Production with supervision
{:ok, _} = ClaudeCode.Supervisor.start_link(name: :assistant)
ClaudeCode.query(:assistant, "Help with this task")
π Complete Getting Started Guide β
- π¬ Conversation Continuity: Claude remembers context across queries automatically
- π Real-time Streaming: Watch responses appear in real-time with Elixir Streams
- π οΈ File Operations: Built-in tools for reading, editing, and analyzing files
- π Production Ready: Fault-tolerant supervision with automatic restarts
- β‘ High Performance: Concurrent sessions for parallel processing
- π§ Phoenix Integration: Drop-in compatibility with LiveView and Phoenix apps
# In your application.ex
def start(_type, _args) do
children = [
MyAppWeb.Endpoint,
{ClaudeCode.Supervisor, [
[name: :code_reviewer, api_key: api_key, system_prompt: "You review code"],
[name: :general_assistant, api_key: api_key]
]}
]
Supervisor.start_link(children, strategy: :one_for_one)
end
# Use from anywhere in your app
{:ok, review} = ClaudeCode.query(:code_reviewer, "Review this code")
Benefits:
- β Fault tolerance - Sessions restart automatically on crashes
- β Zero downtime - Hot code reloading preserves session state
- β Global access - Named sessions work from anywhere in your app
- β Distributed support - Sessions work across Elixir clusters
# Use in LiveViews and Controllers
def handle_event("ask_claude", %{"message" => message}, socket) do
case ClaudeCode.query(:assistant, message) do
{:ok, response} -> {:noreply, assign(socket, response: response)}
{:error, _} -> {:noreply, put_flash(socket, :error, "Claude unavailable")}
end
end
case ClaudeCode.query(session, "Hello") do
{:ok, response} -> IO.puts(response)
{:error, :timeout} -> IO.puts("Request timed out")
{:error, {:cli_not_found, msg}} -> IO.puts("CLI error: #{msg}")
{:error, {:claude_error, msg}} -> IO.puts("Claude error: #{msg}")
end
- π Getting Started - Step-by-step tutorial for new users
- π Production Guide - Fault-tolerant production deployments
- π» Examples - Real-world usage patterns and code samples
- π API Reference - Complete API documentation
- π§ Troubleshooting - Common issues and solutions
We β€οΈ contributions! Whether it's:
- π Bug reports - Found an issue? Let us know!
- π‘ Feature requests - Have an idea? We'd love to hear it!
- π Documentation - Help make our docs even better
- π§ Code contributions - PRs welcome!
See our Contributing Guide to get started.
# Clone and setup
git clone https://github.com/guess/claude_code.git
cd claude_code
mix deps.get
# Run tests and quality checks
mix test
mix quality # format, credo, dialyzer
MIT License - see LICENSE for details.
Built on top of the Claude Code CLI and designed for the Elixir community.
Made with β€οΈ for Elixir developers who want the best AI integration experience.