Thank you for your interest in contributing! This guide will help you understand the project architecture and how to contribute effectively.
This project is a Go SDK library that provides programmatic access to the Claude Code CLI. It enables Go developers to integrate Claude Code into their applications via a clean, well-tested API.
Import Path: github.com/lancekrogers/claude-code-go/pkg/claude
For official Claude Code documentation and SDK patterns, see the Claude Code SDK Documentation.
What this project IS:
- Go SDK library (
pkg/claude/) - Subprocess wrapper around official Claude Code CLI
- JSON/streaming response parser
- Convenience methods for common operations
- MCP tool integration
What this project IS NOT:
- CLI distribution or replacement
- Standalone application for end users
- Alternative to the official
claudecommand
We do not provide CLI interfaces. Users should use the official claude command directly.
Rationale:
- Avoids user confusion
- Reduces maintenance burden
- Prevents circular dependencies
- Maintains clear project scope
The SDK executes claude CLI as subprocess and parses responses.
Implementation:
- Uses
exec.CommandContext()with proper context handling - Builds command arguments programmatically
- Parses JSON/text/streaming responses
- Comprehensive error handling
- Go 1.21+ (latest version recommended)
- Claude Code CLI installed
- just command runner (
brew install just)
# Clone the repository
git clone https://github.com/lancekrogers/claude-code-go
cd claude-code-go
# Install dependencies
go mod download
# Run tests
just test all
# Build examples
just build examples
# Run integration tests
just test integration# List all available commands
just
# Core development
just build all # Build library and examples
just test all # Run all tests
just coverage report # Generate coverage report
# Examples and demos
just demo # List demo commands
just demo streaming # Run streaming demo
just build examples # Build all examples
# Testing variants
just test unit # Core library tests only
just test dangerous # Test dangerous package
just test integration # Integration tests with mock server- Follow Go Code Review Comments
- Use
gofmtfor formatting - Run
go vetbefore submitting - Write comprehensive tests
-
All blocking operations must accept
context.Context -
Provide both context-aware and convenience methods:
// Context-aware (preferred) func (c *Client) RunPromptCtx(ctx context.Context, prompt string, opts *RunOptions) (*Result, error) // Convenience wrapper func (c *Client) RunPrompt(prompt string, opts *RunOptions) (*Result, error) { return c.RunPromptCtx(context.Background(), prompt, opts) }
-
Use proper error wrapping with
fmt.Errorf("operation failed: %w", err)
- Minimum 80% test coverage for new code
- Unit tests for all public methods
- Integration tests for end-to-end workflows
- Mock subprocess execution in unit tests
- Use table-driven tests where appropriate
- Minimize external dependencies
- Only add dependencies that enhance core SDK functionality
- No CLI frameworks or command-line parsing libraries
- Prefer standard library when possible
- Test core SDK functionality
- Mock command execution using dependency injection
- Validate argument building and response parsing
- Test error conditions and edge cases
- Test full end-to-end workflows
- Use mock Claude server for reliable testing
- Validate MCP integration
- Test streaming functionality
- Ensure all examples compile and run
- Validate usage patterns
- Test documentation examples
# All tests (recommended)
just test all
# Specific test suites
just test unit # Core library only
just test dangerous # Dangerous package only
just test integration # Integration tests with mock
# With coverage
just coverage report
open coverage/coverage.htmlWe provide a mock Claude server for integration testing:
- HTTP server simulating Claude Code responses
- Enables testing without Claude CLI dependency
- Located in
test/mockserver/
Interactive demos showcase the SDK features. The GIFs are recordings of real Go demos running with actual Claude Code CLI interactions.
brew install expect asciinema just
cargo install --git https://github.com/asciinema/agg# Generate single demo GIF
just demo gif basic
# Generate all demo GIFs
just demo gif-all
# List available demos
just demo gif-listNote: Recording demos makes real API calls via Claude Code CLI. Keep demos short to control costs.
- Create interactive demo:
examples/demo/<name>/cmd/demo/main.go - Create expect script:
scripts/demo-expect/<name>.exp - Add build targets to
.justfiles/demos.just - Add documentation section to
docs/DEMOS.md - Generate the GIF:
just demo gif <name>
claude-code-go/
├── pkg/claude/ # Core SDK library
│ ├── claude.go # Main client implementation
│ ├── claude_test.go # Unit tests
│ └── dangerous/ # Advanced/unsafe features
├── examples/ # Usage examples
│ ├── basic/ # Simple usage patterns
│ ├── advanced/ # MCP and advanced features
│ ├── testing/ # Testing utilities
│ └── demo/ # Interactive demos
├── test/ # Integration tests
│ ├── integration/ # End-to-end tests
│ ├── mockserver/ # Mock Claude server
│ └── fixtures/ # Test data
├── justfile # Primary build automation
├── .justfiles/ # Modular justfile components
└── go.mod # Go module definition
- Check existing issues and discussions
- Discuss major changes in an issue first
- Ensure your Go version meets requirements
# Fork and clone your fork
git clone https://github.com/YOUR_USERNAME/claude-code-go
cd claude-code-go
# Create feature branch
git checkout -b feature/your-feature-name
# Make changes and test
just test all
just build examples
# Commit with clear messages
git commit -m "Add streaming timeout support
- Add context timeout handling in StreamPrompt
- Update tests to verify timeout behavior
- Add example demonstrating timeout usage"- Clear title describing the change
- Comprehensive description with motivation and approach
- Link related issues using "Fixes #123" or "Related to #456"
- Add tests for new functionality
- Update examples if API changes
- Ensure CI passes before requesting review
- Maintainers will review for design, correctness, and style
- Address feedback promptly and thoroughly
- Be responsive to questions and suggestions
- Squash commits before merge if requested
- New convenience methods for common use cases
- Improved error handling and error messages
- Performance optimizations for subprocess execution
- Better streaming support and real-time features
- Enhanced MCP integration and tool support
- Code examples showing real-world usage
- API documentation improvements
- Architecture diagrams and explanations
- Testing guides and best practices
- Edge case testing for error conditions
- Performance benchmarks and load testing
- Cross-platform compatibility testing
- Memory leak detection and fixes
- CLI interfaces or command-line tools
- Standalone applications for end users
- Alternative Claude implementations
- Unrelated utilities that don't enhance the SDK
- GitHub Discussions for questions and ideas
- GitHub Issues for bugs and feature requests
- Code examples in
examples/directory - Existing tests as reference implementations
- Be respectful and inclusive
- Focus on constructive feedback
- Help others learn and improve
- Assume good intentions
Contributors will be recognized in:
- GitHub contributors page
- Release notes for significant contributions
- Project documentation and examples
Thank you for helping make Claude Code Go SDK better! 🚀