Repository navigation
refactor(anthropic): replace Agent SDK with direct CLI transport - #138707
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
Dependency GuardThis PR changes dependency-related files. Maintainers should confirm these changes are intentional. Changed files:
Maintainer follow-up:
|
Dependency graph changes notedThis PR includes dependency graph changes. The dependency guard is informational because the PR author is a repository admin, a member of
Security review is still recommended before merge when the dependency graph change is intentional. |
|
Codex review: blocked before merge. Reviewed September 4, 2026, 11:48 PM ET / September 5, 2026, 03:48 UTC. ClawSweeper reviewWhat this changesThe Anthropic plugin replaces the Agent SDK with direct communication to installed Claude Code, removes SDK packaging, and preserves executable invocation details through the shared runner. Merge readiness⛔ Blocked before merge - 4 items remain Keep open: current main has not absorbed this maintainer-sponsored work, and no actionable introduced defect was found. The previously raised protocol-ownership decision is resolved in the discussion. Priority: P2 Review scores
Verification
How this fits togetherOpenClaw’s CLI runner prepares agent prompts, credentials, tool policy, and session ownership for the Anthropic plugin. The plugin exchanges structured messages with Claude Code and returns results while OpenClaw retains approval and lifecycle control. flowchart TD
A[Agent turn] --> B[Shared CLI runner]
B --> C[Anthropic transport]
C --> D[Installed Claude Code]
D --> E[Native tool request]
E --> F[Current turn and host policy]
F --> C
D --> G[Streamed results and session continuity]
Before merge
Agent review detailsSecurityNone. PR surfaceSource +68, Tests -733, Docs +2, Config -4, Other -198. Total -865 across 45 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Maintain one Anthropic-owned transport while preserving shared admission, approvals, credential isolation, and native session continuity within the accepted CLI compatibility boundary. Do we have a high-confidence way to reproduce the issue? Not applicable to the central refactor; subprocess regression scenarios and reported live runs cover the preserved behavior, but were not rerun during this read-only review. Is this the best way to solve the issue? Yes, within the accepted CLI boundary: the patch replaces the transport at its plugin owner and retains the shared lifecycle and policy machinery. Independent upstream-contract reinspection was unavailable here. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 185ca0df6328. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (4 earlier review cycles)
|
|
The post-adoption audit and requested live verification are complete on
Windows native Claude cancellation has not been exercised on a Windows installation; portable subprocess coverage and current Windows CI cover the shared process boundary. This limitation is separate from the authenticated Linux and native macOS proof above. The separately installed ACPX adapter's upstream SDK dependency remains outside core distribution. @clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
Read the refreshed exact-head review. Proceeding with its recommended exercised CLI boundary: the Anthropic plugin owns future native-protocol maintenance, with direct SDK/native source inspection plus Claude 2.1.243/2.1.261 and authenticated Gateway proof supporting this replacement. This is not a claim of compatibility with arbitrary future CLI versions. Native Windows Claude cancellation remains an explicitly recorded coverage limit; both required Windows CI jobs passed and the existing custom process/credential owner is retained. The added fingerprint flag is also not a persisted-data migration. |
Apply the upstream fixture correction from #138769 so chat startup and dashboard navigation resolve the same session.
…mment Upstream replaced the Agent SDK with a direct CLI transport (openclaw#138707), so the comment's reference to how "the Agent SDK types this field" no longer names anything in the tree. The dual-spelling read is still required -- the streamed record and the on-disk transcript disagree -- so only the attribution changes, not the behavior. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01BjsHL4YEa67pAiPpSY3svm
…8504) Closes #138424 ## What Problem This Solves Fixes ordinary `claude-cli` agent turns failing to launch on Windows when an npm installation exposes an extensionless shell shim or a `.cmd` launcher. ## User Impact Windows users can complete Claude CLI turns through their npm-installed command without replacing launcher files. Native executables and non-Windows command handling are preserved. No configuration, authentication, or identity-verification policy changes are required. ## Why This Change Was Made The earlier implementation targeted the Agent SDK adapter removed by #138707. This revision preserves the contributor's commits while applying the repair to the current direct CLI transport. Its launch boundary now uses the existing shared Windows resolver and carries the resolved program together with its leading arguments. Relative commands and PATH entries are resolved against the child working directory; existing identity callers retain their previous behavior. ## Evidence The supported `agent --local --session-id <fresh> --message "Reply with exactly PONG" --json --timeout 60` path was exercised on real GitHub-hosted Windows 2025 with Node 24.20.0, isolated OpenClaw state, an npm-style prefix, and a controlled external CLI speaking the Anthropic transport protocol. No auth-binding callback or exact-version policy normalized the command first; no platform mock or live provider credential was used. | Actual Windows launch | Unchanged main production | Candidate production | | --- | --- | --- | | Extensionless shim plus npm `.cmd` | `write EPIPE`, no run child or reply | Run child launched; final reply `PONG` | | npm `.cmd` resolving to Node plus script | `spawn EINVAL`, no run child or reply | Node and script argument preserved; final reply `PONG` | | Native `.exe` control | Final reply `PONG` | Final reply `PONG` | - [Baseline run](https://github.com/openclaw/openclaw/actions/runs/35431111855): production from `7a932d979442`, proof ref `381771f2ca50`. - [Candidate run](https://github.com/openclaw/openclaw/actions/runs/35433705895): `e9f91d13d7e3`, with the same three fixtures and order. All three product cases passed. Publication head `7f7212ac7e6b` changes only the fixture's filesystem-error typing, not production or executable fixture bytes. - A macOS npm-shim control also completed with `PONG`. Focused local checks passed 75 tests, with the native-only case skipped; scoped lint passed. - The candidate Windows workflow is **not wholly green**: three later executable-identity tests failed with `expected undefined to be package-tree`. The baseline stopped before those cases, so this is not claimed as reproduced base-red. Their two-argument resolver calls retain exactly the previous behavior, run outside the changed execution owner, and execute in separate test processes. The identity guards and assertions remain intact. This proves the real OpenClaw command, Windows process launch, direct transport, and final reply boundary with a controlled CLI peer. It does not claim live Anthropic authentication/model traffic, pnpm launcher coverage, or Windows resume-session coverage. Ordinary exact-head PR CI remains the wider validation gate. Co-authored-by: Ayaan Zaidi <[email protected]>
…nclaw#138504) Closes openclaw#138424 ## What Problem This Solves Fixes ordinary `claude-cli` agent turns failing to launch on Windows when an npm installation exposes an extensionless shell shim or a `.cmd` launcher. ## User Impact Windows users can complete Claude CLI turns through their npm-installed command without replacing launcher files. Native executables and non-Windows command handling are preserved. No configuration, authentication, or identity-verification policy changes are required. ## Why This Change Was Made The earlier implementation targeted the Agent SDK adapter removed by openclaw#138707. This revision preserves the contributor's commits while applying the repair to the current direct CLI transport. Its launch boundary now uses the existing shared Windows resolver and carries the resolved program together with its leading arguments. Relative commands and PATH entries are resolved against the child working directory; existing identity callers retain their previous behavior. ## Evidence The supported `agent --local --session-id <fresh> --message "Reply with exactly PONG" --json --timeout 60` path was exercised on real GitHub-hosted Windows 2025 with Node 24.20.0, isolated OpenClaw state, an npm-style prefix, and a controlled external CLI speaking the Anthropic transport protocol. No auth-binding callback or exact-version policy normalized the command first; no platform mock or live provider credential was used. | Actual Windows launch | Unchanged main production | Candidate production | | --- | --- | --- | | Extensionless shim plus npm `.cmd` | `write EPIPE`, no run child or reply | Run child launched; final reply `PONG` | | npm `.cmd` resolving to Node plus script | `spawn EINVAL`, no run child or reply | Node and script argument preserved; final reply `PONG` | | Native `.exe` control | Final reply `PONG` | Final reply `PONG` | - [Baseline run](https://github.com/openclaw/openclaw/actions/runs/35431111855): production from `cc262448fa0c`, proof ref `381771f2ca50`. - [Candidate run](https://github.com/openclaw/openclaw/actions/runs/35433705895): `e9f91d13d7e3`, with the same three fixtures and order. All three product cases passed. Publication head `7f7212ac7e6b` changes only the fixture's filesystem-error typing, not production or executable fixture bytes. - A macOS npm-shim control also completed with `PONG`. Focused local checks passed 75 tests, with the native-only case skipped; scoped lint passed. - The candidate Windows workflow is **not wholly green**: three later executable-identity tests failed with `expected undefined to be package-tree`. The baseline stopped before those cases, so this is not claimed as reproduced base-red. Their two-argument resolver calls retain exactly the previous behavior, run outside the changed execution owner, and execute in separate test processes. The identity guards and assertions remain intact. This proves the real OpenClaw command, Windows process launch, direct transport, and final reply boundary with a controlled CLI peer. It does not claim live Anthropic authentication/model traffic, pnpm launcher coverage, or Windows resume-session coverage. Ordinary exact-head PR CI remains the wider validation gate. Co-authored-by: Ayaan Zaidi <[email protected]>
…ompt Narrow openclaw#137134 onto the current direct transport per the ClawSweeper review recommendation (preserve existing defaults; consolidate explicit isolation support on the current Anthropic transport). - Drops the retired Agent SDK implementation: the SDK adapter this branch patched was removed by openclaw#138707, so no SDK code is touched anymore. - The memory-isolation half is covered by openclaw#166073 (claudeCli.excludeNativeMemory, opt-in, default off); this branch no longer implements it. - Reimplements the prompt-ownership half as an opt-in on the direct transport: plugins.entries.anthropic.config.claudeCli.replaceNativePrompt (default false). When enabled, normalizeClaudeBackendConfig swaps the backend's system-prompt file arg from --append-system-prompt-file to --system-prompt-file, so OpenClaw's prompt replaces Claude Code's native prompt instead of appending to it. The --exclude-dynamic-system-prompt- sections trim flag is skipped when replacing, since there are no native sections left to trim. - Defaults are unchanged: without the setting, runs keep the native prompt with OpenClaw's instructions appended. Docs: setting documented in docs/gateway/cli-backends.md; schema and UI hints added to the Anthropic plugin manifest; generated config baseline regenerated. Tests: three new cases in extensions/anthropic/cli-shared.test.ts covering the default append behavior, the opt-in swap, and the trim-flag skip.
What Problem This Solves
OpenClaw distributes the Claude Agent SDK for an integration that runs the user's installed Claude Code executable. This removes that dependency and its copied package assets while retaining Claude CLI support.
Related: anthropics/claude-agent-sdk-typescript#224
Why This Change Was Made
The Anthropic plugin now owns the CLI's bidirectional stream-json transport. The shared runner retains admission, approvals, questions, credential handling, timeouts, warm-session registration, and MCP lifetime. Private prompt context, native tool policy, session resume/fork, and process-tree cleanup remain supported. Permission callbacks revalidate the admitted turn immediately before their response is written, and failed turns cannot leave background work attached to a later admission.
The audit traced 112 relevant commits after SDK adoption in 12d0fd2 (#128131), retaining the later question, permission, environment, credential, session, MCP, diagnostics, and compaction fixes. Direct inspection of Agent SDK 0.3.243 and native Claude's protocol found two contracts to preserve: unhandled MCP elicitation returns
decline, and the plugin runner forwards the verified executable's script prefix andargv0. Before-fix subprocess and protocol tests reproduced both gaps. Detailed audit and proof.The SDK asset copier, build exceptions, dependency entries, and SDK-option mocks are removed. Provider tests exercise real subprocesses and protocol messages.
User Impact
Existing Claude CLI configuration and native login continue to work with the separately installed Claude Code executable. Normal Anthropic API-key support retains its separate API client. No additional plugin installation, configuration change, or database migration is needed.
The Plugin SDK gains optional
CliBackendExecuteContext.argv0to preserve verified invocation through PATH shims. Prepared arguments retain the executable's script prefix; executors spawning the prepared command should forward both.The separately installed ACPX adapter retains its own upstream Agent SDK dependency. ACPX is excluded from core distribution; this PR removes the bundled Anthropic provider's SDK dependency.
Evidence
Final CI passed on
0672fed74110f67f5fba354aaef2e49444438ed3, including both Windows jobs and real-Gateway E2E.974 tests across 37 files passed on the initial implementation. After the audit fixes, 112 focused tests across eight files passed, covering the provider and shared runner. Fresh Codex reviews found no actionable P0–P2 findings. Formatting, lint, production/test types, dead-export scans, repository guards, and the full build passed.
Authenticated Gateway suites passed with both an API key and native subscription authentication: real parent/child execution, ordered completion announcement, resumed recall, image understanding, MCP discovery, and automation creation. Initial authenticated proof. A supplementary native subscription run on the refreshed runtime also passed, 1/1 test in 101.119 seconds, following a fresh frozen install and build. Refreshed runtime proof. Its source tree matches merge commit 11d251c; central transport and runner files remain unchanged through the final refresh. Stored reports recovered the result after the Testbox output connection was lost; the model run was not repeated.
Real Claude Code 2.1.243 and 2.1.261 against an isolated HTTP/SSE fixture additionally proved host denial overriding native allow settings, private context, warm reuse, cancellation, background final-result handling, cold resume, and checkpoint fork without altering the original history. Native Windows Claude cancellation was not live-tested; portable process tests and Windows CI cover the shared launcher.
On the live-tested refreshed runtime revision
11d251c65dc, the package passed both npm lock validators, package integrity, and the complete dist import graph. Its 10,066 entries contain zero Agent SDK asset paths or runtime JavaScript references, with no Agent SDK dependency in the root or bundled Anthropic manifest. Tarball: 58,795,536 bytes; SHA-256ba9dbbbc3d1152afc814df74c95933e62a0b948ebf9d362a4e56a5e0b904c43d.CI exposed an inconsistent dashboard navigation fixture, repaired upstream in #138769 and #138793. The branch preserves the current mainline fixture and all original browser assertions; the focused browser test and all 36 dashboard-owner tests passed. One supplementary local invocation case hit its one-second deadline under severe filesystem contention; its unchanged two-case rerun passed. No timeout was increased.
Production/build/manifests: +809/−845 (net −36). Tests/support: +1,057/−1,790 (net −733). Lockfile: −98. Documentation: +35/−33. Renames are discounted. The removed asset copier owned build output, and the invocation fingerprint belongs to a process-local Map; neither requires a saved-data migration.