This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
# Run all tests
bundle exec rake spec
# Run tests with coverage
bundle exec rake coverage
# Run integration tests (requires Claude Code CLI)
bundle exec rake integration
# Default task (runs spec + rubocop)
bundle exec rake# Run linter
bundle exec rubocop
# Generate documentation
bundle exec yard# Install dependencies
bundle install
# Open console with gem loaded
bundle exec rake console
# Build and install gem locally
bundle exec rake install
# Release gem (updates version, creates tag, pushes to rubygems)
bundle exec rake releaseThis is a Ruby SDK for Claude Code CLI that provides a Ruby interface to Anthropic's AI coding assistant. The architecture follows these key patterns:
- Main Entry Point:
ClaudeCodeSDKmodule providesquery()andask()methods - Transport Layer: Abstracts communication with Claude Code CLI via subprocess
- Message System: Strongly typed message objects for different interaction types
- Configuration: Global and per-query configuration options
Transport Layer (lib/claude_code_sdk/transport/):
Base: Abstract transport interfaceSimpleCLI: Current implementation using direct CLI executionSubprocessCLI: Alternative implementation (currently disabled due to subprocess issues)
Message Types (lib/claude_code_sdk/messages.rb):
UserMessage: User inputAssistantMessage: Claude's responses with content blocks (text, tool use, tool results)SystemMessage: System notificationsResultMessage: Session results with cost/usage data
Configuration (lib/claude_code_sdk/configuration.rb):
- Singleton pattern for global defaults
- Options object for per-query configuration
- Supports all Claude Code CLI parameters (tools, permissions, prompts, etc.)
The SDK currently uses SimpleCLI transport which spawns the Claude Code CLI process for each query. The CLI communication happens via JSON message streaming, with the SDK parsing and converting CLI output into strongly-typed Ruby message objects.
- Ruby >= 3.0.0
- Claude Code CLI must be installed:
npm install -g @anthropic-ai/claude-code - Zeitwerk for autoloading
- Unit tests for message parsing and configuration
- Integration tests that require actual Claude Code CLI
- Coverage reporting via SimpleCov
- RuboCop for code style enforcement