claude-codes
A tightly typed Rust interface for the Claude Code JSON protocol.
Development Workflow
This project uses a strict PR-based workflow with automated quality checks:
Branch Protection & Git Hooks
- No direct commits to main - All changes must go through feature branches and PRs
- Automated pre-commit checks - Run
./setup_hooks.shto install local git hooks that enforce:- Branch protection (prevents commits to main)
- Code formatting (
cargo fmt) - Linting (
cargo clippy) - JSON test case formatting
- All tests passing
Getting Started
# Clone the repository
# Install git hooks (required for all contributors)
# Create a feature branch for your work
# Make your changes, then commit
# Push to GitHub and create a PR
Test-Driven Protocol Development
This crate uses a unique test-driven approach for protocol development:
- Run the test client:
cargo run --bin claude-test - Failed deserializations are automatically saved to
test_cases/failed_deserializations/ - Format test cases:
./format_test_cases.sh - Run tests to see what needs implementing:
cargo test deserialization - Add missing message types to the
ClaudeOutputenum - Tests turn green as the protocol is implemented
CI/CD Requirements
All PRs must pass the following GitHub Actions checks:
- ✅ Code formatting (
cargo fmt --all -- --check) - ✅ Clippy linting (
cargo clippy --all-targets --all-features -- -D warnings) - ✅ All tests passing (
cargo test --all-features) - ✅ JSON test cases properly formatted
- ✅ Documentation builds (
cargo doc --no-deps) - ✅ MSRV compatibility (Rust 1.85+)
Features
- Type-safe message encoding/decoding
- JSON Lines protocol support
- Async and sync I/O support
- Comprehensive error handling
- Stream processing utilities
Installation
[]
= "0.0.1"
Usage
use ;
// Serialize a request
let request = Request ;
let json_line = serialize?;
// Deserialize a response
let response: Response = deserialize?;
License
Licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.