Skip to content

Commit 4002862

Browse files
ElliotDrelclaude
andcommitted
feat(anthropic): enforce --safe-mode on all claude-cli subprocess launches
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]>
1 parent 706132c commit 4002862

2 files changed

Lines changed: 15 additions & 2 deletions

File tree

‎extensions/anthropic/cli-backend.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ export function buildAnthropicCliBackend(): CliBackendPlugin {
3535
"stream-json",
3636
"--include-partial-messages",
3737
"--verbose",
38+
"--safe-mode",
3839
"--setting-sources",
3940
"user",
4041
"--allowedTools",
@@ -46,6 +47,7 @@ export function buildAnthropicCliBackend(): CliBackendPlugin {
4647
"stream-json",
4748
"--include-partial-messages",
4849
"--verbose",
50+
"--safe-mode",
4951
"--setting-sources",
5052
"user",
5153
"--allowedTools",

‎extensions/anthropic/cli-shared.ts‎

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ export const CLAUDE_CLI_CLEAR_ENV = [
6060
const CLAUDE_LEGACY_SKIP_PERMISSIONS_ARG = "--dangerously-skip-permissions";
6161
const CLAUDE_PERMISSION_MODE_ARG = "--permission-mode";
6262
const CLAUDE_SETTING_SOURCES_ARG = "--setting-sources";
63+
const CLAUDE_SAFE_MODE_ARG = "--safe-mode";
6364
const CLAUDE_SAFE_SETTING_SOURCES = "user";
6465
const CLAUDE_BYPASS_PERMISSION_MODE = "bypassPermissions";
6566

@@ -168,6 +169,16 @@ export function normalizeClaudeSettingSourcesArgs(args?: string[]): string[] | u
168169
return normalized;
169170
}
170171

172+
export function normalizeClaudeSafeModeArgs(args?: string[]): string[] | undefined {
173+
if (!args) {
174+
return args;
175+
}
176+
if (args.includes(CLAUDE_SAFE_MODE_ARG)) {
177+
return args;
178+
}
179+
return [...args, CLAUDE_SAFE_MODE_ARG];
180+
}
181+
171182
export function normalizeClaudeBackendConfig(
172183
config: CliBackendConfig,
173184
context?: CliBackendNormalizeConfigContext,
@@ -177,9 +188,9 @@ export function normalizeClaudeBackendConfig(
177188
const permission = resolveClaudePermissionMode(context);
178189
return {
179190
...config,
180-
args: normalizeClaudePermissionArgs(normalizeClaudeSettingSourcesArgs(config.args), permission),
191+
args: normalizeClaudePermissionArgs(normalizeClaudeSettingSourcesArgs(normalizeClaudeSafeModeArgs(config.args)), permission),
181192
resumeArgs: normalizeClaudePermissionArgs(
182-
normalizeClaudeSettingSourcesArgs(config.resumeArgs),
193+
normalizeClaudeSettingSourcesArgs(normalizeClaudeSafeModeArgs(config.resumeArgs)),
183194
permission,
184195
),
185196
output,

0 commit comments

Comments
 (0)