Skip to content

Preserve user env settings during provider switch#79

Closed
istarwyh wants to merge 3 commits into
guyskk:mainfrom
istarwyh:fix/preserve-user-env-in-settings
Closed

Preserve user env settings during provider switch#79
istarwyh wants to merge 3 commits into
guyskk:mainfrom
istarwyh:fix/preserve-user-env-in-settings

Conversation

@istarwyh

Copy link
Copy Markdown
Contributor

Summary

  • Preserve user-managed ANTHROPIC_* and CLAUDE_* env settings unless the active provider defines the same key
  • Simplify env cleanup to remove only provider env key conflicts
  • Update merge strategy docs and regression tests for the narrower cleanup behavior

Test plan

  • go test ./internal/config ./internal/provider
  • ./check.sh

🤖 Generated with Claude Code

istarwyh and others added 3 commits March 8, 2026 01:59
Only remove settings.json env entries that conflict with the active provider env so user-managed Claude and Anthropic environment variables remain intact.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@guyskk

guyskk commented May 19, 2026

Copy link
Copy Markdown
Owner

Closing: superseded by #76 (already merged on main), which fixes the same issue (user env in settings.json being wiped) with a safer approach.

Empirical finding (claude 2.1.144): settings.json env strictly overrides the process environment variable that ccc passes to the claude subprocess via syscall.Exec. Verified with isolated dual-port tests on ANTHROPIC_BASE_URL.

Consequence: this PR's narrower cleanup (keeping user ANTHROPIC_/CLAUDE_ in settings.json + removing delete(settingsWithHook,"env")) would let stale/user ANTHROPIC_* in settings.json override the provider env passed on the command line, silently breaking provider switching (wrong base_url/token/model). #76's FilterUserEnvForSettings (strip all ANTHROPIC_/CLAUDE_ + managed keys from settings.json) is the correct approach and already preserves non-provider user env.

@guyskk guyskk closed this May 19, 2026
@guyskk

guyskk commented May 20, 2026

Copy link
Copy Markdown
Owner

sofeisen pushed a commit to sofeisen/claude-code-supervisor that referenced this pull request Jun 8, 2026
Repository was renamed back to claude-code-config-switcher after
supervisor mode removal in 0.4.0.

- README/README-CN: update release download/listing URLs
- CHANGELOG: update compare links; note repo rename in 0.4.0 entry
- docs/discuss-20260519-env-priority.md: update PR guyskk#79 link
- docs/supervisor-mode-improvement-proposal.md: update project link

Historical entries (0.2.0 rename note, frozen plan snapshots) left
intact as historical records.
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.

2 participants