Skip to content

poc(daemon): Claude Agent SDK as PTY replacement#1149

Draft
nicacioliveira wants to merge 1 commit intomainfrom
poc/claude-agent-sdk
Draft

poc(daemon): Claude Agent SDK as PTY replacement#1149
nicacioliveira wants to merge 1 commit intomainfrom
poc/claude-agent-sdk

Conversation

@nicacioliveira
Copy link
Copy Markdown
Contributor

@nicacioliveira nicacioliveira commented Apr 1, 2026

What

Proof of concept replacing @sigma/pty-ffi PTY with @anthropic-ai/claude-agent-sdk.

How it works

Before:
AITask → PtySession → spawn "claude" (Node.js) → PTY → ANSI text → WebSocket

After:
AITask → SdkSession → spawn "node task-sdk.mjs" → JSON events → formatted text → WebSocket
  • USE_AGENT_SDK=true env var activates the new path
  • task-sdk.mjs — Node.js script using query() from the Agent SDK
  • sdk-session.ts — drop-in replacement for PtySession with same interface
  • Events formatted as ANSI text → Terminal.tsx works without changes

Validated locally

  • ✅ Uses existing Claude Code login (no API key required)
  • Bash, LS, Read tools work correctly
  • ✅ Events stream over WebSocket
  • ✅ Buffer replay on reconnect
  • ✅ Exit code 0 on success

Benefits

  • Removes @sigma/pty-ffi (FFI dependency)
  • Structured events instead of ANSI parsing
  • Same capabilities as the CLI
  • Compatible with Claude Max subscription / OAuth

Next steps

  • Add to Dockerfile: npm install -g @anthropic-ai/claude-agent-sdk
  • Remove @sigma/pty-ffi from image after validation
  • Update Terminal.tsx for richer event display (optional)
  • Test with issue/Ralph flow
  • Benchmark memory usage vs PTY approach

🤖 Generated with Claude Code


Summary by cubic

Add an optional path to run tasks via @anthropic-ai/claude-agent-sdk instead of the PTY, streaming structured events through a Node subprocess and formatting them to ANSI so the existing terminal and WebSocket flow work unchanged. This is behind USE_AGENT_SDK=true and paves the way to remove @sigma/pty-ffi.

  • New Features
    • Added SdkSession as a drop-in for PtySession with the same interface.
    • Introduced task-sdk.mjs that calls SDK query() and emits NDJSON events.
    • AITask chooses the SDK path when USE_AGENT_SDK=true and a prompt is present.
    • Events are formatted to ANSI; Terminal.tsx and the WebSocket protocol are unchanged.

Written for commit ab6f3fb. Summary will update on new commits.

Proof of concept replacing @sigma/pty-ffi PTY with @anthropic-ai/claude-agent-sdk.

How it works:
- When USE_AGENT_SDK=true, AITask spawns a Node.js subprocess (task-sdk.mjs)
  instead of a PTY session
- Node script uses the SDK query() function and writes newline-delimited JSON
  events to stdout
- SdkSession reads stdout, formats events as ANSI text (xterm.js compatible),
  and exposes the same interface as PtySession (onData, onExit, outputBuffer)
- WebSocket protocol unchanged — Terminal.tsx works without modification

Validated locally:
- SDK runs with existing Claude Code login (no API key required)
- tool_use events (Bash, LS, Read) work correctly
- Events stream over WebSocket as readable formatted text
- Exit code 0 on success

Next steps:
- Add to Dockerfile: npm install -g @anthropic-ai/claude-agent-sdk
- Update Terminal.tsx for richer event display (optional)
- Remove @sigma/pty-ffi dependency once validated in production

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 1, 2026

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 5603e329-ddb8-4bb0-a2a6-3343214a30cf

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch poc/claude-agent-sdk

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 1, 2026

Tagging Options

Should a new tag be published when this PR is merged?

  • 👍 for Patch 1.188.1 update
  • 🎉 for Minor 1.189.0 update
  • 🚀 for Major 2.0.0 update

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant