Skip to content

fix(anthropic): keep Claude Code's memory out of ordinary claude-cli runs - #140487

Closed
zijunl wants to merge 2 commits into
openclaw:mainfrom
zijunl:fix/claude-cli-memory-isolation
Closed

zijunl wants to merge 2 commits into
openclaw:mainfrom
zijunl:fix/claude-cli-memory-isolation

Conversation

@zijunl

@zijunl zijunl commented Sep 6, 2026 •

Copy link
Copy Markdown

What Problem This Solves

Claude Code loads its own memory surfaces into every run: project CLAUDE.md / CLAUDE.local.md / .claude/rules files, and its auto-memory. On the claude-cli backend those land in the agent context OpenClaw composed, which never accounted for them — they address Claude Code as a coding assistant, not the agent the operator configured, and they consume a context budget OpenClaw is separately managing.

Exactly one payload in the tree turns them off, and today it reaches almost nothing:

extensions/anthropic/cli-shared.ts   (only occurrence of either key in the repo)
CLAUDE_RESTRICTED_SETTINGS = '{"disableAllHooks":true,"enabledPlugins":{},
  "autoMemoryEnabled":false,"claudeMdExcludes":[...]}'

It is pushed only by resolveClaudeCliRestrictedExecutionArgs, and that builder runs only when context.toolAvailability is set:

const resolvedArgs = context.toolAvailability
  ? resolveClaudeCliRestrictedExecutionArgs(executionArgs, context.toolAvailability)
  : executionArgs;                 // ← no --settings on this branch

Only two production callers set cliToolAvailability: src/agents/isolated-completion.ts and src/agents/embedded-agent-runner/cli-backend-dispatch.ts. An ordinary conversation turn is neither, so it passes no --settings and both keys stay unset.

--setting-sources user does not close this. It bounds which settings files load (user/project/local); CLAUDE.md and auto-memory are separate mechanisms that only these two keys control.

Approach

Normalize an isolation payload onto every claude-cli invocation, fresh and resumed. Per claude --help, --settings <file-or-json> loads "additional settings", so this layers onto the user's settings rather than replacing them.

Scope is deliberately narrower than the restricted profile — memory keys only. Hooks and plugins are operator-owned customization that does not feed the model's context, so ordinary runs leave them alone; the restricted profile remains the place both are also shut off.

Both profiles are now built from one shared field set so they cannot drift into expressing different memory policies. The restricted string is byte-identical to before, which its three existing assertions pin.

This is a default-behavior change. Anyone who deliberately wants their workspace CLAUDE.md read by a claude-cli-backed agent loses that unless they opt back in. The escape hatch is in this PR: an operator who supplies their own --settings in the backend args owns the whole payload, and OpenClaw appends nothing. Documented in docs/gateway/cli-backends.md. I flagged this as the reviewer's call rather than mine — if you would rather it be config-gated than default-on, say so and I will convert it.

Evidence

The two behavior tests fail against unfixed source rather than merely passing — removing the append block yields expected -1 to be greater than or equal to 0 on both.

End-to-end probe through the real shipped descriptor (not a fixture), confirming normalizeConfig actually reaches execution via resolveCliBackendConfig:

SETTINGS_PRESENT: true
PAYLOAD: {"autoMemoryEnabled":false,"claudeMdExcludes":["**/CLAUDE.md","**/CLAUDE.local.md","**/.claude/rules/**"]}
RESUME_PRESENT: true

Gates run locally: pnpm check:test-types exit 0 (all three projects), tsgo:core exit 0, pnpm check:docs exit 0, oxlint/oxfmt clean, deadcode:knip clean.

extensions/anthropic suite: 469 passed. The one failure there, session-catalog > re-stats only the changed project directory on the next poll, reproduces on clean main and is unrelated to this change.

Tests

extensions/anthropic/cli-shared.arg-normalization.test.ts — 55 passing, covering:

  • an ordinary run carries the isolation payload;
  • the real backend descriptor carries it fresh and resumed;
  • an operator's own --settings is left alone, in both split and = forms, with no second flag appended;
  • restricted runs still receive the stricter profile, with no duplicate --settings and no leak of the ordinary default.

cli-shared.test.ts was already near the 1000-line cap, so the argv-normalization describes moved into that new file alongside the new ones; the moved blocks are unchanged except for the added expectations.

Limits

Verified on the OpenClaw side: which flags are and are not passed on each path. What Claude Code then does with the absence of those flags is its own default behavior, which I could not verify from this repo.

Relationship to #137134

This supersedes #137134, which fixed the same class of problem against extensions/anthropic/agent-sdk.runtime.ts. #138707 deleted that file, so that PR's diff no longer applies. Its settings payload was already adopted upstream as CLAUDE_RESTRICTED_SETTINGS — this PR closes the remaining half, the ordinary run.

🤖 Generated with Claude Code

https://claude.ai/code/session_01BjsHL4YEa67pAiPpSY3svm

@clawsweeper

clawsweeper Bot commented Sep 6, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added the docs Improvements or additions to documentation label Sep 6, 2026
@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime extensions: anthropic triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. size: M labels Sep 6, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Sep 6, 2026
@clawsweeper

clawsweeper Bot commented Sep 6, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed September 29, 2026, 8:52 PM ET / September 30, 2026, 00:52 UTC (Revision 12).

ClawSweeper review

What this changes

The Anthropic plugin adds memory-exclusion settings to ordinary fresh and resumed Claude CLI runs, with documentation and argument-normalization tests.

Merge readiness

⛔ Blocked before merge - 6 items remain

This PR addresses a gap still present on current main, but its documented operator override is unreachable through the supported configuration path. The default change also needs a maintainer decision, and the supplied proof stops before an installed Claude Code process demonstrates the result.

Priority: P2
Reviewed head: a99ce7901dcfda510fe826c37ff626c836c49db3
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) The focused implementation and tests establish argument preparation, but the unreachable override and missing installed-process proof limit merge readiness.
Proof confidence 🦪 silver shellfish (2/6) Needs stronger real behavior proof before merge: The Anthropic normalizer and shipped descriptor produce a memory-exclusion argv for fresh and resumed runs, as shown by tests and the reported descriptor probe. The PR supplies no after-fix observation from an installed Claude Code process showing memory exclusion or an intentional override; a redacted terminal trace or recording of those runs would close that gap. No stored-data contract changes. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Patch quality 🦐 gold shrimp (3/6) 2 actionable review findings remain.

Verification

Check Result Evidence
Real behavior Needs proof Needs stronger real behavior proof before merge: The Anthropic normalizer and shipped descriptor produce a memory-exclusion argv for fresh and resumed runs, as shown by tests and the reported descriptor probe. The PR supplies no after-fix observation from an installed Claude Code process showing memory exclusion or an intentional override; a redacted terminal trace or recording of those runs would close that gap. No stored-data contract changes. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Evidence reviewed 9 items Introduced default: The PR appends memory-exclusion settings whenever a supplied argument array has no --settings flag.
Registered backend arguments: The bundled Anthropic descriptor supplies fixed fresh and resumed argument arrays; its builder exposes no operator argument input.
Runtime configuration boundary: The resolver normalizes the registered descriptor's config and does not merge operator-supplied backend arguments into it.
Findings 2 actionable findings [P1] Provide a reachable override before changing the default
[P3] Consolidate the repeated normalization tests
Security None None.

How this fits together

OpenClaw's Anthropic plugin supplies launch arguments for the installed Claude Code CLI. The CLI backend resolver prepares those arguments for fresh or resumed agent runs, and Claude Code then constructs the agent's context.

flowchart LR
  A[Agent turn] --> B[Anthropic CLI backend]
  B --> C[Normalize launch arguments]
  C --> D{Restricted run?}
  D -->|No| E[Ordinary settings]
  D -->|Yes| F[Restricted settings]
  E --> G[Claude Code process]
  F --> G
Loading

Decision needed

Question Recommendation
Should ordinary claude-cli runs exclude Claude Code memory by default, or should operators opt into that isolation through a supported setting? Preserve the current default: Add a supported opt-in isolation setting and leave existing Claude CLI workspaces using their current memory behavior.

Why: Either choice changes which instructions existing users' agents receive; the PR itself calls out the default-policy tradeoff, and its proposed escape hatch is unreachable.

Before merge

  • Add real behavior proof - Needs stronger real behavior proof before merge: The Anthropic normalizer and shipped descriptor produce a memory-exclusion argv for fresh and resumed runs, as shown by tests and the reported descriptor probe. The PR supplies no after-fix observation from an installed Claude Code process showing memory exclusion or an intentional override; a redacted terminal trace or recording of those runs would close that gap. No stored-data contract changes. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
  • Provide a reachable override before changing the default (P1) - The new default excludes memory for every ordinary run, but the documented escape hatch requires editing backend args. The shipped descriptor fixes both argument arrays, resolveCliBackendConfig does not merge user arguments, and the former config key is retired. Existing users who rely on workspace memory therefore have no supported way to retain it; preserve the old default or add a supported choice for fresh and resumed runs.
  • Consolidate the repeated normalization tests (P3) - The new test file repeats the permission-mode and setting-source cases still present in cli-shared.test.ts, with the same normalizer inputs. Keep one primary set of cases and retain the distinct fresh/resumed payload assertions so every PR does not pay for duplicate coverage.
  • Resolve merge risk (P1) - Existing Claude CLI users who intentionally rely on workspace CLAUDE.md or auto-memory would lose those instructions after upgrade, and the documented backend-args override cannot be configured through the current resolver.
  • Complete next step (P2) - Resolve the default-memory policy, make the selected override reachable for fresh and resumed runs, and add redacted installed-Claude behavior proof before merge. Updating the PR body should trigger a fresh ClawSweeper review; if it does not, ask a maintainer to comment @clawsweeper re-review.
  • Resolve maintainer decision - Resolve the maintainer decision shown above before merge.

Findings

  • [P1] Provide a reachable override before changing the default — extensions/anthropic/cli-shared.ts:228-230
  • [P3] Consolidate the repeated normalization tests — extensions/anthropic/cli-shared.arg-normalization.test.ts:35-36
Agent review details

Security

None.

PR surface

Source +30, Tests +215, Docs +11. Total +256 across 4 files.

View PR surface stats
Area Files Added Removed Net
Source 1 32 2 +30
Tests 2 251 36 +215
Docs 1 11 0 +11
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 294 38 +256

Review metrics

Metric Value Why it matters
Default and configuration 1 new default payload, 0 operator settings The new Claude CLI behavior affects ordinary runs without a supported configuration escape hatch.
Production versus test growth production net +30 lines, tests net +215 lines The production growth has a stated purpose, while repeated argument cases add test cost without a distinct boundary.

Merge-risk options

Maintainer options:

  1. Make isolation opt-in (recommended)
    Preserve existing workspace-memory behavior and add a supported setting for operators who want isolation.
  2. Approve a new default
    Accept the default change after adding a reachable override and demonstrating upgrade behavior in installed Claude Code.
  3. Pause the policy change
    Keep the PR open until the Anthropic backend owner chooses the intended ordinary-run memory policy.

Technical review

Best possible solution:

Keep the current default until a maintainer chooses the isolation policy; if isolation is optional, expose one supported Anthropic-owned setting that reaches fresh and resumed runs, then prove both choices with an installed Claude Code process.

Do we have a high-confidence way to reproduce the issue?

Not applicable as a policy change. Source shows the current-main ordinary path lacks memory-exclusion settings, but no installed Claude Code before-and-after behavior was observed for this PR.

Is this the best way to solve the issue?

No. The shared argument normalizer is a plausible owner for the payload, but the proposed unconditional default and unreachable override do not provide a safe upgrade path.

Full review comments:

  • [P1] Provide a reachable override before changing the default — extensions/anthropic/cli-shared.ts:228-230
    The new default excludes memory for every ordinary run, but the documented escape hatch requires editing backend args. The shipped descriptor fixes both argument arrays, resolveCliBackendConfig does not merge user arguments, and the former config key is retired. Existing users who rely on workspace memory therefore have no supported way to retain it; preserve the old default or add a supported choice for fresh and resumed runs.
    Confidence: 0.96
  • [P3] Consolidate the repeated normalization tests — extensions/anthropic/cli-shared.arg-normalization.test.ts:35-36
    The new test file repeats the permission-mode and setting-source cases still present in cli-shared.test.ts, with the same normalizer inputs. Keep one primary set of cases and retain the distinct fresh/resumed payload assertions so every PR does not pay for duplicate coverage.
    Confidence: 0.88

Overall correctness: patch is incorrect
Overall confidence: 0.94

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against ec9f4865045b.

Labels

Label changes:

No label changes.

Label justifications:

  • P2: This is a bounded Anthropic CLI improvement whose proposed default could affect existing users, without evidence of an urgent outage.
  • merge-risk: 🚨 compatibility: Merging would change the instructions received by existing Claude CLI agents, while the documented operator override is unreachable.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🦐 gold shrimp.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs stronger real behavior proof before merge: The Anthropic normalizer and shipped descriptor produce a memory-exclusion argv for fresh and resumed runs, as shown by tests and the reported descriptor probe. The PR supplies no after-fix observation from an installed Claude Code process showing memory exclusion or an intentional override; a redacted terminal trace or recording of those runs would close that gap. No stored-data contract changes. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Vito Cappello: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Resolve the default policy and implement a supported choice that reaches fresh and resumed runs.
  • Add redacted installed-Claude before-and-after output for memory exclusion and the intentional override; redact keys, IP addresses, phone numbers, and private endpoints.
  • Consolidate the duplicate normalization cases.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (11 earlier review cycles; latest 8 shown)
  • reviewed 2026-09-07T19:25:50.740Z sha 6ab030dda6c40a7a12d118e97d7487ed14919d1f :: needs real behavior proof before merge. :: [P2] Document the memory override for resumed runs too
  • reviewed 2026-09-07T19:46:36.893Z sha 399672afbbf72e0b2d24006be1acfec54bd5c2ce :: needs real behavior proof before merge. :: [P2] Document the memory override for resumed runs too
  • reviewed 2026-09-18T09:56:04.756Z sha bde528d4ac78a7f0789a9336444cd23d0b7e2f27 :: needs real behavior proof before merge. :: [P2] Document the memory override for resumed runs too
  • reviewed 2026-09-24T23:53:42.401Z sha bde528d4ac78a7f0789a9336444cd23d0b7e2f27 :: needs real behavior proof before merge. :: [P2] Document the settings override for resumed sessions
  • reviewed 2026-09-29T22:43:50.967Z sha 9a2e7ec4d773221c5c825ad854234d2a067f9c86 :: needs real behavior proof before merge. :: [P1] Provide a usable override before changing the default | [P2] Document the override for resumed sessions
  • reviewed 2026-09-29T23:29:59.850Z sha 7a312ce0e433ccfe6e689c023a3395c3d21f7a10 :: needs real behavior proof before merge. :: [P1] Provide a reachable override before changing the default | [P2] Document how the override reaches resumed runs
  • reviewed 2026-09-30T00:26:46.347Z sha 9fd7c70c8b803a27c41322ce5410c3771ac73c33 :: needs real behavior proof before merge. :: [P1] Provide a reachable override before changing the default | [P2] Document an override that works for resumed sessions
  • reviewed 2026-09-30T00:37:43.672Z sha c0dc13b04db4cdbb285b5577d1ed38c12ac49afa :: needs real behavior proof before merge. :: [P1] Provide a reachable override before changing the default | [P2] Document an override that reaches resumed runs | [P2] Consolidate duplicate argument-normalization cases

@openclaw-barnacle openclaw-barnacle Bot removed the triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. label Sep 7, 2026
@zijunl
zijunl force-pushed the fix/claude-cli-memory-isolation branch from 8dd90c0 to 6306e72 Compare September 7, 2026 18:29
@zijunl

zijunl commented Sep 7, 2026

Copy link
Copy Markdown
Author

CI note: acp-spawn.authority is a load-sensitive flake, not this PR

checks-node-compact-* failed on:

src/agents/subagents/spawn/acp-spawn.authority.test.ts
  > pending ACP spawn authority > transfers initialized ACP work only from its live parent: runtime / abort
AssertionError: cleanup completes before spawn returns: expected { …(11) } to be undefined
Test Files  1 failed | 135 passed (136)

Evidence it is not caused by either branch:

Worth filing separately as a flaky test; happy to open that if it is not already tracked.

I have no re-run rights on this repo, so I rebased onto current main to retrigger. Before pushing I ran the actual gates rather than a subset: check:test-types (all three tsconfig projects), tsgo:core, deadcode:knip, format:check, and format:docs:check — all exit 0.

🤖 Generated with Claude Code

https://claude.ai/code/session_01BjsHL4YEa67pAiPpSY3svm

@zijunl

zijunl commented Sep 7, 2026

Copy link
Copy Markdown
Author

Follow-up: the retrigger hit a different flake in the same shard

The rebase cleared acp-spawn.authority, and the run then failed on another test in the same agents-support shard:

src/agents/harness/native-hook-relay.test.ts > native hook relay registry > shares relay sta...
AssertionError: promise rejected "Error: connect ECONNRESET 127.0.0.1:36461 { …(5) }" instead of resolving
Test Files  1 failed | 135 passed (136)

ECONNRESET on a loopback port is environmental, not a logic failure, and this PR touches only extensions/anthropic/cli-shared.ts, its tests, and one doc page — nothing in the hook relay. It passes 3/3 locally on this exact commit (119 tests each run).

So across two retriggers this branch has hit two different flaky tests in that one shard, and no failure has ever pointed at the change itself. I am going to stop re-pushing rather than keep re-rolling a ~170-job matrix; a maintainer re-run of the failed job is the cheap fix.

All authored gates remain green on this commit: check:test-types (three tsconfig projects), tsgo:core, deadcode:knip, format:check, format:docs:check — every one exit 0.

🤖 Generated with Claude Code

https://claude.ai/code/session_01BjsHL4YEa67pAiPpSY3svm

zijunl and others added 2 commits September 29, 2026 17:44
…runs

Claude Code loads its own memory surfaces into every run: project
CLAUDE.md / CLAUDE.local.md / .claude/rules files and its auto-memory.
On this backend those land in an agent context OpenClaw did not compose
and does not account for in its context budget -- they address Claude
Code as a coding assistant, not the agent the operator configured.

Only one payload in the tree turns them off, and today it reaches almost
nothing. `CLAUDE_RESTRICTED_SETTINGS` is pushed solely by the restricted
argv builder, which runs only when `context.toolAvailability` is set --
and just two production callers set it (isolated completions, and
opted-in embedded CLI dispatch). Ordinary conversation turns take the
`: executionArgs` branch, so they pass no `--settings` at all and both
keys stay unset. `--setting-sources user` does not close this: it bounds
which *settings files* load, while CLAUDE.md and auto-memory are
separate mechanisms.

Normalize an isolation payload onto every claude-cli invocation instead,
fresh and resumed. `--settings` takes "a JSON string to load additional
settings from", so this layers onto user settings rather than replacing
them.

Scope is deliberately narrower than the restricted profile: memory keys
only. Hooks and plugins are operator-owned customization that does not
feed the model's context, so ordinary runs leave them alone. Both
profiles are now built from one field set so they cannot drift into
expressing different memory policies -- the restricted string is
byte-identical to before, which its three existing assertions pin.

An operator who supplies their own `--settings` owns the whole payload
and OpenClaw appends nothing, which is the escape hatch for anyone who
deliberately wants their workspace CLAUDE.md read.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01BjsHL4YEa67pAiPpSY3svm
`tsconfig.extensions.test.json` typechecks extension tests as its own
project, so the direct `as Parameters<...>[0]` assertion on a partial
context failed there (TS2352) while core typechecking stayed green.
Build the real context shape the other tests in this file already use.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01BjsHL4YEa67pAiPpSY3svm
@zijunl
zijunl force-pushed the fix/claude-cli-memory-isolation branch from c0dc13b to a99ce79 Compare September 30, 2026 00:44
@hannnnn-l

Copy link
Copy Markdown
Contributor

Adding a real-world report in support of fixing this.

Environment: OpenClaw 2026.9.8 (fc23bc8), Ubuntu 22.04, systemd user service, Claude Code 2.1.282, anthropic/claude-opus-5-5 with agentRuntime.id: "claude-cli", two agents driven from Discord.

On ordinary channel turns (no toolsAllow), Claude Code injects the user ~/.claude/CLAUDE.md and its auto memory (the MEMORY.md index plus its persistent-memory instructions) next to the OpenClaw system prompt and workspace bootstrap files. Following those instructions, the agent saves durable memory to ~/.claude/projects/<workspace-key>/memory/ instead of the workspace MEMORY.md / memory/. After a few weeks our main agent had 45 memory files there and none in the workspace. memory_search doesn't index them, OpenClaw backups don't include them, and the agent loses them when it runs on another runtime. We hit exactly that when moving our second agent to openai/gpt-6-astra on the built-in runtime: its knowledge had to be migrated out of Claude's memory folder by hand. Host-global ~/.claude/CLAUDE.md rules also silently apply to every claude-cli agent, alongside each agent's own workspace rules.

The documented alternative, a separate CLAUDE_CONFIG_DIR, currently breaks session continuity (#145309), so there is no supported switch today. As a stopgap we are setting CLAUDE_CODE_DISABLE_CLAUDE_MDS=1 and CLAUDE_CODE_DISABLE_AUTO_MEMORY=1 in a systemd drop-in for the Gateway.

On the policy question in the review: an opt-in setting would fully solve this for us, as long as it is a supported switch that reaches both fresh and resumed runs.

@hannnnn-l

hannnnn-l commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

Hi @zijunl, thanks for this PR and for working out the shared memory field set with the restricted profile.

I opened #166073, which builds on your approach. It started as the opt-in the review suggested, but it now follows your original direction: ordinary claude-cli runs exclude Claude Code's memory by default, fresh and resumed. It adds the piece the review found missing, a reachable override: plugins.entries.anthropic.config.claudeCli.excludeNativeMemory: false. It also adds a Doctor note that points at a scoped openclaw migrate claude --from <workspace memory dir> import, plus installed-Claude-Code proof. The ordinary-run payload uses the same fields as CLAUDE_RESTRICTED_SETTINGS, and the PR body credits your work.

Edited 2026-10-07: updated after #166073 moved from opt-in to default-on.

Happy to fold anything from your branch back into it, or to close mine if you would rather update this PR instead. Whatever works best for you.

@zijunl

zijunl commented Oct 6, 2026

Copy link
Copy Markdown
Author

Thanks for picking this up, @hannnnn-l — happy for #166073 to be the vehicle. It implements exactly what the review recommended (keep today's default, add a supported opt-in that reaches fresh and resumed runs), and the shared field set is already carried over with credit. Nothing on my branch needs folding back in. Closing this one as superseded by #166073.

@zijunl zijunl closed this Oct 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation extensions: anthropic gateway Gateway runtime merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. size: M status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants