Skip to content

fix(env): preserve CLAUDE_CODE_USE_FOUNDRY through the SDK env sanitizer#3166

Open
jimweller wants to merge 1 commit into
thedotmack:mainfrom
jimweller:feat/preserve-foundry-env
Open

fix(env): preserve CLAUDE_CODE_USE_FOUNDRY through the SDK env sanitizer#3166
jimweller wants to merge 1 commit into
thedotmack:mainfrom
jimweller:feat/preserve-foundry-env

Conversation

@jimweller

Copy link
Copy Markdown

Summary

sanitizeEnv (src/supervisor/env-sanitizer.ts) strips every CLAUDE_CODE_* / CLAUDECODE_* variable before the SDK subprocess is spawned, unless the name is in ENV_PRESERVE. The provider selectors CLAUDE_CODE_USE_BEDROCK and CLAUDE_CODE_USE_VERTEX are already preserved; CLAUDE_CODE_USE_FOUNDRY (Microsoft Foundry) is not, so it gets stripped and the subprocess loses provider selection on Foundry-backed installs.

This adds CLAUDE_CODE_USE_FOUNDRY to ENV_PRESERVE, alongside the sibling selectors.

Why

Foundry users set CLAUDE_CODE_USE_FOUNDRY=1 the same way Bedrock/Vertex users set their selector. Without preservation, the observer/worker SDK subprocess cannot reach the Foundry endpoint and observation capture breaks. This is parity with the existing Bedrock/Vertex handling, not a new mechanism.

Changes

  • src/supervisor/env-sanitizer.ts: add CLAUDE_CODE_USE_FOUNDRY to ENV_PRESERVE
  • tests/supervisor/env-sanitizer.test.ts: dedicated preserve test plus an assertion in the selective-preserve test

Safety

  • Layer 1 (BLOCKED_ENV_VARS in EnvManager.ts) is unchanged; no credential or effort var is affected.
  • The CLAUDE_CODE_EFFORT_LEVEL / CLAUDE_CODE_ALWAYS_ENABLE_EFFORT strip is untouched.

Test

bun test tests/supervisor/env-sanitizer.test.ts -> 12 pass / 0 fail.

The supervisor env sanitizer strips all CLAUDE_CODE_* / CLAUDECODE_* vars except those in ENV_PRESERVE. CLAUDE_CODE_USE_FOUNDRY selects the Microsoft Foundry provider for the spawned SDK subprocess, exactly as CLAUDE_CODE_USE_BEDROCK and CLAUDE_CODE_USE_VERTEX already do. Without preserving it, Foundry-backed installs lose provider selection when claude-mem spawns the SDK, breaking observation capture.

Adds the var to ENV_PRESERVE alongside the sibling provider selectors, with matching tests (dedicated case + selective-preserve assertion).
@greptile-apps

greptile-apps Bot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR preserves the Foundry provider selector when sanitizing the SDK subprocess environment. The main changes are:

  • Adds CLAUDE_CODE_USE_FOUNDRY to the sanitizer preserve list.
  • Keeps the existing deny-by-default stripping for other CLAUDE_CODE_* and CLAUDECODE_* variables.
  • Adds tests for Foundry preservation and the selective preserve/strip behavior.

Confidence Score: 5/5

Safe to merge with minimal risk.

The change is a narrow allowlist update with direct tests for the new environment variable. Existing stripping for unapproved CLAUDE_CODE_* variables and effort flags remains covered.

No files require special attention.

T-Rex T-Rex Logs

What T-Rex did

  • Ran Bun tests for tests/supervisor/env-sanitizer.test.ts to validate environment sanitization, capturing the run details for review.
  • The test run completed with exit code 0 and reported 12 passed tests across 1 file with 65 expect() calls.

View all artifacts

T-Rex Ran code and verified through T-Rex

Important Files Changed

Filename Overview
src/supervisor/env-sanitizer.ts Adds CLAUDE_CODE_USE_FOUNDRY to the explicit preservation allowlist while preserving the existing strip behavior.
tests/supervisor/env-sanitizer.test.ts Adds tests covering CLAUDE_CODE_USE_FOUNDRY preservation and selective sanitizer behavior.

Sequence Diagram

%%{init: {'theme': 'neutral'}}%%
sequenceDiagram
participant Parent as Supervisor process env
participant Sanitizer as sanitizeEnv
participant Child as SDK subprocess env
Parent->>Sanitizer: "CLAUDE_CODE_USE_FOUNDRY=1"
Sanitizer->>Sanitizer: key is in ENV_PRESERVE
Sanitizer->>Child: preserve CLAUDE_CODE_USE_FOUNDRY
Parent->>Sanitizer: "other CLAUDE_CODE_* values"
Sanitizer->>Sanitizer: not in ENV_PRESERVE
Sanitizer--xChild: strip unapproved variables
Loading
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
sequenceDiagram
participant Parent as Supervisor process env
participant Sanitizer as sanitizeEnv
participant Child as SDK subprocess env
Parent->>Sanitizer: "CLAUDE_CODE_USE_FOUNDRY=1"
Sanitizer->>Sanitizer: key is in ENV_PRESERVE
Sanitizer->>Child: preserve CLAUDE_CODE_USE_FOUNDRY
Parent->>Sanitizer: "other CLAUDE_CODE_* values"
Sanitizer->>Sanitizer: not in ENV_PRESERVE
Sanitizer--xChild: strip unapproved variables
Loading

Reviews (1): Last reviewed commit: "fix(env): preserve CLAUDE_CODE_USE_FOUND..." | Re-trigger Greptile

Copilot AI added a commit that referenced this pull request Jul 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant