Skip to content

Drive Claude through the Agent SDK instead of claude -p stream-json - #1

Open
snowopsdev wants to merge 6 commits into
mainfrom
cursor/claude-agent-sdk-f301
Open

snowopsdev wants to merge 6 commits into
mainfrom
cursor/claude-agent-sdk-f301

Conversation

@snowopsdev

@snowopsdev snowopsdev commented Oct 15, 2026 •

Copy link
Copy Markdown
Owner

Replace the Claude backend's hand-written stdio control protocol with the official @anthropic-ai/[email protected], using the user's installed claude executable and existing CLI login. Model/mode selection, resume, CLAUDE.md, hooks, skills, MCP tools and background work keep the same Modex surfaces. Packaged builds exclude the SDK's bundled native CLI packages.

Stop allows a graceful SDK interrupt before escalating to SIGTERM/SIGKILL, drains late messages and waits for process close. CLI failures preserve stderr and exit codes. Permission callbacks wait for tool rows, withdraw cancelled cards and approval-rule decisions, and suppress stale responses through the SDK. The frozen lockfile matches the exact dependency pin.

Upstream 6366cb5 is integrated, and existing CLI fixtures answer SDK initialization and process user messages separately from controls. Codex's upstream follow-up identified a deferred-launch cancellation race. The process factory now forwards the SDK's cancellation signal; a real-SDK regression verifies that a launch attempted after Stop exits with AbortError.

Local verification on macOS Apple Silicon with Node 24.14.0 and pnpm 10.34.5 passes: frozen install, workspace build/typechecks, and 1,597 tests (19 skips). The SDK Electron lifecycle case passes again after this fix, exercising approvals, withdrawal, graceful Stop and exit diagnostics. Fourteen targeted Electron cases passed on the earlier candidate, including subagents, titles, shutdown persistence, Pages MCP and the pinned Knowledge companion; the other 13 were not rerun for this follow-up. The full browser/Electron matrix and native iPhone suite were not run.

Installed-Claude smoke reached Claude Code 2.1.301 but the account's weekly usage limit prevented live model acceptance; the real SDK/CLI protocol and UI checks use local scripted executables. All commits in this PR are verified by GitHub. The follow-up commits use the registered GPG key 05896A04CA8D92EA. Detailed fixes, validation and rerun commands.

Upstream contribution: TypeSafeAI#250.

Signing repair preserved every file, commit message, author and merge parent. Reviewed commit e1f893e maps to 13c6530, and tested implementation 1199621 maps to e105d4f; their trees are identical.

Point query() at the user's installed claude executable so the existing
CLI login, CLAUDE.md, hooks, MCP servers and skills still apply. Map
canUseTool onto Modex approval cards, keep Stop/interrupt and resume,
and omit the SDK's bundled native CLI from packaged builds.

Tests inject a scripted query() so FakeProcess still covers approvals,
denial, Stop, and concurrent subagents without speaking the real SDK
handshake.

Co-authored-by: AJ <[email protected]>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-15T21:44:17.370603Z e1f893e Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@snowopsdev
snowopsdev marked this pull request as draft October 15, 2026 21:04

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 778844ff0c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread pnpm-lock.yaml Resolved
Wait for Claude to close after Stop, allow graceful interruption, and
preserve CLI exit diagnostics through SDK errors. Withdraw cancelled
approvals throughout the runner and approval rules, and order permission
cards after tool rows.

Exercise the real SDK with offline CLI fixtures, add opt-in installed-CLI
smoke tests, align the pinned lockfile, and record verification evidence.

Refs #1
Co-Authored-By: Codex <[email protected]>
snowopsdev added a commit that referenced this pull request Oct 15, 2026
Wait for Claude to close after Stop, allow graceful interruption, and
preserve CLI exit diagnostics through SDK errors. Withdraw cancelled
approvals throughout the runner and approval rules, and order permission
cards after tool rows.

Exercise the real SDK with offline CLI fixtures, add opt-in installed-CLI
smoke tests, align the pinned lockfile, and record verification evidence.

Refs #1
Co-Authored-By: Codex <[email protected]>
@snowopsdev
snowopsdev marked this pull request as ready for review October 15, 2026 21:41
snowopsdev and others added 2 commits October 15, 2026 17:49
Retain upstream's release and security corrections and preserve both
independent in-flight status entries.

Co-Authored-By: Codex <[email protected]>
Exercise approval, withdrawal, graceful Stop and CLI exit diagnostics
through the real SDK, runner, IPC and Electron UI with a local CLI.
Align the existing Claude fixtures with SDK initialization and validate
the candidate against current upstream.

Co-Authored-By: Codex <[email protected]>
Record real Electron captures of approval, withdrawal, Stop and CLI
failure through the shipped SDK and local executable fixture. Include
capture provenance and link the images from the upstream review.

Co-Authored-By: Codex <[email protected]>
@snowopsdev
snowopsdev force-pushed the cursor/claude-agent-sdk-f301 branch from 1199621 to e105d4f Compare October 15, 2026 22:33
Pass the SDK spawn signal through to the CLI launcher so a deferred
launch cannot outlive a stopped turn. Cover cancellation after the
Stop grace with the real SDK and a real child process.

Refs TypeSafeAI#250
Co-Authored-By: Codex <[email protected]>
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.

2 participants