Repository navigation
fix(anthropic): stop inheriting Claude Code's prompt and memory surfaces on the Agent SDK path - #137134
fix(anthropic): stop inheriting Claude Code's prompt and memory surfaces on the Agent SDK path#137134zijunl wants to merge 1 commit into
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. |
|
Codex review: needs real behavior proof before merge. What this changesThis PR adds an off-by-default Anthropic setting intended to replace Claude Code’s native system prompt with OpenClaw’s. Example: An operator enables plugins.entries.anthropic.config.claudeCli.replaceNativePrompt for claude-cli agent turns.
Review scores
ProductKind: Feature · Worth it: Needs a maintainer decision · Fix scope: Partial Merge readiness⛔ Blocked before merge - 5 items remain Keep open: the opt-in proposal contains distinct work, but the prior transport finding remains unresolved and the new configuration surface needs an owner decision. Priority: P2 Decision needed
Before merge
Findings
Tests
Agent review detailsHow this fits togetherThe Anthropic plugin converts prepared OpenClaw turns into Claude Code subprocess arguments and initialization messages, then returns streamed agent events to the shared runner. flowchart LR
A[Agent turn and config] --> B[Shared CLI runner]
B --> C[Anthropic configuration adapter]
C --> D[Direct CLI transport]
D --> E[Claude Code subprocess]
E --> F[Streamed agent events]
Technical reviewBest possible solution: If an owner sponsors the option, implement replacement in the existing transport initialization and session-compatibility path while preserving default append behavior. Do we have a high-confidence way to reproduce the issue? The enabled-setting failure follows directly from the shipped execution path: plugin-owned execution bypasses prompt argv delivery and initializes with appendSystemPrompt; no target code was executed. Is this the best way to solve the issue? Changing backend descriptor fields is insufficient because the direct transport owns prompt delivery; repair that owner and verify its initialization contract. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 6913563f69d9. Provenance checked
TestingProof path: unit tests only. SecurityNone. EvidenceWhat I checked:
PR surfaceSource +58, Tests +52, Docs +28, Generated 0. Total +138 across 6 files. Added test files: 0. View PR surface stats
Review metrics
LabelsLabel changes:
Label justifications:
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment HistoryReview history (14 earlier review cycles; latest 8 shown)
Reviewed October 18, 2026, 8:27 AM ET / 12:27 UTC (Revision 15). |
|
Thanks — your read was right, and better than mine. I've reverted the system-prompt half in 492c42d and narrowed this PR to the To be explicit about what was wrong: my "verified" evidence for the prompt change exercised i.e. with The harness-identity half of #137124 is still real but its owner is @clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
Added the real fix for the harness-identity half in 8001ad1 ( Root cause of why the earlier descriptor change was inert: Proof is now authority-chain, from a probe inside { "systemPromptType": "string", "systemPromptIsPreset": false, "tools": ["Skill"], "allowedTools": ["mcp__openclaw__*"] }For the native- Skills-still-work: a normal gateway turn lists Two things left for maintainers, both called out in the body: the docs page still describes append + the old default args, and the default-capability removal is an owner call (can move behind a @clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
CI caught one — |
|
Exact-head proof on the ordinary path, which is the gap the last review named ("the supplied memory trace uses empty setting sources"). Built this branch from source and ran a real A temporary probe on the resolved SDK options, on a turn that completed normally ( {
"systemPromptType": "string",
"systemPromptIsPreset": null,
"systemPromptHead": "You are a personal assistant running inside OpenClaw.\n## Tooling\nTools",
"settingSources": ["user"],
"settings": {
"autoMemoryEnabled": false,
"claudeMdExcludes": ["**/CLAUDE.md", "**/CLAUDE.local.md", "**/.claude/rules/**"]
},
"extraArgsSettingsPresent": false
}
The restricted branch ( Local against this head: The probe was added to the local build only and is not in the diff. |
Superseded by #140487 — this PR's target files no longer exist#138707 ("replace Agent SDK with direct CLI transport") deleted The substance split in two:
But only half of that landed. The payload is pushed solely by the restricted argv builder, which runs only when #140487 closes that remaining half against the new transport, with the ordinary-run scope limited to the memory keys and an operator Leaving this open for a maintainer to close, rather than closing it myself. 🤖 Generated with Claude Code |
…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.
2562a01 to
46944cd
Compare
|
Narrowed this PR per the ClawSweeper review recommendation (preserve existing defaults; consolidate explicit isolation support on the current Anthropic transport). The branch is rebased onto current
Note: this branch now overlaps #166073's |
|
Thanks @zijunl for tracing and documenting the prompt and memory overlap. Closing this SDK-targeted PR as superseded by #138707 (58d8871), which deleted This is not a claim that ordinary Claude CLI runs now isolate host instructions: the direct transport still initializes with |
Stops an OpenClaw agent on the
claude-clibackend from inheriting Claude Code's own prompt and memory surfaces on top of its own.Two changes, both in
agent-sdk.runtime.ts:claude_codepreset system prompt with OpenClaw's, so the agent runs with one system prompt instead of two.CLAUDE.mdpickup — the same two keys OpenClaw already sets on its restricted-run path.Part of #137124.
What Problem This Solves
resolveClaudeAgentSdkOptionsconsumes the backend args itself andcontinues past every--*system-prompt*flag (they are members ofCLAUDE_STREAM_PROTOCOL_VALUE_FLAGS), then hardcodes:A second branch (
excludeDynamicSystemPromptSections, active for Claude Code ≥ 2.1.98) does the same. So OpenClaw's owncli_backendsystem prompt always ran on top of the full Claude Code harness prompt, and the backend descriptor'ssystemPromptFileArg/systemPromptModewere never the owner for normal agent runs.Two prompts means two identities. In production the harness identity reached an end user over Telegram:
A chat user has no concept of "this CLI context".
Change
…at both sites. Per the Agent SDK contract a string
systemPromptis a full custom prompt and no preset is loaded (sdk.d.ts:systemPrompt?: string | string[] | { type: 'preset'; … }).And, after the arg loop:
These are not new policy — they are two of the four keys already in
CLAUDE_RESTRICTED_SETTINGS(cli-shared.ts):{"disableAllHooks":true,"enabledPlugins":{},"autoMemoryEnabled":false, "claudeMdExcludes":["**/CLAUDE.md","**/CLAUDE.local.md","**/.claude/rules/**"]}A restricted run already declines the host's memory surfaces; a normal agent run never did, so a gateway agent carried Claude Code's auto-memory index and any
CLAUDE.mdreachable from cwd alongside its ownAGENTS.md/MEMORY.md.disableAllHooksandenabledPluginsare deliberately not copied — the former would also kill OpenClaw's ownUserPromptSubmitandPreToolUsehooks, which carry its context injection and permission gate.OpenClaw's
cli_backendprompt is self-contained for this:system-prompt-params.tsforces tool guidance, the skills section, and the read-tool name on for that surface, so nothing downstream was relying on the preset to describe the agent's own tooling.Evidence
Live 2026.8.1 gateway, Claude Code 2.1.241, on a real Telegram turn (not a CLI-initiated probe). A temporary probe inside
resolveClaudeAgentSdkOptionsrecorded what the SDK actually received:{ "spType": "string", "spIsPreset": false, "spHead": "You are a personal assistant running inside OpenClaw.\n## Tooling\nTools policy-filtered. Names case-s", "spLen": 30892, "plugins": ["/tmp/openclaw/openclaw-claude-skills-Js5c01/openclaw-skills"] }spIsPreset: falseand the prompt opening with OpenClaw's own first line confirm theclaude_codepreset is no longer loaded and OpenClaw's prompt is the whole system prompt.For the memory settings, the probe confirms they reach the SDK:
{"settingSources":[],"settings":{"autoMemoryEnabled":false, "claudeMdExcludes":["**/CLAUDE.md","**/CLAUDE.local.md","**/.claude/rules/**"]},"spType":"string"}and the agent, asked whether a Claude Code memory index is present in its context, went from describing one ("
claudeMd… Claude Code 那边自动带的 memory index,跟 OpenClaw 的 MEMORY.md 是两套不同系统") to answering plainly: 没有 (no).Skills are unaffected —
--plugin-dirdelivery still works with a string prompt. A normal gateway turn listsopenclaw-skills:browser,:oracle,:summarize, and in a standalone control a plugin-provided skill was both discovered and successfully invoked under--system-prompt-file.Withdrawn: the
--toolsrestrictionAn earlier revision added
--tools SkilltoCLAUDE_CLI_DEFAULT_ARGS, arguing Claude Code's built-ins duplicated OpenClaw's MCP tools. That premise was wrong and the change broke the backend. Recording it here because the reasoning may save someone else the same mistake.On the
cli_backendprompt surface OpenClaw describes its ownexecas "Run shell on connected node; sync; host=node" and ships noread/write/edit/processMCP tools to that surface at all. Local shell and filesystem access are delegated to the harness's native tools by design — which is whatnativeToolMode: "selectable"andselectedNativeToolsProvideFileAccessare reasoning about.exec(remote node) and nativeBash(local) are different execution targets, not duplicates.With
--tools Skillapplied, the agent had no local execution and no file access. Asked to write and read back a file:After reverting, the same request succeeded via native
Bashand the file was created.Worse, my original evidence was that failure: I cited the agent reaching for
execinstead ofBashas proof the restriction worked, and quoted thehost=node requires a paired nodeerror in this PR body without registering that it was the breakage. Retracted.Notes
agent-sdk.runtime.test.ts's warm-restart assertion expectedsystemPrompt: objectContaining({ append })and is updated to expect the string. It was the only test asserting the preset shape.--setting-sourcesis a related but separate issue and is not touched here.normalizeClaudeArgsforcesCLAUDE_SAFE_SETTING_SOURCES = "user"unconditionally, so a gateway inherits whatever Claude Code plugins the host operator has enabled and their hooks fire on every agent turn — on my machine a third-party plugin'sSessionStartandUserPromptSubmithooks inject a large document plus per-turn "MANDATORY: You must run Skill(...)" text.[]is the same isolation argument taken further (and matches what running the model over the plain API looks like), but it also drops the operator's user-level skills and plugins, so it reads as a config knob — ideally defaulting to[]for unattended runs — rather than a straight flip. Worth noting OpenClaw already passes--setting-sources ""on its own restricted-run path, so the empty value is not foreign to the design.src/node-host/invoke-agent-cli-claude.ts) still uses--append-system-prompt-file; separate execution path, left untouched.🤖 Generated with Claude Code
https://claude.ai/code/session_01BjsHL4YEa67pAiPpSY3svm