Skip to content

feat(server): replace Claude Agent SDK runtime with a direct stream-json CLI driver (subscription billing)#1

Closed
akarabach wants to merge 199 commits into
mainfrom
read-claude-streamed-messages
Closed

feat(server): replace Claude Agent SDK runtime with a direct stream-json CLI driver (subscription billing)#1
akarabach wants to merge 199 commits into
mainfrom
read-claude-streamed-messages

Conversation

@akarabach
Copy link
Copy Markdown
Owner

Why

Driving Claude through @anthropic-ai/claude-agent-sdk could bill usage against pay-per-token API credits. We need Claude usage to draw from the user's Claude subscription (Pro/Max) instead. The SDK's query() is what spawns and drives the claude binary, so removing the SDK runtime (while keeping its types) lets us own the process and its environment directly.

What

  • New ClaudeCliTransport.ts — an SDK-free driver that spawns the native claude binary and speaks its stream-json IPC protocol directly.
  • ClaudeAdapter.ts — the createQuery seam now uses the new transport; the SDK import is import type only.
  • ClaudeProvider.ts — the capabilities/auth probe no longer executes SDK runtime code (uses the transport's initialize() handshake).
  • @anthropic-ai/claude-agent-sdk moved dependenciesdevDependencies (types only — zero runtime code ships).
  • Added protocol integration tests driving a fake CLI.

How it works now

createQuerymakeClaudeCliQuery spawns claude --output-format stream-json --verbose --input-format stream-json …, then:

  • stdout: NDJSON is framed and emitted as the same SDKMessage stream the adapter already consumes — no downstream changes.
  • stdin: user messages + control requests (interrupt, setModel, setPermissionMode, setMaxThinkingTokens) are written as NDJSON.
  • Permissions: with a canUseTool callback the CLI runs with --permission-prompt-tool stdio, so can_use_tool requests arrive on the same stdout stream and are answered on stdin — no separate MCP server.
  • An initialize handshake is sent on startup (also powers the auth/capabilities probe).

Because no SDK code runs, the spawned process uses the local claude login → subscription billing (provided ANTHROPIC_API_KEY is not in the server environment).

Verification

  • Typecheck clean; 300 provider tests + 5 new transport tests pass; production bundle builds with zero runtime SDK import.
  • ⚠️ Not yet verified against a live claude binary with a real subscription — needs a manual end-to-end pass (streaming, tool approval, resume, claude auth status).

Screenshot

TODO: screenshot

juliusmarminge and others added 30 commits April 12, 2026 18:22
Co-authored-by: Cursor Agent <cursoragent@cursor.com>
Co-authored-by: julius <julius0216@outlook.com>
Co-authored-by: Cursor Agent <cursoragent@cursor.com>
Co-authored-by: cursor[bot] <206951365+cursor[bot]@users.noreply.github.com>
Co-authored-by: codex <codex@users.noreply.github.com>
Co-authored-by: Julius Marminge <jmarminge@gmail.com>
Co-authored-by: Cursor Agent <cursoragent@cursor.com>
Co-authored-by: Cursor Agent <cursoragent@cursor.com>
Co-authored-by: codex <codex@users.noreply.github.com>
Co-authored-by: Cursor Agent <cursoragent@cursor.com>
Co-authored-by: cursor[bot] <206951365+cursor[bot]@users.noreply.github.com>
…ingdotgg#1541)

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-authored-by: Julius Marminge <julius0216@outlook.com>
Co-authored-by: codex <codex@users.noreply.github.com>
Co-authored-by: Cursor Agent <cursoragent@cursor.com>
Co-authored-by: cursor[bot] <206951365+cursor[bot]@users.noreply.github.com>
Co-authored-by: codex <codex@users.noreply.github.com>
…gg#2024)

Co-authored-by: Julius Marminge <julius0216@outlook.com>
Co-authored-by: codex <codex@users.noreply.github.com>
Co-authored-by: Julius Marminge <julius0216@outlook.com>
ben-vargas and others added 26 commits May 8, 2026 23:52
Co-authored-by: Julius Marminge <julius0216@outlook.com>
Co-authored-by: Julius Marminge <julius@macmini.local>
Co-authored-by: Julius Marminge <julius@macmini.local>
Co-authored-by: Julius Marminge <julius@macmini.local>
Co-authored-by: codex <codex@users.noreply.github.com>
Co-authored-by: Julius Marminge <julius0216@outlook.com>
Co-authored-by: Cursor Agent <cursoragent@cursor.com>
Co-authored-by: Julius Marminge <juliusmarminge@users.noreply.github.com>
Co-authored-by: Julius Marminge <julius0216@outlook.com>
Co-authored-by: Cursor Agent <cursoragent@cursor.com>
Co-authored-by: Julius Marminge <juliusmarminge@users.noreply.github.com>
Co-authored-by: Julius Marminge <julius0216@outlook.com>
Co-authored-by: Cursor Agent <cursoragent@cursor.com>
Co-authored-by: Julius Marminge <juliusmarminge@users.noreply.github.com>
Co-authored-by: Julius Marminge <julius0216@outlook.com>
- Restrict release workflow defaults to read-only access
- Grant `id-token` only to the publish job
- Document safe handling for `pull_request_target` in PR size checks
Co-authored-by: Julius Marminge <julius@macmini.local>
Replace the @anthropic-ai/claude-agent-sdk runtime with a direct
stream-json child-process driver so usage bills against the user's
Claude subscription instead of pay-per-token API credits. The SDK is
now a type-only devDependency (zero runtime code, types unchanged).

- ClaudeCliTransport.ts (new): spawn + NDJSON framing + control
  protocol (interrupt/setModel/setPermissionMode/setMaxThinkingTokens),
  can_use_tool permission bridge over stdio, initialize handshake
- ClaudeAdapter.ts: createQuery -> makeClaudeCliQuery; import type only
- ClaudeProvider.ts: capabilities/auth probe ported off SDK runtime
- package.json: SDK moved dependencies -> devDependencies
- ClaudeCliTransport.test.ts (new): protocol integration tests
@github-actions github-actions Bot added vouch:trusted PR author is trusted by repo permissions or the VOUCHED list. size:XXL labels May 16, 2026
@akarabach
Copy link
Copy Markdown
Owner Author

Superseded by the upstream PR pingdotgg#2729 (correct base).

@akarabach akarabach closed this May 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XXL vouch:trusted PR author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.