Skip to content

feat(anthropic): enforce --safe-mode on all claude-cli subprocess launches - #92070

Closed
ElliotDrel wants to merge 1 commit into
openclaw:mainfrom
ElliotDrel:feat/safe-mode-default-claude-cli
Closed

ElliotDrel wants to merge 1 commit into
openclaw:mainfrom
ElliotDrel:feat/safe-mode-default-claude-cli

Conversation

@ElliotDrel

Copy link
Copy Markdown
Contributor

Summary

OpenClaw manages its own skills, CLAUDE.md, memory, and hooks. Any user-level Claude Code customizations on the host are redundant in this context and can silently interfere with OpenClaw-managed sessions — injecting unexpected context, skills, or hook side-effects into turns that OpenClaw controls.

This PR enforces --safe-mode on every Claude Code CLI subprocess OpenClaw launches, using the same pattern already established for --setting-sources user:

  • Added to the default args and resumeArgs in cli-backend.ts
  • Enforced unconditionally via a new normalizeClaudeSafeModeArgs normalizer in cli-shared.ts, wired into the normalizeClaudeBackendConfig pipeline

This means even if a user removes --safe-mode from their agents.defaults.cliBackends.claude-cli config override, normalization re-applies it — matching the behavior of --setting-sources user.

Changes

  • extensions/anthropic/cli-backend.ts: add --safe-mode to default args and resumeArgs
  • extensions/anthropic/cli-shared.ts: add CLAUDE_SAFE_MODE_ARG constant, normalizeClaudeSafeModeArgs function, and wire it into normalizeClaudeBackendConfig

Requirements

Requires Claude Code CLI >= 2.1.169 (2026-06-08), which introduced --safe-mode / CLAUDE_CODE_SAFE_MODE.

Test plan

  • Fresh claude-cli session launches include --safe-mode in the subprocess args
  • Resumed sessions (--resume) include --safe-mode
  • A user config override that omits --safe-mode from agents.defaults.cliBackends.claude-cli.args still gets it re-applied by normalization
  • Existing --setting-sources user enforcement is unaffected

🤖 Generated with Claude Code

…nches

OpenClaw manages its own skills, CLAUDE.md, memory, and hooks. Any
user-level Claude Code customizations on the host are redundant and can
silently interfere with OpenClaw-managed sessions — injecting unexpected
context, skills, or hook side-effects into turns that OpenClaw controls.

This mirrors how --setting-sources user is already enforced: added to the
default args in cli-backend.ts and enforced unconditionally via a new
normalizeClaudeSafeModeArgs normalizer in cli-shared.ts, which is wired
into the normalizeClaudeBackendConfig pipeline for both fresh and resumed
sessions. Even if a user removes --safe-mode from their
agents.defaults.cliBackends.claude-cli config override, normalization
re-applies it.

Requires Claude Code CLI >= 2.1.169 (2026-06-08), which introduced
--safe-mode / CLAUDE_CODE_SAFE_MODE.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. labels Jun 19, 2026
@clawsweeper

clawsweeper Bot commented Jun 19, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed August 11, 2026, 9:12 PM ET / August 12, 2026, 01:12 UTC.

ClawSweeper review

What this changes

This PR adds --safe-mode to fresh and resumed Claude CLI defaults and re-adds it after backend-argument overrides.

Merge readiness

⛔ Blocked until real behavior proof is added - 6 items remain

Do not merge this PR: its global --safe-mode normalization conflicts with the current Claude CLI design that preserves MCP-backed normal sessions. It cannot yet use the stale-proof close path because the supplied context has fresh review activity but does not establish 14 days without check activity.

Priority: P1
Reviewed head: 4002862df54f4b380dbfa0aa7974344d1f3f8186

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) The proposed global policy conflicts with the current MCP contract and has no after-fix real behavior proof.
Proof confidence 🧂 unranked krab (1/6) Needs real behavior proof before merge: The unchecked plan contains no redacted after-fix OpenClaw-spawned fresh or resumed Claude CLI evidence; a revived PR needs proof that MCP tools still work. 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 🧂 unranked krab (1/6) 1 actionable review finding remain.

Verification

Check Result Evidence
Real behavior Needs proof Needs real behavior proof before merge: The unchecked plan contains no redacted after-fix OpenClaw-spawned fresh or resumed Claude CLI evidence; a revived PR needs proof that MCP tools still work. 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 7 items Proposed global override: The supplied PR diff adds --safe-mode to both default arrays and routes both configured arrays through a new unconditional normalizer.
Current MCP contract: Restricted-run argument resolution deliberately removes safe mode; the adjacent comment states that safe mode suppresses explicit MCP, while the function then supplies the exact OpenClaw MCP allowlist.
Normal-session regression coverage: Current tests explicitly preserve Claude customizations when no exact per-run restriction exists; separate tests cover isolation while retaining the exact MCP allowlist.
Findings 1 actionable finding [P1] Do not force safe mode onto MCP-backed sessions
Security None None.

How this fits together

The Anthropic plugin turns OpenClaw agent configuration into Claude Code subprocess arguments, then applies per-run tool restrictions before launch. Those arguments preserve normal MCP tool access while isolating restricted or side-question runs.

flowchart LR
  A[Agent configuration] --> B[Claude CLI backend]
  B --> C[Backend normalization]
  C --> D[Per-run tool policy]
  D --> E[Claude Code subprocess]
  E --> F[OpenClaw MCP tools]
Loading

Before merge

  • Add real behavior proof - Needs real behavior proof before merge: The unchecked plan contains no redacted after-fix OpenClaw-spawned fresh or resumed Claude CLI evidence; a revived PR needs proof that MCP tools still work. 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.
  • Do not force safe mode onto MCP-backed sessions (P1) - This adds --safe-mode to every normal backend configuration, but the current restricted-run owner explicitly strips that flag because it suppresses explicit MCP. Normal OpenClaw Claude runs need the generated MCP config and allowed OpenClaw tools, so keep safe mode scoped to the already-isolated side-question path. This re-raises the unresolved prior P1.
  • Resolve merge risk (P1) - GitHub currently reports this branch as dirty; any revival needs a rebase plus after-fix proof that fresh and resumed OpenClaw MCP sessions still work.
  • Complete next step (P2) - The P1 design conflict and missing real behavior proof block merge; automatic stale closure is not yet justified because the supplied check activity is not timestamped.
  • Improve patch quality - Rebase the idea onto current main and remove global safe-mode enforcement from normal MCP-backed sessions.
  • Improve patch quality - Add redacted OpenClaw-spawned fresh and resumed Claude CLI evidence showing the expected MCP tool surface and behavior.

Findings

  • [P1] Do not force safe mode onto MCP-backed sessions — extensions/anthropic/cli-shared.ts:188-192
Agent review details

Security

None.

PR surface

Source +13. Total +13 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 2 15 2 +13
Tests 0 0 0 0
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 15 2 +13

Review metrics

Metric Value Why it matters
Production versus test delta production +15/-2 (net +13); tests +0/-0 The branch adds behavior-changing subprocess policy without regression coverage.
Claude CLI argument policy 1 flag forced across 2 default arrays and 2 normalized override paths Existing operator backend arguments can no longer opt out, so this changes normal-session compatibility.

Merge-risk options

Maintainer options:

  1. Preserve normal MCP sessions (recommended)
    Remove the global safe-mode default and only retain it where the existing isolated side-question policy can prove that MCP is intentionally unavailable.
  2. Pause the branch
    Leave the branch unmerged until a rebased implementation and redacted OpenClaw-spawned fresh/resume MCP proof establish a compatible policy.

Technical review

Best possible solution:

Keep --safe-mode limited to the side-question isolation path and preserve generated MCP access for normal Claude CLI sessions.

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

Yes, from source: normal Claude CLI configuration would receive --safe-mode before per-run argument handling, despite the current MCP path documenting that safe mode suppresses explicit MCP.

Is this the best way to solve the issue?

No. Current main isolates only restricted and side-question runs while preserving exact MCP access; a global config-time flag is the wrong boundary.

Full review comments:

  • [P1] Do not force safe mode onto MCP-backed sessions — extensions/anthropic/cli-shared.ts:188-192
    This adds --safe-mode to every normal backend configuration, but the current restricted-run owner explicitly strips that flag because it suppresses explicit MCP. Normal OpenClaw Claude runs need the generated MCP config and allowed OpenClaw tools, so keep safe mode scoped to the already-isolated side-question path. This re-raises the unresolved prior P1.
    Confidence: 0.98

Overall correctness: patch is incorrect
Overall confidence: 0.98

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against ff73a14f5ae7.

Labels

Label justifications:

  • P1: Forcing safe mode on normal Claude CLI runs can suppress the MCP tools that OpenClaw agents rely on.
  • merge-risk: 🚨 compatibility: The branch changes existing Claude CLI launch defaults and overrides for all configured sessions.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🧂 unranked krab.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: The unchecked plan contains no redacted after-fix OpenClaw-spawned fresh or resumed Claude CLI evidence; a revived PR needs proof that MCP tools still work. 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:

  • Proposed global override: The supplied PR diff adds --safe-mode to both default arrays and routes both configured arrays through a new unconditional normalizer. (extensions/anthropic/cli-shared.ts:188, 4002862df54f)
  • Current MCP contract: Restricted-run argument resolution deliberately removes safe mode; the adjacent comment states that safe mode suppresses explicit MCP, while the function then supplies the exact OpenClaw MCP allowlist. (extensions/anthropic/cli-shared.ts:428, 585503896dd3)
  • Normal-session regression coverage: Current tests explicitly preserve Claude customizations when no exact per-run restriction exists; separate tests cover isolation while retaining the exact MCP allowlist. (extensions/anthropic/cli-shared.test.ts:362, 585503896dd3)
  • Execution path: The core resolves plugin normalization before execution, then passes the resolved argument set to the backend’s per-run argument resolver. (src/agents/cli-backends.ts:393, ff73a14f5ae7)
  • Dependency signal and current capability gate: The backend declares the Claude Code package and currently requires the newer msg_lifecycle_v1 capability with an observed minimum version of 2.1.206; the PR’s separate 2.1.169 assertion has no attached real-run proof. (extensions/anthropic/cli-backend.ts:122, 585503896dd3)
  • Feature provenance: Blame attributes the current safe-mode constant, restricted execution policy, and normal-session configuration behavior to the current implementation snapshot. (extensions/anthropic/cli-shared.ts:437, 585503896dd3)

Likely related people:

  • Josh Lehman: Current blame attributes the safe-mode and MCP-restriction behavior to this implementation snapshot. (role: current implementation author; confidence: high; commits: 585503896dd3; files: extensions/anthropic/cli-shared.ts, extensions/anthropic/cli-backend.ts)
  • anagnorisis2peripeteia: Their merged change established the nearby default native-tool restriction in the same backend. (role: adjacent Claude CLI policy contributor; confidence: medium; commits: 298a0cd55f5e; files: extensions/anthropic/cli-backend.ts)

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 (6 earlier review cycles)
  • reviewed 2026-06-21T20:25:42.141Z sha 4002862 :: needs real behavior proof before merge. :: [P1] Gate safe mode on supported Claude CLI versions
  • reviewed 2026-06-30T22:28:49.995Z sha 4002862 :: needs real behavior proof before merge. :: [P1] Gate safe mode on supported Claude CLI versions
  • reviewed 2026-07-24T03:05:30.216Z sha 4002862 :: needs real behavior proof before merge. :: [P1] Gate safe mode on supported Claude CLI versions
  • reviewed 2026-07-30T13:02:45.613Z sha 4002862 :: needs real behavior proof before merge. :: [P1] Do not force safe mode onto MCP-backed sessions | [P1] Gate safe mode on supported Claude CLI versions
  • reviewed 2026-08-02T07:00:12.963Z sha 4002862 :: needs real behavior proof before merge. :: [P1] Preserve MCP-backed Claude CLI sessions | [P1] Gate the new flag on the installed Claude CLI version
  • reviewed August 8, 2026, 8:43 AM ET / 12:43 UTC sha unknown :: needs real behavior proof before merge. :: [P1] Keep safe mode out of normal MCP execution | [P1] Gate the new flag on a supported CLI capability

@openclaw-barnacle

Copy link
Copy Markdown

This pull request has been automatically marked as stale due to inactivity.
Please add updates or it will be closed.

@openclaw-barnacle openclaw-barnacle Bot added stale Marked as stale due to inactivity triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. and removed stale Marked as stale due to inactivity labels Jul 21, 2026
@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. and removed P2 Normal backlog priority with limited blast radius. labels Jul 30, 2026
@vincentkoc vincentkoc self-assigned this Aug 12, 2026
@vincentkoc vincentkoc added the close:superseded PR close reason label Aug 12, 2026
@vincentkoc

Copy link
Copy Markdown
Member

closing as superseded.

@ElliotDrel's customization-leak observation is valid: host-level Claude customizations can interfere with OpenClaw-managed sessions. the blanket --safe-mode approach is the wrong boundary, though, because Claude Code safe mode also disables MCP servers, which would remove OpenClaw's MCP tool surface from every fresh and resumed Claude CLI run.

current main now handles the two execution modes at their owners:

the existing head is conflicting. it adds no tests, provides no fresh/resumed MCP real-behavior proof, and has five failed Real behavior proof runs under PR context and evidence.

the replacement implementations were independently authored, so there is no co-author transfer.

@vincentkoc vincentkoc closed this Aug 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

close:superseded PR close reason merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants