- Status: Accepted
- Date: 2026-03-05
Claude Code is CLI-oriented and communicates through the installed claude binary.
To keep behavior parity and reduce protocol drift, this .NET SDK needs a transport strategy aligned with real CLI behavior.
For runtime behavior, the practical source of truth is the observed print-mode contract:
claude -p --output-format jsonclaude -p --output-format stream-json --verbose
Use the local Claude Code CLI process as the only runtime transport layer for ManagedCode.ClaudeCodeSharpSDK.
ClaudeExecbuilds argument order and environment variables.DefaultClaudeProcessRunnerstarts the process and streams stdout lines asynchronously.ThreadEventParsermaps the observedstream-jsonprotocol to strongly typed events and items.
flowchart LR
SDK["ManagedCode.ClaudeCodeSharpSDK"] --> Exec["ClaudeExec"]
Exec --> Cli["claude -p --output-format json|stream-json"]
Cli --> Jsonl["stdout JSONL"]
Jsonl --> Parser["ThreadEventParser"]
Parser --> Models["ThreadEvent / ThreadItem"]
- High parity with upstream Claude Code CLI behavior.
- No separate protocol server to maintain.
- Easier compatibility when Claude Code CLI adds flags or events.
- Requires
claudebinary availability in the environment. - Runtime errors may come from external process failures.
- SDK remains process-boundary integration; unit tests may substitute process runners where appropriate, but CLI smoke coverage still uses the real
claudebinary.
- Direct HTTP protocol implementation: rejected due to drift risk and higher maintenance.
- TCP/daemon transport abstraction now: deferred; may be revisited if Claude Code introduces a stable server mode.