Skip to content

meawoppl/rust-code-agent-sdks

Repository files navigation

rust-code-agent-sdks

Typed Rust interfaces for AI code agent CLI protocols.

This workspace provides independent crates for interacting with Claude Code, OpenAI Codex, and opencode via their streaming protocols (JSON/JSONL over stdio, or HTTP + SSE).

Crates

Crate Version Docs CI WASM
claude-codes Crates.io docs.rs CI Feature Matrix
codex-codes Crates.io docs.rs CI Feature Matrix
opencode-codes Crates.io docs.rs CI Feature Matrix

Versioning

Each crate's version tracks the CLI it wraps:

  • claude-codes version tracks the Claude CLI it targets and may sit slightly ahead of the CLI it was last integration-tested against. Currently claude-codes 2.1.166, tested against Claude CLI 2.1.220.
  • codex-codes version tracks the Codex CLI it has been tested against, sitting a small offset behind while the bindings stabilize. Currently codex-codes 0.145.0, tested against Codex CLI 0.145.0.
  • opencode-codes version tracks the opencode release train it wraps. Currently opencode-codes 1.18.5, tested against opencode 1.18.5.

claude-codes and codex-codes warn (or fail gracefully) when the installed CLI version diverges from the tested version. opencode-codes tracks the opencode release train by version but ships no runtime version-divergence check.

Feature Flags

claude-codes

claude-codes is structured into three feature flags to control dependency weight:

Feature Description WASM-compatible
types Core message types and protocol structs only Yes
sync-client Synchronous client with blocking I/O No
async-client Asynchronous client using tokio No

All features are enabled by default. For WASM or type-sharing use cases:

[dependencies]
claude-codes = { version = "2", default-features = false, features = ["types"] }

codex-codes

codex-codes mirrors the same feature flag structure:

Feature Description WASM-compatible
types Core message types and protocol structs only Yes
sync-client Synchronous client with blocking I/O No
async-client Asynchronous client using tokio No

All features are enabled by default. For WASM or type-sharing use cases:

[dependencies]
codex-codes = { version = "0.142", default-features = false, features = ["types"] }

opencode-codes

opencode-codes wraps an HTTP + SSE server rather than a stdio CLI, so its flags differ:

Feature Description WASM-compatible
types Core protocol types only (serde) Yes
async-client Async HTTP/SSE client using reqwest + tokio No
server Managed opencode serve launcher (picks a free port) No

default = ["types", "async-client"] (there is no sync client). For WASM or type-sharing use cases:

[dependencies]
opencode-codes = { version = "1.18", default-features = false, features = ["types"] }

Testing Approach

The crates share the same testing philosophy:

  1. Unit tests validate serde round-tripping for every type variant against hand-crafted JSON.
  2. Integration tests deserialize real JSONL captures from actual CLI sessions. These captures live in each crate's test_cases/ directory and are checked into the repo, so deserialization is validated against real-world protocol output.
  3. CI matrix tests each feature combination independently, including WASM builds via wasm32-unknown-unknown, clippy, rustfmt, and MSRV (1.85).

To run all tests locally:

cargo test --workspace

Workspace Structure

rust-code-agent-sdks/
  claude-codes/          # Claude Code CLI protocol bindings
    src/                 # Types, sync/async clients, protocol handling
    tests/               # Deserialization + integration tests
    test_cases/          # Real CLI captures and failure cases
    examples/            # async_client, sync_client, basic_repl
  codex-codes/           # Codex CLI protocol bindings
    src/                 # Types, sync/async clients, CLI builder
    tests/               # Integration tests
    test_cases/          # Real CLI captures
    examples/            # async_client, sync_client, basic_repl
  opencode-codes/        # opencode HTTP + SSE server bindings
    src/                 # Types, async client, HTTP/SSE transport, server launcher
    tests/               # Drift checks and schema snapshot

See each crate's README for detailed usage:

License

Apache-2.0. See LICENSE.

About

A rust interface to the streaming claude codes json terminal api.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages