|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## Development Commands |
| 6 | + |
| 7 | +### Testing |
| 8 | +```bash |
| 9 | +# Run all tests |
| 10 | +bundle exec rake spec |
| 11 | + |
| 12 | +# Run tests with coverage |
| 13 | +bundle exec rake coverage |
| 14 | + |
| 15 | +# Run integration tests (requires Claude Code CLI) |
| 16 | +bundle exec rake integration |
| 17 | + |
| 18 | +# Default task (runs spec + rubocop) |
| 19 | +bundle exec rake |
| 20 | +``` |
| 21 | + |
| 22 | +### Code Quality |
| 23 | +```bash |
| 24 | +# Run linter |
| 25 | +bundle exec rubocop |
| 26 | + |
| 27 | +# Generate documentation |
| 28 | +bundle exec yard |
| 29 | +``` |
| 30 | + |
| 31 | +### Development |
| 32 | +```bash |
| 33 | +# Install dependencies |
| 34 | +bundle install |
| 35 | + |
| 36 | +# Open console with gem loaded |
| 37 | +bundle exec rake console |
| 38 | + |
| 39 | +# Build and install gem locally |
| 40 | +bundle exec rake install |
| 41 | + |
| 42 | +# Release gem (updates version, creates tag, pushes to rubygems) |
| 43 | +bundle exec rake release |
| 44 | +``` |
| 45 | + |
| 46 | +## Architecture Overview |
| 47 | + |
| 48 | +This 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: |
| 49 | + |
| 50 | +### Core Structure |
| 51 | +- **Main Entry Point**: `ClaudeCodeSDK` module provides `query()` and `ask()` methods |
| 52 | +- **Transport Layer**: Abstracts communication with Claude Code CLI via subprocess |
| 53 | +- **Message System**: Strongly typed message objects for different interaction types |
| 54 | +- **Configuration**: Global and per-query configuration options |
| 55 | + |
| 56 | +### Key Components |
| 57 | + |
| 58 | +**Transport Layer** (`lib/claude_code_sdk/transport/`): |
| 59 | +- `Base`: Abstract transport interface |
| 60 | +- `SimpleCLI`: Current implementation using direct CLI execution |
| 61 | +- `SubprocessCLI`: Alternative implementation (currently disabled due to subprocess issues) |
| 62 | + |
| 63 | +**Message Types** (`lib/claude_code_sdk/messages.rb`): |
| 64 | +- `UserMessage`: User input |
| 65 | +- `AssistantMessage`: Claude's responses with content blocks (text, tool use, tool results) |
| 66 | +- `SystemMessage`: System notifications |
| 67 | +- `ResultMessage`: Session results with cost/usage data |
| 68 | + |
| 69 | +**Configuration** (`lib/claude_code_sdk/configuration.rb`): |
| 70 | +- Singleton pattern for global defaults |
| 71 | +- Options object for per-query configuration |
| 72 | +- Supports all Claude Code CLI parameters (tools, permissions, prompts, etc.) |
| 73 | + |
| 74 | +### Transport Implementation Details |
| 75 | +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. |
| 76 | + |
| 77 | +### Prerequisites |
| 78 | +- Ruby >= 3.0.0 |
| 79 | +- Claude Code CLI must be installed: `npm install -g @anthropic-ai/claude-code` |
| 80 | +- Zeitwerk for autoloading |
| 81 | + |
| 82 | +### Testing Strategy |
| 83 | +- Unit tests for message parsing and configuration |
| 84 | +- Integration tests that require actual Claude Code CLI |
| 85 | +- Coverage reporting via SimpleCov |
| 86 | +- RuboCop for code style enforcement |
0 commit comments